Created
January 18, 2016 07:54
-
-
Save akhileshs/887974e4003a3da7a780 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
class CanQuack a where | |
quack :: a -> IO () | |
class HasFeathers a where | |
feathers :: a -> IO () | |
data Duck = Duck | |
data Person = Person | |
instance CanQuack Duck where | |
quack _ = putStrLn "Quaaaaack!" | |
instance HasFeathers Duck where | |
feathers _ = putStrLn "The duck has white and gray feathers." | |
instance CanQuack Person where | |
quack _ = putStrLn "The persom imitates a duck." | |
instance HasFeathers Person where | |
feathers _ = putStrLn "The person takes a feather from the ground and shows it." | |
-- Optional type is: | |
-- inTheForst :: (CanQuack obj, HasFeathers obj) => obj -> IO () | |
inTheForst duck = do | |
quack duck | |
feathers duck | |
game = do | |
let donald = Duck | |
let john = Person | |
inTheForst donald | |
inTheForst john | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment