Allow types to be used as sets
Closed this issue · 1 comments
The idea would be that any type T
could be used in an expression, and it would have type Set T
. This would allow writing things like
Disco> 3 elem N
true
Disco> twinPrimes = { p | p <- N, isPrime p, isPrime (p+2) }
Disco> 3 elem twinPrimes
true
Disco> 7 elem twinPrimes
false
Most significantly, this means we would now support (potentially) infinite sets. Because of this, sets could no longer be represented at runtime by literal sets of values; they would instead be represented by a deeply embedded DSL containing things like binary set operations (union, intersection, etc.), complement, map, and bind. Set expressions might fail at runtime if an operation requiring a finite set is performed on a set which is not known to be finite.
This would require a careful design (which I will continue to write up) but I think it's important given the discussion at https://byorgey.wordpress.com/2021/06/24/types-versus-sets-in-math-and-programming-languages/ .
Note we could also get rid of the count
and enumerate
operators, since they could now be accomplished using size
and list
, respectively.
I think this is a dead end, especially now that Disco is strict: something of type Set T
can only be a finite set. See also Derek Elkins' comments here: https://byorgey.wordpress.com/2021/06/24/types-versus-sets-in-math-and-programming-languages/#comment-39823