[Haskell-cafe] Question about type families

Grigory Sarnitskiy sargrigory at ya.ru
Tue Sep 13 16:58:21 CEST 2011

Is there a way to make the following code working?

{-# LANGUAGE TypeFamilies #-}

data family Foo a

data instance (Num a)        => Foo a = A a deriving Show

data instance (Fractional a) => Foo a = B a deriving Show

I want to have different constructors for 'Foo a' depending on a class of 'a'. Note also, that in the example above I also meant constructor A to be available for (Fractional a) => Foo, since in that case 'a' has Num too. How can I achieve it, maybe not with TypeFamilies? Current error is

    Conflicting family instance declarations:
      data instance Foo a -- Defined at 1.hs:7:33-35
      data instance Foo a -- Defined at 1.hs:5:33-35

More information about the Haskell-Cafe mailing list