ndmitchell / record-dot-preprocessor

A preprocessor for a Haskell record syntax using dot
Other
129 stars 19 forks source link

Support field sections #2

Closed ndmitchell closed 5 years ago

ndmitchell commented 6 years ago

(.b) should be (\x -> x.b) where it is a selector.

mitchellwrosen commented 6 years ago

In Elm, .b without the ( ) is sugar for (\x -> x.b). Is that possible here? (Cool project btw!)

ndmitchell commented 6 years ago

Possible, yes, although at the moment I've used the rule that unless you have a.b with no spaces where a is not a leading capital we don't touch it at all. As soon as we have .b alone then you would have to space-separate that piece to have no impact. That said, following someone else makes a lot of sense, as per http://elm-lang.org/docs/records.

I'm on the fence, how strongly do you feel this would be useful? (I'm not sure I can judge in advance)

mitchellwrosen commented 6 years ago

I'm not too sure, either :)

A couple more points: in Elm, the dotless record accessor is actually not generated, so where you might write .foo, in Haskell this would just be spelled foo.

However, it is awfully convenient to be able to have the same syntax for expressing both:

foo.bar.baz :: Baz

and:

.bar.baz :: Foo -> Baz

(I don't believe .bar.baz currently works with this library?)

ndmitchell commented 6 years ago

Decision:

Omitting brackets is appealing, and might be what I do in the end, but it's a greater chance of breaking existing programs, and is compatible - if I decide to make brackets optional, it won't break anything, if I decide to make them mandatory it will break existing programs using the preprocessor.

ndmitchell commented 6 years ago

The more I look, the more weirder map (.bar) xs looks - it just doesn't feel like a section in any way. Decision is made to allow .bar on its own as well.

I wonder if {foo=x} should also be treated as an operator in its own right that can be mapped? Then x{foo=y} is just {foo=y} x. It's somewhat appealing...

ndmitchell commented 5 years ago

I have implemented the bracket based selectors. I haven't turned updating into a section.