问题
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
isay -> by -> cy
cx
isby -> 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