Additional edits to #285#1
Conversation
Wanted to make this a PR to a PR branch for easier commenting on proposed changes. purescript-contrib#285
|
|
||
| ```haskell | ||
| findEntry firstName lastName book = head $ filter filterEntry book | ||
| findEntry firstName lastName book = head (filter filterEntry book) |
There was a problem hiding this comment.
Since there's a bunch of content to get through before the explanation of $, I figured it would be better to reveal the alternative version later on.
| infix 4 eq as == | ||
| ``` | ||
|
|
||
| and therefore `entry.firstName == firstName` in `filterEntry` could be replaced with the `eq entry.firstName firstName`. | ||
| and therefore `entry.firstName == firstName` in `filterEntry` could be replaced with the `eq entry.firstName firstName`. We'll cover a few more examples of defining infix operators later in this section. |
There was a problem hiding this comment.
I imagine some readers getting hung-up on not fully understanding that infix code.
| ``` | ||
|
|
||
| PureScript provides an equivalent [_property accessor_](https://github.com/purescript/documentation/blob/master/language/Syntax.md#property-accessors) shorthand, where an underscore is followed by a field name, so the inline function above is equivalent to: | ||
| PureScript also allows [_property accessor_](https://github.com/purescript/documentation/blob/master/language/Syntax.md#property-accessors) shorthand, where an underscore acts as the anonymous fuction argument, so the inline function above is equivalent to: |
There was a problem hiding this comment.
Inner thesaurus wants just one "equivalent" in this sentence.
|
|
||
| For example, the earlier `book3` example could be rewritten as: | ||
| ```haskell | ||
| book7 = insertEntry john $ insertEntry peggy $ insertEntry ned emptyBook |
There was a problem hiding this comment.
Relocated this example closer to the previous snippet so we can avoid the recap.
Also a fan of showing the most compelling example first, then the deeper explanation. So I did some other reordering. I think many beginning users can just make a mental note of what $ means in practice, and be productive with it without necessarily being able to write the code for apply if quizzed.
| add5 = add 5 | ||
| add5 = \x -> 5 + x | ||
| add5 = (5 + _) | ||
| add5 x = 5 `(+)` x -- Yo Dawg, I herd you like infix, so we put infix in your infix! |
There was a problem hiding this comment.
Too much?
Was hoping that this would work too:
add5 x = (`add`) 5 xThere was a problem hiding this comment.
My feeling is that book's overall tone is a bit drier, so I don't know how well the comment on the last line fits.
Personally, I like it, and earlier I had considered changing your "john" "peggy" "ned" example to "homer" "apu" "ned", but decided against it, for consistency.
Wanted to make this a PR to a PR branch for easier commenting on proposed changes.
purescript-contrib#285