Skip to content

Chapter 3: Infix function application example using record accessors does not seem to work #282

Description

@shaunplee

Chapter 3 includes the following as an example of how ($) can make things easier to read by reducing the number of parentheses:

For example, the following nested function application, which finds the street in the address of an employee's boss:

street (address (boss employee))

becomes (arguably) easier to read when expressed using $:

street $ address $ boss employee

However, these street, address, and boss accessor functions are not defined. I think this would be valid Haskell when using record syntax, but, based on my quick experiments in PSCi 0.13.8, it seems like PureScript doesn't automatically create these accessor functions.

I'm new to PureScript, so I could be missing something here.

Suggestion is to rewrite this a bit, maybe by introducing record accessor functions using _. per issue #281, and then rewriting the above as:

For example, the following nested function application, which finds the street in the address of an employee's boss:

_.street (_.address (_.boss employee))

becomes (arguably) easier to read when expressed using $:

_.street $ _.address $ _.boss employee

I can take a crack at this, unless I'm misunderstanding how PureScript works.

Activity

  1. changed the title [-]Infix function application example using record accessors[/-] [+]Chapter 3: Infix function application example using record accessors does not seem to work[/+] on Jan 2, 2021
  2. milesfrain commented on Jan 2, 2021

    @milesfrain
    Member

    Yeah, this is a very hand-wavy snippet. I think we could completely eliminate that section and in the preceding section just link to the docs for $. We can improve those docs if they're not beginner-friendly enough.

    For context, a lot of the book's address records were previously wrapped in Newtype to work around some of the limitations of records, and it was common to have helper functions to unwrap the fields (since I don't think wrap/unwrap were available for Newtype yet either). Anyway, things are a lot easier now. In the real world, assuming we had a boss :: Entry -> Entry function, that snippet would just be written as:

    (boss employee).address.street
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions