This has me stumped. How do you write a Functor instance for newtype Mu f = InF {outF :: f (Mu f)}
You can't. In order to define an instance Functor c
for some c
, c
must be of the kind * -> *
. So in your case, Mu
should have been of that kind, which means that its argument f
must have been of the kind *
. But clearly this is not the case, as you are applying f
to something else (to Mu f
).
To put it more simply, if Mu
was a functor, you could use fmap
on values of type Mu f
for any f
. But this would have allowed you to change the type parameter to any other type, e.g., by applying the function fmap (const (0 :: Int))
to any Mu f
value, it would have to return a Mu Int
value. But you can not form such a value because the outF
of that value would have had type Int (Mu Int)
which does not make sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With