I want to create a type class for various types of "columns of stuff", so something like this:
class Column c where
at :: c a -> Int -> a
data ListColumn a = ListColumn {
lcContent :: [a]
}
instance Column ListColumn where
at c i = lcContent c !! i
Now I want to derive one column from another. Say I have a column of customers, and I want to derive a column of customer names from that. So I wrote:
data DerivedColumn a b c = DerivedColumn {
dcBase :: c a,
dcDerive :: a -> b
}
a
being the customer, b
the customer name in the example above. Now I thought I could write something like this:
instance Column (DerivedColumn a b) where
at c i = dcDerive c $ at (dcBase c) i
But ghc does not seem to like it (Column should have kind * -> *, but DerivedColumn a b has kind (* -> *) -> *
). Can someone please point in the right direction...?
DerivedColumn
to have the container type,a
, last? So the definition should bedata DerivedColumn c b a = ...
? TheColumn
typeclass expects a type that it can apply a container type to in order to get a concrete type. – Alexis King