3 ms·
Not necessarily. ML-family languages which compile to JS, like ReasonML, can encode sum types in a variety of ways. (Sum types are essentially type reification
by yawaramin 8y ago
Not necessarily. ML-family languages which compile to JS, like ReasonML, can encode sum types in a variety of ways. (Sum types are essentially type reification because the alternative cases are 'tagged' with names).
Tag encoding can be quite clever. For example, ReasonML's BuckleScript compiler can encode a sum type like this:
type chequeNum = string;
type paymentMethod =
| Cash
| Cheque(chequeNum);
... as the number 0 for the `Cash` case and as a single-element array for the cheque case.
See e.g. https://reasonml.github.io/en/try.html?rrjsx=true&reason=C4TwDgpgBAxgFhAjgVwgOWQWygXigZ2ACcBLAOwHMBuAKFEijAEMRMIzgBZCYOAewAmuGgB8oAYSb44oiQhQQAFPCSoMmAJS0aAGx5RgfAMrFyFXFABmyMjShQxk6bgB8UAEQAFJiSHlYUnDudg5yqkoqCuoarlAA3gBWIt6+UADuJLyw8qhQZHwAdFAAJJFqWCIJAL7aesAB0t6s7PV4TnC0ddnhTWwcFuI5Su4AjABMAMwALO5aNEA https://reasonml.github.io/en/try.html?rrjsx=true&reason=C4T...