--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
On Tuesday, November 26, 2013 11:58:36 PM UTC+1, Dobes Vandermeer wrote:
You might want to add it to your own fork of Elm and then show a working example application that uses it. Then people can weigh in on how it looks and feels.
Personally I'm not a fan of the % but I don't have anything better coming to mind. It does look handy, but whether it would get enough use to have its own syntax I'm not sure.
I wonder if this is something that could be implemented as a function instead of a syntax extension. Maybe a version of map like "fieldMap".If you could somehow use the same ".foo" value to set a field we'd be in business - basically a kind of "first-class field" feature. Maybe some built-in function that takes a field getter ".foo" and turns it into a setter?
--
Sean: Oh of course, it's just a higher order function. The lack of the constantly had me thinking it was an expression. Incidentally, the Haskell people call that const, and it's the function I will push the strongest to be added to Basics, when we get a chance. In the mean time just write: const a _ = aEvan: It's not applicable to statically typed languages, but D3 and probably many other JS libraries use the same function for getting and setting, based on the number of arguments. You could try .nameGets or some other lingual rather than symbol difference.
--
--
Some really good ideas here, I'll implement some more of them, I think.I've seen an other approach to this problem in the Vinyl package for extensible records in Haskell. They treat records as a generalization of Applicative (i.e., without pure). When we port the record syntax to Elm it would look like:type Person = { name : String , age : Int }bob = Person "Bob" 42{ name = toUpper } <<*>> bob === { name = "BOB" , age = 42 }I don't know whether (<<*>>) can be implemented as plain Elm, but it'll suffice. Then we need an infix version (liftR?) to use it for higher order stuff. (or are operator sections under the way?).Also cool is that you can do stuff like { age = (+) } <<*>> bob <<*>> bob because they're just applicatives. This does fall short when you need to access other fields.(My comment was deleted, don't know why. I've typed it again. Sorry if it pops up again later on.)
Jeff, I don't fully understand your concern. I think the idea is that ._.map is a syntactic unit where some field name goes in the blank, so it is distinct from normal field access and the ._.get pattern. Perhaps this is an argument for using something besides a dot there (although everything else seems to look weirder or be syntactically ambiguous)
@Vincent:I guess if done at parse time, the operation would always have to take a literal record on the left. I was thinking it would work even if the record on the left was an expression that resulted in a record, as long as the record had a bunch of functions in it.
--
--
I like Martin's {{ syntax, provided I understand correctly that the type of the entire block is a function from records to records (which can be mapped over a list).
And from Evan's parsing comments, it sounds like detecting {{ is efficient. I don't follow all the details with |> but it's worth exploring.
Evan, did you know you can make values of type {sameName: a, sameName: b} ? That's really weird. It happens when you use regular setter syntax {a | sameName = a.sameName}. I know it's the wrong use case and you should use <-, so, is this a feature or a bug?
- Moustache modifier maker: {{field}} = (\f a -> {a| field <- f a.field} -- not so sure about this one. It's %field, but I feel it doesn't jive with the other moustaches. This is better:
- Up next: Moustache modifier without explicit bindings: {{ field1 |> f, field2 |> g |> h}} = (\a -> {a| field1 <- f a.field1, field2 <- h (g a.field2)})
That's great! I'm just afraid of having ambiguous operators, though. I mean, I'm having trouble with the dot syntax sometimes already... It sneaks up on you when you don't expect it. Maybe that's just because the errors still need some work. :)
Also added a moustache lambda {{\ a b c | bla }} = ((\x a b c -> { x | bla }) {})
I realized that {{x a b | sum = a.field1 + b.field2, prod = a.field1 * b.field2}} {} <~ aSig ~ bSig was a pattern I actually would use more than one the one that alters an existing record. I added it and I think it looks nice and straightforward.