Haskell Pure functional language
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
ghcighc -O2 -o <out> Main.hs
runghc <file.hs>
:t <expr>:rcabal runcabal replghcup tuiConcepts
GHC
ghc <file.hs>
ghc -o <out> <file.hs>
ghc -O2 <file.hs>
ghc -Wall <file.hs>
ghc -e '<expr>'
ghc -c <file.hs>
ghc --make Main.hs
ghc -i<dir> Main.hs
ghc -outputdir <dir> Main.hs
ghc -threaded -rtsopts Main.hs
ghc -package <pkg> Main.hs
ghc -prof -fprof-auto Main.hs
ghc -fno-code <file.hs>
ghc -XOverloadedStrings Main.hs
runghc <file.hs>
GHCi
ghci:l <file>:r:t <expr>:i <name>:k <type>:q:browse <Module>
:doc <name>
:set +t:m + <Module>
:main <args>
:set -X<Ext>
:! <cmd>let x = 5itCabal
cabal initcabal buildcabal run <exe>
cabal testcabal replcabal updatecabal install <pkg>
cabal install --lib <pkg>
cabal cleancabal haddockcabal benchcabal freezecabal list <text>
cabal build --enable-profiling
cabal run -- <args>
Stack and ghcup
stack new <name>
stack buildstack runstack teststack ghcistack exec <cmd>
stack install <pkg>
stack cleanstack pathghcup listghcup install ghc <ver>
ghcup set ghc <ver>
ghcup install cabal
ghcup upgradeTypes and classes
f :: Int -> Int
data T = A | B Int
data P = P { x :: Int }
newtype N = N Int
type S = Stringclass C a whereinstance C T where
deriving (Show, Eq, Ord)
f :: (Show a) => a -> String
Maybe aEither e a[a](a, b)IO aSyntax
f 0 = 1; f n = n * f (n-1)
case m of Just x -> x
f x | x > 0 = 1 | otherwise = 0
\x -> x + 1
let y = 2 in y * 2
f = g where g = 1
if c then a else b
do { x <- act; return x }
[x*2 | x <- xs, x > 1]
f . gf $ g xxs !! 2import qualified Data.Map as M
-- note / {- note -}
Common functions
map f xsfilter p xsfoldr f z xsfoldl' f z xs
zip xs ysfmap f m / f <$> m
mapM_ print xsmaybe d f meither f g eread s :: Intshow xputStrLn sgetLinesequence_ / traverse
Recipes
main :: IO ()main = putStrLn "Hello"-- ghc -O2 -Wall -o hello Hello.hs
safeDiv :: Int -> Int -> Maybe IntsafeDiv _ 0 = NothingsafeDiv a b = Just (a `div` b)main = print (safeDiv 4 2 >>= safeDiv 10)
data Color = Red | Green deriving (Eq, Show)class Pretty a where pretty :: a -> Stringinstance Pretty Color where pretty Red = "red" pretty Green = "green"
mkdir demo && cd democabal init --non-interactivecabal build && cabal runcabal repl



