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) -> (P->MR) [type type for
-the composition operator corrects a "type"-o from the class handout]
+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
'a, let the boxed type be 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]) = fun p -> [r | q <- first p, r <- second q]
Sanity check:
- f p = [x, x+1]
- s q = [x*x, x+x]
- >=> f s 7 = [49, 14, 64, 16]
+ 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 = [x, x+1]
- s q = [x*x, x+x]
- >=> f s 7 = [49, 64]
+ f p = [p, p+1]
+ s q = [q*q, q+q]
+ >=> f s 7 = [49, 16]
and then prove it obeys the monad laws.