
2009/4/28 Tuve Nordius
If I for some data type wants to derive, in this case Data and Typeable for use with syb code, but the problem is the same regardless what I want to derive.
data family Something
data Tree = Leaf Something | Fork Something Tree Tree deriving (Data, Typeable)
The problem is I want to derive a class for a data type that depends on some non instantiated data type.
I can of course rewrite Tree as:
data (Data a) => Tree a = Leaf a | Fork a Tree Tree deriving (Data, Typeable)
but then data family Something is redundant, I want to think of Something as a not yet instantiated abstract data type
Is there anyway to express that either the instance of Something used in Tree should be a member of Data, or even better any instance of Something should be a member of Data or maybe even better that every instance should derive data.
data family Something deriving Data
//Tuve Nordius_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
If you enable flexible contexts, you can have something like class Data (Something a) => HasSomething a where data Something a It turns out you can't have contexts on family declarations themselves, though, hence the dummy class. (BTW, you were missing the parameters on your family declarations.) Plus, trying it just now, you can't derive Typeable for family instances, so you'll need to write it longhand. Data seems to be OK, though.