<@UCGAK10LS> See this example - In the implementat...
# thinking-together
y
@Nick Smith See this example - In the implementation of
sum
,
fold
wants a “binary operator” function that takes two parameters - an “accumulator” and an “item”. In Haskell, which is based on positional arguments, I’d simply pass the operator “+”. But in Lamdu I can’t because the parameters of “+” are not called “accumulator” and “item”. So instead I use a lambda which uses “+”. However it gets sugared as a “lightweight lambda”, with underlines under the lambda symbol and under its parameters where used. This isn’t too heavyweight and it also gives us helpful places to display the intermediate values of everything (when display of evaluation results is enabled)
👍 1
n
Oh cool. Does the sugar happen automatically? Does the programmer still type the full lambda before it gets simplified? Seems like an interesting feature. I'd imagine that for larger functions the lack of an explicit parameter list might harm readability, but at that point the sugar is probably unnecessary anyway.
y
The sugar happens automatically when the code matches a certain pattern (all parameters are in use is one condition). The conditions are such that it doesn’t tend to happen for larger functions
Btw here is the same example with syntax sugars disabled. All functions (including the “..” or “+” operators) get a single argument which is a record, constructed by adding fields one by one to the empty record. Instead of “sum” having a parameter in the LHS it equals to a lambda, etc
😨 1
n
Why do you represent records this way? Seems like it introduces an ordering amongst fields.
Also seems to preclude the possibility of having a "merge" operator for two records?
y
@Nick Smith Perhaps “merge” is the way to go, and I’m interested in compelling examples for it. However with “merge” you still have the same ordering freedom where you can either construct a full record or merge many small ones where you have freedom in their ordering.
n
Unless "merge" is an operator from a set of sets to a set 😛
I have no familiarity with language implementation but I tend to (over)think about conceptual simplicity 🤷. Merge seems naturally to be an operation on a set of sets (or a labelled set I guess... I think there's a mathematical term for it).
y
Yeah it appears like a nice idea. Iirc there is some language that has it. But it’s probably more complicated to make type-inference work for it
d
The issue would seem to be that order and names don't matter to us as readers when it comes to addition. Addition is an abstraction layer high enough already.
(reduce + 0 [1 2 3])
Other implantations of fold could benefit from the names though
Again, it's contextual I think