简体   繁体   English

为什么在Haskell中编写函数时需要使用方括号?

[英]Why do we need to use brackets while composing functions in haskell?

Let say I have need to define the following function: 假设我需要定义以下函数:

Identity = chr.ord 身份=密码

But the above line won't work, the correct way would be: 但是上面的行不起作用,正确的方法是:

Identity = (chr.ord) 身份=(chr.ord)

Haskell usually is quite a minimalist language, so using that extra brackets does not seem natural(to me). Haskell通常是一种极简主义的语言,因此对我来说,使用多余的括号似乎并不自然。

Is anyone aware of the need for introducing the brackets. 是否有人知道需要引入方括号。 I can't remember where else we use the dot operator in haskell (other then for decimals). 我不记得我们在haskell的其他地方使用点运算符了(除了小数点以外)。

Editing after comments from Nate/Daniel Nate / Daniel发表评论后进行编辑

Both you are correct. 你们两个都是对的。 My actual method was: 我的实际方法是:

nextLetter a 
         | a /= 'z' = chr.ord a
         | a == 'z' = 'a'

Now I understand, in this case it will evaluate ord a and then try to evaluate chr.97, hence the error! 现在我明白了,在这种情况下,它将评估ord a,然后尝试评估chr.97,因此出现错误!

Thanks. 谢谢。

You're mistaken. 你误会了 When I write 当我写

import Data.Char
identity = chr.ord

in test.hs and load it in ghci , nothing goes wrong. test.hs并将其加载到ghci ,没有任何问题。

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

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