haskell list comprehension and local scoping

ghc -e 'let hw = let zhw = zip "hello" "world"; h = [fst x | x <- zhw]; w = [snd y | y <- zhw] in h ++ " " ++ w' -e 'hw'

Advertisements

haskell factorial function

ghc -e 'let {factorial 0 = 1; factorial n | n > 0 = product [1..n]; factorial n | n < 0 = (-1) * factorial (-n); factorial -n = (-1) * factorial n; }' -e 'factorial 5' -e 'factorial -6' -e 'factorial (-7)'