The reason this doesn't work is because f :: D -> D
. D
wants a function which can take in any type x
and return x
. This is equivalent to
d :: forall a. a -> a
As you can see, the only sane implementation for this is id
. Try
data D = D (D -> D)
...
unit = D id
Perhaps for better printing:
data D = DFunc (D -> D) | DNumber Int