Tried this out after I read about it. Note: the following was all done on a Macbook, but it should work similarly on Linux too.
Get Stack
Download it.
gunzip
and copy to some directory in $PATH
Use Stack
Create dummy .hs
file.
main = putStrLn "Hello World"
Digression: first build
You need GHC
installed, and a file called stack.yaml
in the local directory. But if you don't, no problem.
$ stack ghc dummy.hs
No .cabal file found in directory /Users/agam/Documents/Haskell/Dummy/
Writing default config file to: /Users/agam/Documents/Haskell/Dummy/stack.yaml
Downloading lts-2.13 build plan ...
Downloaded lts-2.13 build plan.
Populating index cache, may take a moment ...
Updating package index hackage.haskell.org ...
Cloning package index ...
Done populating index cache.
Downloading ghc-7.8.4 ...
Downloaded ghc-7.8.4.
Unpacking GHC ...
Configuring GHC ...
Installing GHC ...
GHC installed.
Run it once more to actually build it.
$ stack ghc dummy.hs
[1 of 1] Compiling Main ( dummy.hs, dummy.o )
Linking dummy ...
$ ls
stack.yaml dummy.o dummy.hs dummy.hi dummy
Run the program
Just run the executable created:
$ ./dummy
Hello World
Alternatively, combine steps 4 and 5
$ stack runghc dummy.hs
Hello World
Libraries
(this is why we're really here, right?)
$ stack update
Updating package index hackage.haskell.org ...
What packages do we have ?
$ stack exec -- ghc-pkg list
/Users/agam/.stack/programs/x86_64-osx/ghc-7.8.4/lib/ghc-7.8.4/package.conf.d/
Cabal-1.18.1.5
array-0.5.0.0
base-4.7.0.2
bin-package-db-0.0.0.0
binary-0.7.1.0
bytestring-0.10.4.0
containers-0.5.5.1
deepseq-1.3.0.2
directory-1.2.1.0
filepath-1.3.0.2
ghc-7.8.4
ghc-prim-0.3.1.0
haskeline-0.7.1.2
haskell2010-1.1.2.0
haskell98-2.0.0.3
hoopl-3.10.0.1
hpc-0.6.0.1
integer-gmp-0.5.1.0
old-locale-1.0.0.6
old-time-1.1.0.2
pretty-1.1.1.1
process-1.2.0.0
rts-1.0
template-haskell-2.9.0.0
terminfo-0.4.0.0
time-1.4.2
transformers-0.3.0.0
unix-2.7.0.1
xhtml-3000.2.1
Get a new package using Stack
First, we need to require some new package. Change dummy code to (e.g.)
import System.Random
import Control.Monad (replicateM)
main = replicateM 10 (randomIO :: IO Float) >>= print
Try to build it
$ stack ghc dummy.hs
dummy.hs:1:8:
Could not find module ‘System.Random’
Use -v to see a list of the files searched for.
So let's get it then:
$ stack deps random
random-1.1: downloading
random-1.1: configure
random-1.1: build
random-1.1: install
... and then run it again:
$ stack ghc dummy.hs
[1 of 1] Compiling Main ( dummy.hs, dummy.o )
Linking dummy ...
$ ./dummy
[0.4301154,0.9796305,4.801333e-2,0.6978437,0.45780963,0.21923387,0.33110678,0.2976914,5.8295727e-3,0.28221375]
Not bad at all. Reminds me of the feeling I got after wading through the plethora of python package handling frameworks and discovering Anaconda. This is finally a newbie-friendly language; "cabal hell" is no more (!)