[Haskell-beginners] Clarifying $ vs parentheses

Bob Ippolito bob at redivi.com
Thu Aug 20 19:36:24 UTC 2020


Because the second one is:

  take (succ 10 (cycle “hello world”))

On Thu, Aug 20, 2020 at 12:03 Josh Friedlander <joshuatfriedlander at gmail.com>
wrote:

> 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"’
>
>
> _______________________________________________
>
> Beginners mailing list
>
> Beginners at haskell.org
>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200820/0697da5d/attachment.html>


More information about the Beginners mailing list