Uh oh!
There was an error while loading. Please reload this page.
Workaround for Math variadic functions - #82
Conversation
Uh oh!
There was an error while loading. Please reload this page.
| @variadic @val external _minMany: array<float> => float = "Math.min" | ||
| let minMany = arr => | ||
| switch arr { | ||
| | [] => 0.0 | ||
| | arr => _minMany(arr) | ||
| } |
There was a problem hiding this comment.
I'm not sure the float versions ought to be overridden. Math.min([]) does indeed return 0, and Math.min() returns Infinity, but Math.minMany([1, 2, 3]) maps to Math.min(1, 2, 3), not Math.min([1, 2, 3]), and so it seems more consistent to have Math.minMany([]) map to Math.min(), not Math.min([]).
These are also edge cases that are very unlikely to occur in practice, since variadic calls require syntactic arrays there's little chance of it happening by accident. I'd suggest the aim of this is restricted to just making the types sound.
If you remove |
glennsl
commented
Jul 26, 2023
Ah, sorry, I didn't mean to include that. I checked after writing it, but apparently forgot to remove the comment. Please see the other comments instead :) |
aspeddro
commented
Jul 27, 2023
I was wondering and not sure if we should return |
This ensures that the return for an empty array does not return
-InfinityTODO:
See #53