Skip to content

dominicprior/haskellnotes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Things I would like to learn

  • ~
  • forall
  • Lazy IO, conduits, ...
  • WHNF, seq
  • catch, throw
  • text, bytestring
  • react-flux, ghcjs

Snippets

a n | n > 0 = n | True = -n   Guards can go on one line

f 0 = 1 ; f n = n * f (n-1)   This works in GHCi

k :: Int ; k = 4   So does this

Just undefined `seq` 42   Demonstrates that Just expr is in WHNF

a `seq` b `seq` f a b   Forces a and b

ReaderT [String] (WriterT [String] ((StateT StdGen) (ST s))) (Image PixelRGB16)

withFile "b.txt" ReadMode hGetContents   hGetContents: illegal operation (delayed read on closed handle)

withFile "b.txt" ReadMode $ \h -> hGetContents h >>= putStr

Definitions

f $! x = x `seq` f x

seq :: a -> b -> b -- evaluates a to WHNF when seq a b is evaluated to WHNF

hGetContents h = IO.hGetContents h >>= \s -> length s `seq` return s -- strict version

Examples of things in WHNF

The outermost part is a data constructor

Just (2+2)

(1+1, 2+2)

'h' : ("e" ++ "llo")

Lambda

\x -> 2 + 2

About

Code snippets for learning Haskell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published