Skip to content

Conversation

milesfrain
Copy link

Wanted to make this a PR to a PR branch for easier commenting on proposed changes.
purescript-contrib#285

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)
Copy link
Author

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.

Comment on lines 591 to +594
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.
Copy link
Author

@milesfrain milesfrain Jan 4, 2021

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:
Copy link
Author

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
Copy link
Author

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.

Copy link
Owner

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!
Copy link
Author

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

Copy link
Owner

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.

@shaunplee shaunplee merged commit abc0718 into shaunplee:record-field-accessors Jan 4, 2021
@milesfrain milesfrain deleted the 285-edits branch January 5, 2021 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants