| ▲ | Generalised plusequals(leontrolski.github.io) | |||||||
| 12 points by leontrolski 7 hours ago | 6 comments | ||||||||
| ▲ | flebron 3 hours ago | parent | next [-] | |||||||
The website asks what they do in Haskell. The answer is property modification and reading, as well as very powerful traversal constructs, use lenses (https://hackage.haskell.org/package/lens , tutorial at https://hackage.haskell.org/package/lens-tutorial-1.0.5/docs...). | ||||||||
| ▲ | RodgerTheGreat 2 hours ago | parent | prev | next [-] | |||||||
In Lil[0], this is how ordinary assignment syntax works. Implicitly defining a dictionary stored in a variable named "cat" with a field "age":
Defining "l" as in the example in the article. We need the "list" operator to enlist nested values so that the "," operator doesn't concatenate them into a flat list:
Updating the "age" field in the nested dictionary. Lil's basic datatypes are immutable, so "l" is rebound to a new list containing a new dictionary, leaving any previous references undisturbed:
There's no special "infix" promotion syntax, so that last example would be:
[0] http://beyondloom.com/tools/trylil.html | ||||||||
| ▲ | hatthew 3 hours ago | parent | prev | next [-] | |||||||
It seems like this is proposing syntactic sugar to make mutating and non-mutating operations be on equal footing. > The more interesting example is reassigning the deeply nested l to make the cat inside older, without mutating the original cat Isn't that mutating l, though? If you're concerned about mutating cat, shouldn't you be concerned about mutating l? | ||||||||
| ||||||||
| ▲ | rokob 3 hours ago | parent | prev | next [-] | |||||||
Yeah this looks like lenses at first glance | ||||||||
| ▲ | beaumayns 3 hours ago | parent | prev [-] | |||||||
q has the concept of amend, which is similar: https://code.kx.com/q4m3/6_Functions/#683-general-form-of-fu... It's quite handy, though the syntax for it is rather clunky compared to the rest of the language in my opinion. | ||||||||