Declaration vs. expression style

From HaskellWiki
Revision as of 12:42, 3 July 2007 by Lemming (talk | contribs) (taken table from "History of Haskell")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

There are two main styles of writing functional programs, which are both supported by Haskell mainly because several language designers preferred these different styles.

There are characteristic elements of both styles.

Declaration style Expression-style
where clause let expression
Function arguments on left hand side: f x = x*x Lambda abstraction: f = \x -> x*x
Pattern matching in function definitions: f [] = 0 case expression: f xs = case xs of [] -> 0
Guards on function definitions: f [x] | x>0 = 'a' if expression: f [x] = if x>0 then 'a' else ...

See also