Why do we need to use brackets while composing functions in haskell?
-
04-06-2021 - |
Frage
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.
Lösung
You're mistaken. When I write
import Data.Char
identity = chr.ord
in test.hs
and load it in ghci
, nothing goes wrong.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow