You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
871 B
871 B
Wait, how does that even typecheck
(.) :: (b -> c) -> (a -> b) -> a -> c
-- fmap fmap
fmap :: Functor f => (m -> n) -> f m -> f n
fmap :: Functor g => (x -> y) -> g x -> g y
Let's typecheck fmap . fmap.
.
- First, it's important to note that
fmap
is a function that takes a functionm -> n
and returns a functionf m -> f n
. - Using that information we see that
a
is actuallym -> n
. - We also see that
b
is actuallyf m -> f n
andx -> y
, sox
has to bef m
andy
has to bef n
. - We can then also conclude that
g x
isg (f m)
andg y
isg (f n)
Armed with this knowledge, we can apply fmap to (.) a first time
(fmap.) :: (Functor g) => (a -> (f m -> f n)) -> a -> g (f m) -> g (f n)
And now we apply it a second time:
(fmap . fmap) :: (Functor g, Functor f) => (m -> n) -> g (f m) -> g (f n)