简体   繁体   中英

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)

Haskell usually is quite a minimalist language, so using that extra brackets does not seem natural(to me).

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).

Editing after comments from 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!

Thanks.

You're mistaken. When I write

import Data.Char
identity = chr.ord

in test.hs and load it in ghci , nothing goes wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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