Last active
August 29, 2015 14:00
-
-
Save slimane/11343090 to your computer and use it in GitHub Desktop.
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 Duck where | |
class Duck a where | |
quack :: a -> String | |
feathers :: a -> String | |
data Person = Person deriving(Show) | |
data DomesticDuck = DomesticDuck deriving(Show) | |
instance Duck Person where | |
quack _ = "The person imitates a duck." | |
feathers _ = "The person takes a feather from the ground and shows it." | |
instance Duck DomesticDuck where | |
quack _ = "Quaaaaaack !" | |
feathers _ = "The duck has white and gray feathers." | |
inTheForest :: (Duck a) => a -> IO () | |
inTheForest d = do | |
putStrLn $ quack d | |
putStrLn $ feathers d | |
return () | |
main :: IO () | |
main = do | |
inTheForest Person | |
inTheForest DomesticDuck | |
return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment