Content deleted Content added
Citation bot (talk | contribs) Add: title, date. Changed bare reference to CS1/2. | Use this bot. Report bugs. | Suggested by BrownHairedGirl | Linked from User:BrownHairedGirl/Articles_with_bare_links | #UCB_webform_linked 1983/2198 |
→Example code: separated de use of _ to make more clear the example of case and changed the name of lambda expression to hello to avoid confusion with languages that use the lambda keyword |
||
Line 102:
hypotenuse a b =
sqrt (a^2 + b^2)
-- We can create lambda functions with the `\[arg] -> [expression]` syntax.▼
-- Function declarations may have the anonymous parameter names denoted by `_`, which are matched but not used in the body.
const : a -> b -> a
const k _ = k
-- Functions are also curried; here we've curried the multiplication
Line 137 ⟶ 146:
= Empty
| Node a (Tree a) (Tree a)
▲-- We can create lambda functions with the `\[arg] -> [expression]` syntax.
▲lambda : String -> String
▲lambda = \s -> "Hi, " ++ s
-- It is possible to inspect these types with case-expressions.
Line 146 ⟶ 151:
depth tree =
case tree of
Empty -> 0
Node _ left right ->
1 + max (depth left) (depth right)
|