Created
November 8, 2008 05:29
-
-
Save vito/23030 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f :: String -> [String] | |
f x = [x ++ "!", x ++ "."] | |
["Hi"] >>= f >>= f | |
-- is: | |
(["Hi"] >>= f) >>= f | |
-- Which, according to the Prelude implementation of the List monad...: | |
instance Monad [] where | |
m >>= k = concat (map k m) | |
return x = [x] | |
fail s = [] | |
-- ...does: | |
{- 1 -} concat (map f (["Hi"] >>= f)) | |
{- 2 -} concat (map f (concat (map f ["Hi"]))) | |
{- 3 -} concat (map f (concat [["Hi!", "Hi."]])) | |
{- 4 -} concat (map f ["Hi!", "Hi."]) | |
{- 5 -} concat [["Hi!!", "Hi!."], ["Hi.!", "Hi.."]] | |
{- 6 -} ["Hi!!", "Hi!.", "Hi.!", "Hi.."] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f :: String -> [String] | |
f x = [x ++ "!", x ++ "."] | |
main = print $ ["Hi"] >>= f >>= f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
["Hi!!","Hi!.","Hi.!","Hi.."] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment