When I try to partially apply che to r, it doesn't seem to fit:
r
has type
(b -> Identity b) -> (a -> Identity a)
which means its first argument needs to have type (b -> Identity b)
.
che
has type
(b -> Identity b)
Just as r
required, therefore r che
will work and have type (a -> Identity a)
.
After applied to the third argument, suppose it has been named arg
, of modify
, this arg
has type a
, r (Identity . m) arg
will have type Identity a
, after applied runIdentity
on it, the result will have type a
.
type RefF a b = forall f. Functor f => (b -> f b) -> (a -> f a)
modify :: RefF a b -> (b -> b) -> a -> a
modify r m = runIdentity . r (Identity . m)
You could infer the type of modify r m
like this:
r
has typeRefF a b
, which is(b -> f b) -> (a -> f a)
m
has typeb->b
Identity
has typeforall a. a -> Identity a
, thereforeIdentity . m
has typeb -> Identity b
r (Identity . m)
has typea -> Identity a
, becausef
must beIdentity
runIdentity
has typeforall a. Identity a -> a
, thereforerunIdentity . r (Identity . m)
has typea -> a