-
Notifications
You must be signed in to change notification settings - Fork 0
Additional edits to #285 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
findEntry firstName lastName book = head $ filter filterEntry book | ||
findEntry firstName lastName book = head (filter filterEntry book) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is much tidier.
|
||
```haskell | ||
add5 x = 5 + x | ||
add5 x = add 5 x | ||
add5 x = (+) 5 x | ||
add5 x = 5 `add` x | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too much?
Was hoping that this would work too:
add5 x = (`add`) 5 x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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