Skip to content

Instantly share code, notes, and snippets.

@ooharak
Created February 6, 2013 04:56
Show Gist options
  • Select an option

  • Save ooharak/4720451 to your computer and use it in GitHub Desktop.

Select an option

Save ooharak/4720451 to your computer and use it in GitHub Desktop.
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