Closed ndmitchell closed 5 years ago
In Elm, .b
without the ( )
is sugar for (\x -> x.b)
. Is that possible here? (Cool project btw!)
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)
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?)
Decision:
(.bar) ==> (\x -> x.bar)
(.bar.baz) ==> (\x -> x.bar.baz)
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.
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...
I have implemented the bracket based selectors. I haven't turned updating into a section.
(.b)
should be(\x -> x.b)
where it is a selector.