Created
February 6, 2013 04:56
-
-
Save ooharak/4720451 to your computer and use it in GitHub Desktop.
A personal study note after http://en.wikibooks.org/wiki/Programming:Haskell_monads
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
| module Monadwiki | |
| where | |
| {- | |
| A personal study note after | |
| http://en.wikibooks.org/wiki/Programming:Haskell_monads | |
| -} | |
| data Person = Person { name::String, father::Maybe Person, mother::Maybe Person } | |
| deriving (Show,Eq) | |
| ore = Person { | |
| name="Ore", | |
| father = Just Person { | |
| name="Oyaji", | |
| father=Just Person { | |
| name="Oyaji-no-Oyaji", | |
| father=Nothing, | |
| mother=Nothing | |
| }, | |
| mother=Nothing | |
| }, | |
| mother = Just Person { | |
| name="Ofukuro", | |
| father= Just Person { | |
| name="Ofukuro-no-Oyaji", | |
| father=Nothing, | |
| mother=Nothing | |
| }, | |
| mother=Nothing | |
| } | |
| } | |
| {- monad example shown on the page -} | |
| mgf p = mother p >>= father | |
| {- my example -} | |
| myMgf p = let m = mother p | |
| in | |
| case m of | |
| Nothing -> Nothing | |
| Just b -> father b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment