I am learning haskell and I was playing a bit with function composition in the repl.
I am a bit puzzled with the result returned. Could someone explain to me why it returns -13 and not 13?
ghci> f1 = (((-) 1) . (+ 10) . ( + 5))
ghci> f1 (-1)
-13
in my head I do the following: -1 - 1 = -2 => -2 + 10 = 8 => 8 + 5 = 13
Since GHC 9.0, there is the really nice LexicalNegation extension, which makes everything in this area more intuitive, in particular, (- 1) is then parsed as an operator section, so this behaves as you would expect:
Λ :set -XLexicalNegation
Λ f1 = (- 1) . (+ 10) . ( + 5)
Λ f1 -1
13