On Wednesday, July 31, 2013, RedDevil wrote:
Hi, I am looking into the switch statement and would like to know if a case clause can have a range of values without having to specity all.
e.g is there a way to do something like case(129 to 191)?
The switch statement desugars into calls to the case? function, which is implemented in the library to compare the switch value against every case value using the == operator. You could overload case? to accept a range type, as in:
record Range[T](lo:T, hi:T);
[T] overload case?(x:T, range:Range[T]) : Bool = lo < x && x < hi;
-Joe