简体   繁体   English

什么是Haskell的箭头关联性?

[英]What is haskell's arrow associativity?

I am currently learning haskell and struggling with the following test : Suppose we have such a type : 我目前正在学习haskell,正在努力进行以下测试:假设我们有这样的类型:

type Endo a = a -> a

I have to choose all types that are equivalent to Endo (Endo Int) 我必须选择与Endo (Endo Int)等效的所有类型

(Int -> Int) -> (Int -> Int)
(Int -> Int) -> Int -> Int
Int
Int -> Int
Int -> Int -> Int -> Int
(Int -> Int) -> Int
Int -> Int -> (Int -> Int)
Int -> (Int -> Int)
Int -> Int -> Int

Since the type of Endo Int is Int -> Int I understand that type I need has 4 Ints such as (Int -> Int) -> (Int -> Int) . 因为Endo Int的类型是Int -> Int所以我知道我需要的类型有4个(Int -> Int) -> (Int -> Int)例如(Int -> Int) -> (Int -> Int) Int- (Int -> Int) -> (Int -> Int) But I do not really understand which parenthesis are unnecessary 但是我真的不明白哪个括号是不必要的

It is right associative in Haskell, so following are equivalent: 在Haskell中它是正确的关联,因此以下等效:

a -> b -> c
a -> (b -> c)

Function that takes arguments a and b is equivalent to function that given argument a returns function that takes argument b. 接受参数a和b的函数等效于给定参数a的函数返回接受参数b的函数。

It is not left associative. 它不具有关联性。

So the answer is first two. 所以答案是前两个。

Your intuition is correct: (Int -> Int) -> (Int -> Int) is indeed Endo (Endo Int) . 您的直觉是正确的: (Int -> Int) -> (Int -> Int)确实是Endo (Endo Int)

Just recall that -> associates on the right, ie 只要回想一下->右边的同事,即

a -> b -> c     means    a -> (b -> c)

Given that, you should now be able to solve the exercise. 鉴于此,您现在应该可以解决该练习了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM