U1
sits in constructors without paramsSuppose we have the following type along with a value for that type:
data ISBN = ISBN Int
book :: ISBN
book = ISBN 9780441478125
The generics representation of that book
value will look like this:
type parameter nested
info info value
| | |
M1 (M1 (M1 (K1 9780441478125)))
| |
constructor nested type
info wrapper
Now consider another type with only a single constructor, but no parameter:
data Carrot = Carrot
carrot :: Carrot
carrot = Carrot
We expect the generics representation of carrot
to also contain the
M1
wrappers with the type and constructor information, but what do we
nest inside?
M1 (M1 ( ??? ))
The answer: U1
. It’s a lot like ()
(unit): a filler type.
It’s definition is:
data U1 p = U1