Which is the type of (flip .)?

人盡茶涼 提交于 2019-12-31 07:37:03

问题


I'm trying to understand why the type of:

(flip .) is: (a -> a1 -> b -> c) -> a -> b -> a1 -> c

First of all, the type of:

flip: is (a -> b -> c) -> b -> a -> c (.): is (b -> c) -> (a -> b) -> a -> c

I will rename the variables to be more clear in my explanation, so the types:

flip: is (ax -> bx -> cx) -> bx -> ax -> cx (.): is (by -> cy) -> (ay -> by) -> ay -> cy

Then I try substituing like this:

ax = (by -> cy) bx = (ay -> by) cx = ay -> cy

So the resulting type is: (ay -> by) (by -> cy) -> ay -> cy, which is different with the correct result.

Any help?

Thanks, Sebastián.


回答1:


(flip .) is (.) flip, so:

  • (.) :: (bx -> cx) -> (ax -> bx) -> ax -> cx
  • flip :: (ay -> by -> cy) -> by -> ay -> cy
  • In (.) flip,
    • bx is ay -> by -> cy
    • cx is by -> ay -> cy
    • so it’s all (ax -> (ay -> by -> cy)) -> ax -> (by -> ay -> cy),
      which is just (ax -> ay -> by -> cy) -> ax -> by -> ay -> cy,
      which matches up with (flip .) :: (a -> a1 -> b -> c) -> a -> b -> a1 -> c.


来源:https://stackoverflow.com/questions/23187423/which-is-the-type-of-flip

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