{-# LANGUAGE RankNTypes #-}
newtype Coyoneda f a = Coyoneda {
uncoyo :: forall b r. ((b -> a) -> f b -> r) -> r
}
coyoneda f tx = Coyoneda (\k -> k f tx)
I think Coyoneda
should work by simulating existentials with a higher-rank type, but I fail to construct values of this type. The coyoneda
auxiliary function doesn't type check, because with regard to the term k f tx
the higher-rank type variable b
would escape its scope.
However, I cannot come up with another way to implement coyoneda
. Is it possible at all?