Skip to content

Instantly share code, notes, and snippets.

@akhileshs
Created January 18, 2016 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhileshs/887974e4003a3da7a780 to your computer and use it in GitHub Desktop.
Save akhileshs/887974e4003a3da7a780 to your computer and use it in GitHub Desktop.
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