I'm trying to make a typeclass for signed numerical types. Here's my code:
{-# LANGUAGE TypeFamilies, FlexibleContexts, UndecidableInstances #-}
data Sign = Negative | Zero | Positive
deriving (Eq, Ord, Read, Show)
class Signed a where
sign :: a -> Sign
instance Signed Integer where
sign = undefined
This compiles, but I'd like to adapt this code to work on any Integral a
.
instance (Integral a) => Signed a where
sign = undefined
At which point it fails to compile.
I've checked Haskell type family instance with type constraints, but that seems to be addressing a different problem from mine. I don't think there's a syntax error, in my code.