Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Haskell's 'Generic' class type family 'Rep a' annotated as a type constructor, and not a type?

Tags:

haskell

Consider Haskell's Generic class :

class Generic a where
  -- | Generic representation type
  type Rep a :: * -> *
  -- | Convert from the datatype to its representation
  from  :: a -> (Rep a) x
  -- | Convert from the representation to the datatype
  to    :: (Rep a) x -> a

I'm curious as to why it wasn't written as below:

class Generic a where
  -- | Generic representation type
  type Rep a :: *
  -- | Convert from the datatype to its representation
  from  :: a -> Rep a
  -- | Convert from the representation to the datatype
  to    :: Rep a -> a

More specifically what does the type variable x stand for in the standard definition?

like image 624
shayan Avatar asked Oct 06 '20 21:10

shayan


1 Answers

This is done to allow the Generic and Generic1 classes to share most of their representation types. Whether this was really a good idea is debatable. Just do your best to ignore the extra parameter.

like image 104
dfeuer Avatar answered Nov 16 '22 01:11

dfeuer