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
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 have a script
#!/usr/bin/env stack
{-# LANGUAGE QuasiQuotes #-}
module Script where
import qualified Data.Set as Set (Set, fromList)
import Data.Maybe (fromJust)
{- import Text.RawString.QQ not neccessary for demonstration -}
main :: IO()
main = print "foo"
That I run with stack --resolver lts-12.5 runghc --package raw-strings-qq Script.hs
But I can't load it in GHCi:
$ stack ghci --resolver lts-12.5 --package raw-strings-qq
Note: No local targets specified, so a plain ghci will be started with no package hiding or package options.
If you want to use package hiding and options, then you can try one of the following:
* If you want to start a different project configuration than /home/t/.stack/global-project/stack.yaml, then you can use stack init to create a new
stack.yaml for the packages in the current directory.
* If you want to use the project configuration at /home/t/.stack/global-project/stack.yaml, then you can add to its 'packages' field.
Configuring GHCi with the following packages:
GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /tmp/haskell-stack-ghci/2a3bbd58/ghci-script
Prelude> :load Script.hs
[1 of 1] Compiling Script ( Script.hs, interpreted )
Stacko.hs:7:1: error:
Could not find module ‘Data.Set’
Perhaps you meant Data.Int (from base-4.11.1.0)
Use -v to see a list of the files searched for.
|
7 | import qualified Data.Set as Set (Set, fromList)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.
Own research:
I can load the file if I start ghci with just stack ghci --resolver lts-12.5.
Interestingly, when I import Data.Set 'unqualified' as I do with Data.Maybe:
import Data.Set
import Data.Maybe
the error persists, but when I drop the Data.Set import all together I can load Script.hs
Imports that don't work: Data.Set, Data.Map.Strict
Imports that work: Data.List, Data.Function, Data.Maybe
packages that produce the error: raw-strings-qq, HUnit
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?
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.