2 ms·
> I hope you have a wide enough monitor to read this. Not only does this seem ad-hoc and unpretty, but it also doesn’t allow you to put more than 10 elements in
by hombre_fatal 7y ago
> I hope you have a wide enough monitor to read this. Not only does this seem ad-hoc and unpretty, but it also doesn’t allow you to put more than 10 elements in a container! All because someone in charge of API design was afraid of lists and had more power than someone in charge of Swift language.
This explanation doesn't sound right to me coming from other statically typed languages where you're stuck either using codegen or arity hardcoding. Currying also gives a nice solution where your DSL simply builds up a function A->B->C->...
Hard-coding each level of arity is done so that your generics keep upstream type knowledge.
Here's an example in Elm, though it has to keep renaming the function due to lack of arity overloading.
https://github.com/elm/json/blob/063aaf05e0dc5a642bacbdaae59c33dcfd116898/src/Json/Decode.elm#L420-L450 https://github.com/elm/json/blob/063aaf05e0dc5a642bacbdaae59...
You can't use variadic functions because then you function doesn't even know how many arguments it has at compile time much less any specifics about them.
That Swift doesn't require commas between closure returns seems like a different point.
You'd still need this solution even if you were just spitting out generic TupleView<(View, View)>, TupleView<(View, View, View)>, etc.
Unless, of course, you don't actually care about type info the same way you don't care how many arguments are passed to a variadic max(1, 4, 66) function.
Another comment says there will be a variadic viewbuilder function once Swift gets variadic generic functions which will still throw away type info, so this seems to be the case. Still, I don't see the relationship with commas.