Good wiki book at http://en.wikibooks.org/wiki/Haskell
- Assignment is prefixed with 'let' in ghci but not in ghc or loaded .hs files
- let x = 3
- x = 3
- Assignment of the result of an IO action is via <-
- x <- getLine
- x <- getLine
- Function declarations do NOT use parenthesis or comma.
- funname parm1, parm2 = parm1 - 6 * parm2
- List literals use square brackets and commas; they can also be written with colons and an empty list
- x = [1,2,3]
- x = 1:2:3:[]
- List elements must have the same type (i.e. the list's type is "list of x" and not just "list")
- True/False are written in title case, and have type Bool.
- True
- False
- Strings use proper direct-quote marks. They have type 'list of Char' in addition to String.
- "string"
- "string"
- Characters use apostrophes (a.k.a.single-quotes)
- 'x'
- 'x'
- Colon is used to prepend a single value to a list
- value:list
- Tuples use parenthesis and commas and need not have elements of the same type
- x = (1, "b", False)
- fst and snd retrieve the first and second items from a pair respectively (i.e. a 2-tuple)
- if statements are of the form:
- if condition
- then value
- else value
- if condition
- case statements are of the form:
- case var of
- pattern1 -> result1
- pattern2 -> result2
- _ -> result3
- case var of
- Function composition: the following are equivalent
- (f . g) x
- f(g(x))
- Local variables:
let a = 3
b = 2
in (blahblahblah,
bleebleeblee)
- putStrLn <string>
- show <variable>
- return "abcd"
- x <- return "foo"