Open
Description
I'll explain via an example:
i1 : Truthy = new Type of List;
i2 : Truthy == Boolean := (T, B) -> T#0 === B;
i3 : T = new Truthy from {true}
o3 = {true}
o3 : Truthy
i4 : F = new Truthy from {false}
o4 = {false}
o4 : Truthy
Given such a type, it would be desirable to use it in if .. then .. else ..
clauses, but this fails:
i5 : if T then print "true"
stdio:5:4:(3): error: expected true or false
Even though this works fine:
i6 : T == true
o6 = true
i8 : T == false
o8 = false
We can define binary operations fine:
i9 : not Truthy := T -> new Truthy from {not T#0};
i10 : not T
o10 = {false}
o10 : Truthy
i17 : Truthy and Truthy := (T1, T2) -> new Truthy from {T1#0 and T2#0};
i18 : T and F
o18 = {false}
o18 : Truthy
i19 : T and T
o19 = {true}
o19 : Truthy
One solution is having if
and while
clauses evaluate truthiness using a method that can be installed from the top level.
One application of this is having lazily evaluated predicates and binary operations that take advantage of this, or even basic symbolic logic.
Metadata
Metadata
Assignees
Labels
No labels