newtype NT m a = MkNT {unNT :: forall b. a -> m b}
foobar1 :: (b -> a) -> NT m a -> NT m b
foobar1 f nt = MkNT $ \ a -> unNT nt (f a)
foobar2 :: (b -> a) -> NT m a -> NT m b
foobar2 f (MkNT nt) = MkNT $ \ a -> nt (f a)
Although they both should work, foobar1 doesn't. The use of unNT gives rise to a wanted m @ b constraint.
one could type foobar1 :: Total m => (b -> a) -> NT m a -> NT m b. The total constraint is needed here as m as it can be applied to any b
Although they both should work,
foobar1
doesn't. The use ofunNT
gives rise to a wantedm @ b
constraint. one could typefoobar1 :: Total m => (b -> a) -> NT m a -> NT m b
. The total constraint is needed here asm
as it can be applied to anyb