X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=exercises%2F_assignment6.mdwn;h=ebc20e064bc1ad1f7d02756ad8a015913dfaea9d;hp=0f654f25daa146fb0dc4953bf9a861ebd77e47fa;hb=b13412acbd429e1cc83669d6e881e3d9e98fbda3;hpb=ff5b3f5a76fb744b332bc5d0fb3ef5632ce02879 diff --git a/exercises/_assignment6.mdwn b/exercises/_assignment6.mdwn index 0f654f25..ebc20e06 100644 --- a/exercises/_assignment6.mdwn +++ b/exercises/_assignment6.mdwn @@ -134,8 +134,9 @@ piece, which we can think of as a function from a type to a type. Call this type function M, and let P, Q, R, and S be variables over types. Recall that a monad requires a singleton function 1:P-> MP, and a -composition operator >=>: (P->MQ) -> (Q->MR) -> (R->MS) that obey the -following laws: +composition operator >=>: (P->MQ) -> (Q->MR) -> (P->MR) [the type for +the composition operator given here corrects a "type"-o from the class handout] +that obey the following laws: 1 >=> k = k k >=> 1 = k @@ -164,3 +165,16 @@ More specifically, Then the obvious singleton for the Option monad is \p.Just p. Give (or reconstruct) the composition operator >=> we discussed in class. Show your composition operator obeys the monad laws. + +2. Do the same with lists. That is, given an arbitrary type +'a, let the boxed type be ['a], i.e., a list of objects of type 'a. The singleton +is `\p.[p]`, and the composition operator is + + >=> (first:P->[Q]) (second:Q->[R]) :(P->[R]) = List.flatten (List.map f (g a)) + +For example: + + f p = [p, p+1] + s q = [q*q, q+q] + >=> f s 7 = [49, 14, 64, 16] +