((f a)b)与Haskell中的(f a b)相同吗?

时间:2018-08-08 22:32:30

标签: haskell currying

map2_Maybe :: (a -> b -> c) -> Maybe a -> Maybe b -> Maybe c
map2_Maybe f Nothing _ = Nothing
map2_Maybe f (Just a) Nothing = Nothing
map2_Maybe f (Just a) (Just b) = Just ((f a) b)
-- Or: map2_Maybe f (Just a) mb = fmap (f a) mb

map2_Either :: (a -> b -> c) -> Either e a -> Either e b -> Either e c
map2_Either f (Left e) _ = Left e
map2_Either f (Right a) (Left e) = Left e
map2_Either f (Right a) (Right b) = Right (f a b)
-- Or: map2_Either f (Right a) eb = fmap (f a) eb

在这两个示例中,((f a) b)是否与(f a b)相同,因为Haskell中的每个函数只能接受一个参数?

2 个答案:

答案 0 :(得分:4)

是的,它们是完全一样的。

答案 1 :(得分:0)

Haskell将(f a b)换位为((f a)b)。叫做咖喱。默认情况下,它将对所有功能执行此操作,但可以将其覆盖。

 add = (+)
(add 1 2) -- becomes --  ((add 1) 2) -- upon execution.

两个都返回3。函数的结果就是它的值。

自然功能。

add1 = add 1
add1 2 -- also returns 3