3 ms·
btw this could (sorta) be considered a special case of the fact that a tuple/struct (product type) can be represented as a function: let pair = (a, b) => (
by uryga 6y ago
btw this could (sorta) be considered a special case of the fact that a tuple/struct (product type) can be represented as a function:
let pair = (a, b) => (
(ix) => (
ix === 0 ? a :
ix === 1 ? b :
undefined
)
);
let p = pair(3, "foo");
p(0) // 3
p(1) // "foo"
i've seen sth like this used as the definition of tuples in a math context. (there are also other ways to do it too, like church/scott encoding)
however the object has the extra wrinkle of self-referentiality, because the `self` function is defined recursively