Skip to content

Instantly share code, notes, and snippets.

@singpolyma
Created September 24, 2012 14:02
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 singpolyma/3776098 to your computer and use it in GitHub Desktop.
Save singpolyma/3776098 to your computer and use it in GitHub Desktop.
"Class Aliases"
module NumberStuff where
import qualified Prelude
class CanAdd a where
(+) :: a -> a -> a
class CanNegate a where
negate :: a -> a
class FromInteger a where
fromInteger :: Prelude.Integer -> a
class (CanAdd a, CanNegate a, FromInteger a) => Num a
instance CanAdd Prelude.Integer where
(+) = (Prelude.+)
instance CanNegate Prelude.Integer where
negate = Prelude.negate
instance FromInteger Prelude.Integer where
fromInteger = Prelude.id
instance Num Prelude.Integer
someFunc :: (Num a) => a -> a
someFunc x = negate (x + x + fromInteger 12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment