Let Boolean values be usable as operators
josephcsible opened this issue · 5 comments
It should be possible to use a Boolean value directly as an operator, behaving the same way it would if it were the first operand to the "choice" operator (i.e. true = λxy.x and false = λxy.y).
Hmm, this is an interesting proposal, but I'm not sure if the cost of implementing this outweighs the benefits. Is this actually a thing that exists in FP languages? I haven't seen it before.
Indeed. It's originally a lambda calculus thing (http://safalra.com/lambda-calculus/boolean-logic/), but it's made its way into a few more practical functional languages.
Ok, TIL :-)
I can have a look in the future at this, but I'm afraid it won't be an easy thing to implement in a clean way, because booleans were never meant to be used as an operator type. But it should be possible.
Yeah, in pure lambda calculus, everything is a function, even numbers, 0(f, x) = x, 1(f, x) = f(x), 2(f, x) = f(f(x)), and so on. But there's no practical use for that in this mod.
As for making it clean, why not just replace existing booleans with these operators, possibly making Boolean a new subtype of Operator for type safety?
I think there would actually be practical uses for that first case, for nested lists for example.
Well yes, that would be the idea, but that isn't very simple to do, as value types currently can not inherit from other types, so some major code changes would be required for that.