Skip to content

Instantly share code, notes, and snippets.

@joker1007
Created July 31, 2012 12:33
Show Gist options
  • Save joker1007/3216725 to your computer and use it in GitHub Desktop.
Save joker1007/3216725 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
class Color a where
toValue :: a -> (Int, Int, Int)
data Red = Red deriving Show
data Blue = Blue deriving Show
instance Color Red where
toValue _ = (255, 0, 0)
instance Color Blue where
toValue _ = (0, 255, 0)
class YesNo a where
yesno :: a -> Bool
instance YesNo Char where
yesno _ = True
instance YesNo [a] where
yesno [] = False
yesno _ = True
instance (Integral a) => YesNo a where
yesno n
| toInteger n == 0 = False
| otherwise = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment