[Haskell-beginners] Clarifying $ vs parentheses

Josh Friedlander joshuatfriedlander at gmail.com
Thu Aug 20 19:02:21 UTC 2020


I understand that in general $ is a) right-associative and b)
lowest-priority. But if so shouldn't these two be roughly the same?

λ take (succ 10) $ cycle "hello world"
"hello world"

But not this?
λ take $ succ 10 $ cycle "hello world"

<interactive>:20:8: error:
    • No instance for (Enum ([Char] -> Int))
        arising from a use of ‘succ’
        (maybe you haven't applied a function to enough arguments?)
    • In the expression: succ 10
      In the second argument of ‘($)’, namely
        ‘succ 10 $ cycle "hello world"’
      In the expression: take $ succ 10 $ cycle "hello world"

<interactive>:20:13: error:
    • No instance for (Num ([Char] -> Int))
        arising from the literal ‘10’
        (maybe you haven't applied a function to enough arguments?)
    • In the first argument of ‘succ’, namely ‘10’
      In the expression: succ 10
      In the second argument of ‘($)’, namely
        ‘succ 10 $ cycle "hello world"’
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200820/60226e97/attachment.html>


More information about the Beginners mailing list