Setting up GHCI via stack
- Install haskell tool stack
stack setup
stack ghci
- search for package atom-beautify language-haskell linter linter-hlint
stack install stylish-haskell
- To import modules
:m +Data.List
- To undo import modules
:m -Data.List
- To load
:l workspace.hs
- To reload
:r
- To find out more info
:i (++)
- To find out type
:t (++)
- To key in a block of codes
:{ :}
λ> :{
Prelude| k (x,y) = x
Prelude| :}
k :: (t, t1) -> t
- To browse functions in a module
:browse! Data.Maybe
λ> :browse! Data.Maybe
-- not currently imported
Data.Maybe.catMaybes :: [Maybe a] -> [a]
Data.Maybe.fromJust :: Maybe a -> a
Data.Maybe.fromMaybe :: a -> Maybe a -> a
Data.Maybe.isJust :: Maybe a -> Bool
Data.Maybe.isNothing :: Maybe a -> Bool
Data.Maybe.listToMaybe :: [a] -> Maybe a
Data.Maybe.mapMaybe :: (a -> Maybe b) -> [a] -> [b]
Data.Maybe.maybeToList :: Maybe a -> [a]
-- imported via Prelude
maybe :: b -> (a -> b) -> Maybe a -> b
Just :: a -> Maybe a
data Maybe a = Nothing | Just a
Nothing :: Maybe a
Edit appropriate ghci.conf file.
In Windows : C:\Users\lbh\AppData\Roaming\ghc\ghci.conf
In Mac : /Users/lbh/.ghc/ghci.conf
- Set ghci to accept multiline input
- Change the prompt
- Show type after evaluation
- Set macro for displaying present working Directory
- Set macro for git add all
- Set macro for git commit all with message
- Set macro for git push
:set +m
:set prompt "\x03BB> "
:set +t
:def pwd (\_-> System.Directory.getCurrentDirectory >>= print >> return "")
:def gitA (\_ -> System.Process.rawSystem "git" ["add", "-A"] >>= print >> return "")
:def gitC (\m -> System.Process.rawSystem "git" ["commit", "-am", m] >>= print >> return "")
:def gitP (\_ -> System.Process.rawSystem "git" ["push"] >>= print >> return "")
Changing directory within GHCI
--because of macro set in earlier step
λ> :pwd
"C:\\Users\\lbh"
λ> :cd haskell\\
λ> :pwd
"C:\\Users\\lbh\\haskell"
stack ghc -- Main.hs -o simple
generates the interface file .hi and object file .o as well as linking the executable "simple"
- If your source file has dependencies on other object files they will be linked automatically assuming they are in the same directory
Compiling modular haskell files
- Assuming you have a Listy.hs and a ListIntances.hs depends on it
stack ghc -- ListyInstances.hs -I. --make
We include the current directory and make modules within it discoverable
cabal init --help
cabal init -n -l BSD3 --is-executable --language=Haskell2010 -a 'laiboonh' -s 'Saying Hello' -p hello-haskell
cabal sandbox init
To isolate dependencies to this project, if not dependencies will be installed into package-db in home directory
cabal install --only-dependencies
To install dependencies
cabal build
./dist/build/hello-haskell/hello-haskell
cabal repl
Including a locally developed library
cabal sandbox init
cabal sandbox add-source ../hello-haskell
cabal install --only-dependencies
Including Test suite in Cabal
cabal configure --enable-tests