Skip to content

Instantly share code, notes, and snippets.

@slimane
Last active August 29, 2015 14:00
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 slimane/11343090 to your computer and use it in GitHub Desktop.
Save slimane/11343090 to your computer and use it in GitHub Desktop.
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