4 ms·
Why are you comparing functions/closures with values? You can do the same in python: [list() for _ in range(4)]
by arijun 3y ago
Why are you comparing functions/closures with values? You can do the same in python:
[list() for _ in range(4)]
- bmitc 3y ago> Why are you comparing functions/closures with values? I'm not. The fun _ -> [] is needed because the argument is the element's index. That's just what List.init happens to expect, a function that takes an index and initializes the element, but the index is not needed here.
- arijun 3y agoAre you saying f# special-cases something that looks like a closure, but isn’t in this one context? Because that, to me, seems like a much more grievous issue than the one at hand.
- bmitc 3y agoNo. F# lambdas are closures. I was just saying that I'm not using the concept of closures to explain here. It's just a side effect of using the List.init function as a demonstration.
- arijun 3y ago(I can’t respond to your other comment) Ah I see, you’re saying that the construction of a list in F# mandates a lambda, thereby reducing one possible point of confusion. I could agree with that. But then it comes at a cost of comfort: [0]*4 has less boilerplate than the F# version. So it comes down to trade-offs again.