I've created a yesod project with following command:
stack new yeplay yesodweb/simple
and I've added a helloworld.hs file to app directory. The app directory contains the following files:
~/haskell/yeplay/app$ ls
devel.hs DevelMain.hs helloworld.hs main.hs
The helloworld.hs file has the following content:
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
import Yesod
data HelloWorld = HelloWorld
mkYesod "HelloWorld" [parseRoutes|
/ HomeR GET
|]
instance Yesod HelloWorld
getHomeR :: Handler Html
getHomeR = defaultLayout [whamlet|Hello World!|]
main :: IO ()
main = warp 3000 HelloWorld
Then I tried to run the file with the command:
runhaskell helloworld.hs
Command 'runhaskell' not found, but can be installed with:
sudo apt install ghc
as described in the documentation.
How can I start the app?
Related
I am trying to write a script that uses Diagrams but the stack package detection feature is confusing me. I have two files and when the support module imports SVGFonts stack doesn't add it to the list of modules that are found. Instead, it's hidden. When the import is in the main file, however, it downloads it and finds it for the build just fine.
Main.hs
-- stack --resolver lts-19.0 script
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
import Diagrams.Prelude
import MyMod (val)
import Diagrams.Backend.SVG
main = print val
MyMod.hs
module MyMod where
import Diagrams.Backend.SVG
val = 1
And I am getting this error
Could not load module ‘Diagrams.Backend.SVG’
It is a member of the hidden package ‘diagrams-svg-1.4.3.1’.
You can run ‘:set -package diagrams-svg’ to expose it.
(Note: this unloads all the modules in the current scope.)
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Diagrams.Backend.SVG (loadFont)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
How can I get stack to automatically find that I need SVGFonts and import it properly without adding the import to my main file?
I'm trying to get the GHC to warn me whenever I write a new function and forget to use it anywhere. I've added the following function in my Main.hs:
unused :: () -> ()
unused _ = ()
and of course not used it.
I have the following in my *.cabal file:
ghc-options:
-W
-Wall
-Werror
-Wcompat
-Wincomplete-uni-patterns
-Wincomplete-record-updates
-Wredundant-constraints
-Wpartial-fields
-Wunused-binds
I've specifically added -Wunused-binds to try to force the compiler to fail on this but it does not report any warning about an unused function.
Any idea what am I doing wrong here?
EDIT
Just to give a bigger picture, here is the beggining of the main file:
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Main where
import Apecs
import Linear ( V2(..) )
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Catch
import qualified System.Terminal as T
import System.Terminal.Internal
import qualified Data.Map as M
import System.Random
Exporting only main function from module fixed the issue:
module Main(main) where
EDIT
Just for reference, this flag is already contained in -Wall so it would be enough to have this in cabal to catch it:
ghc-options:
-Wall
-Werror
I'm using Stack interpreter feature and having a code like this:
#!/usr/bin/env stack
{- stack
--resolver lts-9.0
--install-ghc
runghc
--package yesod
--package yesod-core
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
-- and the code goes on
I want to pass the ddump-splices option to the stack interpreter to it. Is it possible ?
Yes, you have to use -- before passing the actual ghc option. i.e:
#!/usr/bin/env stack
{- stack
--resolver lts-9.0
--install-ghc
runghc
--package yesod
--package yesod-core
-- -ddump-splices
-}
You can use ghc --show-options to see the kind of options you can pass. For more information, see here: https://github.com/commercialhaskell/stack/issues/650#issuecomment-123470879
It's probably very stupid, but I get a
parse error on input ‘⊥’
when I process this file
#!/usr/bin/env stack
-- stack --install-ghc --resolver lts-5.13 runghc --package http-conduit
{-# LANGUAGE OverloadedStrings, RankNTypes, MultiParamTypeClasses, FunctionalDependencies #-}
{-# LANGUAGE ScopedTypeVariables, UnicodeSyntax, PartialTypeSignatures #-}
module MainImplicitConfiguration where
a = ⊥
Is there a reason why that should be a parse error ?
Try:
a = (⊥)
(along with LANGUAGE UnicodeSyntax)
I tried to install the Haskell diagrams library and one of the dependencies cannot be installed. Being not that experienced to haskell, I cannot quite see how to resolve this error.
I removed warnings that I believe are not related to the failed build (------ warnings ommitted (-Winvalid-pp-token) -----)
[hsenv]➜ ~HSENV cabal install vector-space-0.8.5
Resolving dependencies...
Downloading vector-space-0.8.5...
Configuring vector-space-0.8.5...
/var/folders/nq/fx4vf3v14jz9b8mldvcyv1xr0000gn/T/23218.c:1:12:
warning: control reaches end of non-void function [-Wreturn-type]
int foo() {}
^
1 warning generated.
Building vector-space-0.8.5...
Preprocessing library vector-space-0.8.5...
------ warnings ommitted (-Winvalid-pp-token) -----
src/Data/VectorSpace.hs:4:3:
error: invalid preprocessing directive
#-}
^
------ warnings ommitted (-Winvalid-pp-token) -----
2 warnings and 1 error generated.
Failed to install vector-space-0.8.5
cabal: Error: some packages failed to install:
vector-space-0.8.5 failed during the building phase. The exception was:
ExitFailure 1
I presume you’re on OS X with Xcode 5 installed? There are instructions for that.
Xcode 5 supplies Clang as the C compiler, and with respect to pre-processing there are some “differences of interpretation” between it and GCC. These differences can affect some Haskell code that uses the CPP extension. An alternate approach for users with Xcode 5 is to install a GCC and direct GHC at that. See this page for instructions.
As Jon Purdy says, this has to do with the preprocessing. In particular, some of the modules in vector-space have their list of required language extensions on top like this:
{-# LANGUAGE MultiParamTypeClasses, TypeOperators
, TypeFamilies, UndecidableInstances, CPP
, FlexibleContexts
#-}
{-# OPTIONS_GHC -Wall #-}
----------------------------------------------------------------------
-- |
-- Module : Data.VectorSpace
...
i.e. a {#- ... -#} over multiple lines, and the delimiter is thus a line starting with #. Which then triggers the preprocessor, to obviously no good result!
You can change this to
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
or probably this will also do:
{-# LANGUAGE MultiParamTypeClasses, TypeOperators
, TypeFamilies, UndecidableInstances, CPP
, FlexibleContexts #-}
Here's a script that does this transformation automatically:
import System.IO.Strict as S
import System.Environment
import Control.Monad
rmLeadHash :: [String] -> [String]
rmLeadHash [] = []
rmLeadHash [l] = [l]
rmLeadHash (l:l':ls)
| ('#':_) <- dropWhile (==' ') l' = (l ++ l') : rmLeadHash ls
| otherwise = l : rmLeadHash (l':ls)
main = do
files <- getArgs
forM_ files $ \f -> do
hs <- S.readFile f
writeFile f $ unlines . rmLeadHash . lines $ hs
You can with this do
$ git clone git://github.com/conal/vector-space.git # or cabal fetch vector-space
$ cd vector-space
$ cabal install strict # needed for my script
$ find src -name '*.hs' | xargs runhaskell remLeadingHashes.hs
# ^- the script I've posted
$ cabal install # installs the modified vector-space package
If it works, you may want to push the changes.