X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=exercises%2F_assignment6.mdwn;h=ebc20e064bc1ad1f7d02756ad8a015913dfaea9d;hp=cd9db08681ddbf5bac92585cda68f5343f2100f1;hb=b13412acbd429e1cc83669d6e881e3d9e98fbda3;hpb=28a4f4e37ae8c8c189186b5cd49ab055a3646f57 diff --git a/exercises/_assignment6.mdwn b/exercises/_assignment6.mdwn index cd9db086..ebc20e06 100644 --- a/exercises/_assignment6.mdwn +++ b/exercises/_assignment6.mdwn @@ -166,23 +166,15 @@ 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 crossy lists. That is, given an arbitrary type -'a, let the boxed type be a list of objects of type 'a. The singleton +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]) = fun p -> [r | q <- first p, r <- second q] + >=> (first:P->[Q]) (second:Q->[R]) :(P->[R]) = List.flatten (List.map f (g a)) -Sanity check: +For example: f p = [p, p+1] s q = [q*q, q+q] >=> f s 7 = [49, 14, 64, 16] -3. Do the same for zippy lists. That is, you need to find a -composition operator such that - - f p = [p, p+1] - s q = [q*q, q+q] - >=> f s 7 = [49, 64] - -and then prove it obeys the monad laws.