$ brew install haskell-platform
~/.cabal/
, and the scripts go to ~/.cabal/bin/
. You need to add these paths to the PATH environment variable. Something similar is enough, but it all depends on your preferences (I personally use ~/.profile
for this purpose - approx. Translator): $ echo 'export PATH=$HOME/.cabal/bin:$PATH' >> ~/.bashrc
$ cabal update
~/.cabal/config
without library profiling enabled. You will probably want to use it later, and if you do not turn it on now, you will have to rebuild everything in the future. To enable it, change the line -- library-profiling: False
to library-profiling: True
in the file ~/.cabal/config
. $ for f in ~/.cabal/config; do \ cp $f $f.old && \ sed -E 's/(-- )?(library-profiling: )False/\2True/' < $f.old > $f; \ done
$ cabal install cabal-install
$ cabal install ghc-mod
cabal-dev
instead of simple cabal
to build wherever possible. The main compromise is that you have to spend (much) more time compiling packages that have already been installed somewhere else (and fill up disk space), but this is certainly a fair fee.cabal install cabal-dev
, but so far no one has closed bug # 74 , you will have to build and install it from source: $ git clone https://github.com/creswick/cabal-dev.git /tmp/cabal-dev-src && \ (cd /tmp/cabal-dev-src; cabal install) && \ rm -rf /tmp/cabal-dev-src
./cabal-dev
, but you can keep it anywhere. In this example, I will install darcs 2.8.2 (a distributed version control system written in Haskell) into the /usr/local/Cellar/darcs/2.8.2
folder and ask Homebrew to make symlinks for me. On other platforms, you will most likely have to use your own directory structure, and also manually edit your PATH. $ cabal-dev install -s /usr/local/Cellar/darcs/2.8.2 darcs-2.8.2 $ brew link --overwrite darcs
--overwrite
can use --overwrite
almost painlessly, but I recommend that you first --overwrite --dry-run
with the --overwrite --dry-run
key --overwrite --dry-run
. It bothers you, but surely will not spoil you the whole day.use cabal info darcs
and find the Versions available:
section Versions available:
$ git clone https://github.com/bos/pronk.git /tmp/pronk-src && \ (cd /tmp/pronk-src; \ cabal-dev install -s /usr/local/Cellar/pronk/$(git rev-parse --short HEAD)) && \ rm -rf /tmp/pronk-src
Prelude>
Prelude> :m + Data.List Prelude Data.List> :m + Data.Maybe Prelude Data.List Data.Maybe>
echo ':set prompt "h> "' >> ~/.ghci
:set prompt "h> "
every time you start GHCi, but this is also superfluous. $ ghci h> putStrLn "Hello World!" Hello World! h>
remote-repo: hackage.haskell.org:http://hackage.haskell.org/packages/archive
-- TODO When hackage is back up, set back to hackage.haskell.org! -- remote-repo: hackage.haskell.org:http://hackage.haskell.org/packages/archive remote-repo: hdiff.luite.com:http://hdiff.luite.com/packages/archive -- remote-repo: hackage.csc.stanford.edu:http://hackage.scs.stanford.edu/packages/archive
$ cabal update
-n
option to specify the list of necessary options manually. The -n
option uses all the default settings and does not ask you anything. $ mkdir -p ~/src/hs-hello-world $ cd ~/src/hs-hello-world $ touch LICENSE $ cabal init -n --is-executable
Setup.hs
and hs-hello-world.cabal
. The next step is to change the line main-is:
so that bondage knows from which source code to compile the executable file. The end result should be like this: -- Initial hs-hello-world.cabal generated by cabal init. For further -- documentation, see http://haskell.org/cabal/users-guide/ name: hs-hello-world version: 0.1.0.0 -- synopsis: -- description: license: AllRightsReserved license-file: LICENSE -- author: -- maintainer: -- copyright: -- category: build-type: Simple cabal-version: >=1.8 executable hs-hello-world main-is: HelloWorld.hs -- other-modules: build-depends: base ==4.5.*
HelloWorld.hs
, with the following contents: main :: IO () main = putStrLn "Hello, world!"
$ cabal-dev install Resolving dependencies... Configuring hs-hello-world-0.1.0.0... Building hs-hello-world-0.1.0.0... Preprocessing executable 'hs-hello-world' for hs-hello-world-0.1.0.0... Installing executable(s) in /Users/bob/src/hs-hello-world/cabal-dev//bin Installed hs-hello-world-0.1.0.0 $ ./cabal-dev/bin/hs-hello-world Hello, world!
$ cabal-dev configure Resolving dependencies... Configuring hs-hello-world-0.1.0.0... $ cabal-dev build Building hs-hello-world-0.1.0.0... Preprocessing executable 'hs-hello-world' for hs-hello-world-0.1.0.0... [1 of 1] Compiling Main ( HelloWorld.hs, dist/build/hs-hello-world/hs-hello-world-tmp/Main.o ) Linking dist/build/hs-hello-world/hs-hello-world ... $ ./dist/build/hs-hello-world/hs-hello-world Hello, world!
$ runghc HelloWorld.hs Hello, world!
$ ghci GHCi, version 7.4.2: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> :load HelloWorld [1 of 1] Compiling Main ( HelloWorld.hs, interpreted ) Ok, modules loaded: Main. *Main> main Hello, world!
cabal-dev
(or cabal
): $ runghc Setup.hs configure Configuring hs-hello-world-0.1.0.0... $ runghc Setup.hs build Building hs-hello-world-0.1.0.0... Preprocessing executable 'hs-hello-world' for hs-hello-world-0.1.0.0... [1 of 1] Compiling Main ( HelloWorld.hs, dist/build/hs-hello-world/hs-hello-world-tmp/Main.o ) Linking dist/build/hs-hello-world/hs-hello-world ...
cabal-dev ghci
(after cabal-dev configure && cabal-dev build
). Please note that in this case the code will be loaded into the interpreter automatically: $ cabal-dev ghci on the commandline: Warning: -O conflicts with --interactive; -O ignored. GHCi, version 7.4.2: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Ok, modules loaded: Main. h> main Hello, world!
h> :t main main :: IO () h> :t map map :: (a -> b) -> [a] -> [b] h> :t map (+1) map (+1) :: Num b => [b] -> [b]
h> :i Num class Num a where (+) :: a -> a -> a (*) :: a -> a -> a (-) :: a -> a -> a negate :: a -> a abs :: a -> a signum :: a -> a fromInteger :: Integer -> a -- Defined in `GHC.Num' instance Num Integer -- Defined in `GHC.Num' instance Num Int -- Defined in `GHC.Num' instance Num Float -- Defined in `GHC.Float' instance Num Double -- Defined in `GHC.Float' h> :info map map :: (a -> b) -> [a] -> [b] -- Defined in `GHC.Base' h> :info Int data Int = ghc-prim:GHC.Types.I# ghc-prim:GHC.Prim.Int# -- Defined in `ghc-prim:GHC.Types' instance Bounded Int -- Defined in `GHC.Enum' instance Enum Int -- Defined in `GHC.Enum' instance Eq Int -- Defined in `ghc-prim:GHC.Classes' instance Integral Int -- Defined in `GHC.Real' instance Num Int -- Defined in `GHC.Num' instance Ord Int -- Defined in `ghc-prim:GHC.Classes' instance Read Int -- Defined in `GHC.Read' instance Real Int -- Defined in `GHC.Real' instance Show Int -- Defined in `GHC.Show'
h> :m + Data.List h> sort [10,9..1] [1,2,3,4,5,6,7,8,9,10]
h> :! echo 'hello = print "hello"' > Hello.hs h> :l Hello [1 of 1] Compiling Main ( Hello.hs, interpreted ) Ok, modules loaded: Main. h> hello "hello" h> :! echo 'hello = print "HELLO"' > Hello.hs h> :r [1 of 1] Compiling Main ( Hello.hs, interpreted ) Ok, modules loaded: Main. h> hello "HELLO"
Source: https://habr.com/ru/post/165559/
All Articles