Created
September 12, 2012 20:35
-
-
Save chemikadze/3709707 to your computer and use it in GitHub Desktop.
Как поднять штангу (пособие для хаскелистов)
This file contains 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
data LegHealth = Healthy | Broken deriving (Show) | |
data HumanLegs a = Legs a deriving (Show) | |
instance Functor HumanLegs where | |
fmap f (Legs st) = Legs $ f st | |
barbell :: LegHealth -> LegHealth | |
barbell _ = Broken -- playing with iron always ends very bad | |
useBarbell :: HumanLegs LegHealth -> HumanLegs LegHealth | |
useBarbell = fmap barbell -- yay, we lifted it! | |
main = do | |
let leg = Legs Healthy | |
case useBarbell leg of | |
Legs Healthy -> putStrLn "I'm ok!" | |
Legs Broken -> putStrLn "Oh noes :(" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment