Skip to content

Instantly share code, notes, and snippets.

@chemikadze
Created September 12, 2012 20:35
Show Gist options
  • Save chemikadze/3709707 to your computer and use it in GitHub Desktop.
Save chemikadze/3709707 to your computer and use it in GitHub Desktop.
Как поднять штангу (пособие для хаскелистов)
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