fix formatting of `1`
[lambda.git] / exercises / _assignment7.mdwn
1 ## Baby monads
2
3 (Depends on lecture notes for safe division by zero.)
4
5 Write a function `lift'` that generalized the correspondence between +
6 and `add'`: that is, `lift'` takes any two-place operation on integers
7 and returns a version that takes arguments of type `int option`
8 instead, returning a result of `int option`.  In other words, `lift'`
9 will have type:
10
11         (int -> int -> int) -> (int option) -> (int option) -> (int option)
12
13 so that `lift' (+) (Some 3) (Some 4)` will evalute to `Some 7`.
14 Don't worry about why you need to put `+` inside of parentheses.
15 You should make use of `bind'` in your definition of `lift'`:
16
17         let bind' (u: int option) (f: int -> (int option)) =
18                 match u with None -> None | Some x -> f x;;