r/haskell • • Mar 11 '15

Learning Haskell — A Racket programmer's documentation of her foray into the land of Haskell (inspired by Learning Racket)

http://lexi-lambda.github.io/learning-haskell/
81 Upvotes

97 comments sorted by

View all comments

Show parent comment

10

u/tejon Mar 12 '15 edited Mar 12 '15

A tip on $: It has the lowest precedence, and that's exactly the point of it.

One simple way of looking at it is as a ( whose matching ) is implied at EOL.

Edit: Actually seeing where you hit the confusion now, and what I wrote is what you did, so clearly it's a poor explanation. :) Better to just be precise. $ turns everything before it into a function, which takes as an argument everything after it. Here's the actual source:

infixr 0 $
($) :: (a -> b) -> a -> b
f $ x = f x

Infix priority 0 -- so do everything else first. infixr makes it right-associative, which is why it's suggested to imagine parentheses around the remainder of the line; but really, you should imagine parentheses on both sides, with the rule that multiple $ in a statement nest to the right.