Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data Sheep = Sheep { name::String,
- mom::Maybe Sheep,
- dad::Maybe Sheep
- }
- instance Show Sheep where
- show s = show ( name s )
- comb :: Maybe a -> (a -> Maybe b) -> Maybe b
- comb Nothing _ = Nothing
- comb (Just x) f = f x
- breedSheep :: Sheep
- breedSheep = let adam = Sheep "Adam" Nothing Nothing
- eve = Sheep "Eve" Nothing Nothing
- thierry = Sheep "Thierry" (Just eve) (Just adam)
- edith = Sheep "Edith" (Just eve) (Just adam)
- cecile = Sheep "Cecile" (Just edith) (Just thierry)
- in Sheep "Dolly" (Just cecile) Nothing
- maternalGrandfather :: Sheep -> Maybe Sheep
- maternalGrandfather s = (Just s) `comb` mom `comb` dad
- main :: IO ()
- main = let dolly = breedSheep
- in do { print (mom dolly); print (dad dolly); print (maternalGrandfather dolly); }
Add Comment
Please, Sign In to add comment