From 1fd43d5222e15edd0211e106e44deffd2874189a Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 16 Mar 2015 15:38:17 -0400 Subject: [PATCH 1/1] edits --- topics/_week7_monads.mdwn | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/topics/_week7_monads.mdwn b/topics/_week7_monads.mdwn index b9be5bae..7d189e4d 100644 --- a/topics/_week7_monads.mdwn +++ b/topics/_week7_monads.mdwn @@ -156,30 +156,21 @@ consider the box type `α List`, with the following operations: mid: α -> [α] mid a = [a] - mcompose-crossy: (β -> [γ]) -> (α -> [β]) -> (α -> [γ]) - mcompose-crossy f g a = [c | b <- g a, c <- f b] - mcompose-crossy f g a = foldr (\b -> \gs -> (f b) ++ gs) [] (g a) - mcompose-crossy f g a = concat (map f (g a)) + mcompose: (β -> [γ]) -> (α -> [β]) -> (α -> [γ]) + mcompose f g a = concat (map f (g a)) + = foldr (\b -> \gs -> (f b) ++ gs) [] (g a) + = [c | b <- g a, c <- f b] -These three definitions are all equivalent. -In words, `mcompose f g a` feeds the a (which has type α) to g, which -returns a list of βs; each β in that list is fed to f, which returns a -list of γs. +These three definitions are all equivalent. In words, `mcompose f g +a` feeds the a (which has type α) to g, which returns a list of βs; +each β in that list is fed to f, which returns a list of γs. The +final result is the concatenation of those lists of γs. -The final result is the concatenation of those lists of γs. For example, let f b = [b, b+1] in let g a = [a*a, a+a] in - mcompose-crossy f g 7 = [49, 50, 14, 15] + mcompose f g 7 = [49, 50, 14, 15] It is easy to see that these definitions obey the monad laws (see exercises). -There can be multiple monads for any given box type. For instance, -using the same box type and the same mid, we can define - - mcompose-zippy f g a = foldr (\b -> \gs -> f b ++ gs) (g a) [] - -so that - - mcompose-zippy f g 7 = [49, 14] -- 2.11.0