Functor <constant>

Serge D. Mechveliani mechvel at
Wed Sep 9 12:45:52 EDT 2009


I have   data DBit     = Bit0 | Bit1  deriving (Eq, Ord, Enum)
         data BNatural = BNat [DBit]  deriving (Eq)

and want to apply things like  fmap reverse (bn :: BNatural).

GHC reports an error on this usage of  fmap.
It also does not allow      
        instance Functor BNatural where  fmap f (BNat ds) = BNat $ f ds,
-- it reports that a type constructor for Functor must have kind  * -> *.
Probaly, GHC agrees with Haskell at this point (?).

Now, I deceive the compiler by declaring instead

    newtype BNatAux a = BNat a  deriving (Eq)
    type    BNatural  = BNatAux [DBit]
    instance Functor BNatAux where  fmap f (BNat ds) = BNat $ f ds

So, a parasitic  BNatAux  is introduced.
I wonder: is there a simpler way to have  fmap  for BNatural ?
Thank you in advance for advice,

Serge Mechveliani
mechvel at

More information about the Glasgow-haskell-users mailing list