Skip to content

Instantly share code, notes, and snippets.

@rewinfrey
Created June 4, 2016 16:32
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 rewinfrey/ef90873ac729648657198eddce752974 to your computer and use it in GitHub Desktop.
Save rewinfrey/ef90873ac729648657198eddce752974 to your computer and use it in GitHub Desktop.
Parametric Polymorphism example over tiles
module TilesParametricPolymorphism where
class Tile a where
over :: a -> a
instance Tile (Dora Character) where
over MultiSet (Dora Character) -> undefined
instance Tile (Dora Circle) where
over MultiSet (Dora Circle) -> undefined
instance Tile (Dora Bamboo) where
over MultiSet (Dora Bamboo) -> undefined
instance Tile (Dora Wind) where
over MultiSet (Dora Wind) -> undefined
instance Tile (Dora Dragon) where
over MultiSet (Dora Dragon) -> undefined
over :: Hand -> Hand
over h = h { characters = over (characters h)
, circles = over (circles h)
, bamboo = over (bamboo h)
, wind = over (wind h)
, dragon = over (dragon h)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment