Deriving the type of (foldr (.))

◇◆丶佛笑我妖孽 提交于 2019-12-12 01:33:17

问题


I'm trying to manually derive the type of (foldr (.))

foldr :: (a1 -> b1 -> b1) -> b1 -> [a1] -> b1
(.) ::(b2 -> c2) -> (a2 -> b2) -> a2 -> c2

Then:

a1 ~ (b2 -> c2)
b1 ~ (a2 -> b2)
b1 ~ a2

So I get that (foldr (.)) :: (a2 -> b2) -> [(b2 -> c2)] -> (a2 -> b2)

But GHCi returns: :t (foldr (.)) :: (a -> b) -> [b -> b] -> a -> b

Why b2 and c2 are the same?

Thanks,
Sebastián.


回答1:


If you look at the type of (.) as

(b2 -> c2) -> (a2 -> b2) -> (a2 -> c2)

then

b1 ~ (a2 -> b2)
b1 ~ (a2 -> c2)

so (b2 ~ c2)

then you can see the type of (foldr (.)) is

(a2 -> b2) -> [(b2 -> b2)] -> (a2 -> b2)

which is the type GHC derives.



来源:https://stackoverflow.com/questions/23417844/deriving-the-type-of-foldr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!