Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Functor instance for (newtype Mu f = InF {outF :: f (Mu f)})

This has me stumped. How do you write a Functor instance for newtype Mu f = InF {outF :: f (Mu f)}

like image 946
user1897830 Avatar asked Dec 19 '22 13:12

user1897830


1 Answers

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.

like image 63
redneb Avatar answered Jan 08 '23 04:01

redneb