From b04c88ae4081976cc721ab9e9fb0b89bd5962942 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 15 Mar 2015 13:24:08 -0400 Subject: [PATCH] edits --- exercises/_assignment6.mdwn | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/exercises/_assignment6.mdwn b/exercises/_assignment6.mdwn index 0f654f25..50e89ac8 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) [type type for +the composition operator corrects a "type"-o from the class handout] +that obey the following laws: 1 >=> k = k k >=> 1 = k @@ -164,3 +165,24 @@ 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 crossy lists. That is, given an arbitrary type +'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] + +Sanity check: + + f p = [x, x+1] + s q = [x*x, x+x] + >=> 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] + +and then prove it obeys the monad laws. -- 2.11.0