X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?a=blobdiff_plain;f=exercises%2F_assignment6.mdwn;fp=exercises%2F_assignment6.mdwn;h=86c398ff08e96c7fcc01d64a2846f5fcd395b613;hb=a305ebfcf57b336d71c90664d504172fc1b91f6b;hp=9a3d04c049c4733d854cfd51ea829b13d4e7f24c;hpb=8757b34632a67ffd9d55d182500608b1f0198394;p=lambda.git diff --git a/exercises/_assignment6.mdwn b/exercises/_assignment6.mdwn index 9a3d04c0..86c398ff 100644 --- a/exercises/_assignment6.mdwn +++ b/exercises/_assignment6.mdwn @@ -112,3 +112,21 @@ our scorecard. On the simple-minded view, we would replace it with `w`. But that's not the right result, because `w` itself has been mapped onto 2. +## Baby monads + +(Depends on lecture notes for safe division by zero.) + +Write a function `lift'` that generalized the correspondence between + +and `add'`: that is, `lift'` takes any two-place operation on integers +and returns a version that takes arguments of type `int option` +instead, returning a result of `int option`. In other words, `lift'` +will have type: + + (int -> int -> int) -> (int option) -> (int option) -> (int option) + +so that `lift' (+) (Some 3) (Some 4)` will evalute to `Some 7`. +Don't worry about why you need to put `+` inside of parentheses. +You should make use of `bind'` in your definition of `lift'`: + + let bind' (u: int option) (f: int -> (int option)) = + match u with None -> None | Some x -> f x;;