>>> inRange ('a','z') 'e' True >>> inRange ('x','z') 'a' False
>>> :set +s >>> elem (10000000 :: Integer) [1..10000000] True (0.26 secs, 720,556,888 bytes) >>> inRange (1 +=+ 10000000) (10000000 :: Integer) True (0.00 secs, 557,656 bytes) >>>As you can see, this function is significantly more performant, in both speed and memory, than using the elem function.
isInRange (lo, hi) x == isInRange (hi, lo) xRanges include their endpoints:
isInRange (lo, hi) lo == TrueWhen endpoints coincide, there is nothing else:
isInRange (x, x) y == x == yEndpoints are endpoints:
isInRange (lo, hi) x ==> isInRange (lo, x) hi == x == hiRanges are transitive relations:
isInRange (lo, hi) lo' && isInRange (lo, hi) hi' && isInRange (lo', hi') x ==> isInRange (lo, hi) xThere is a default implementation of isInRange via Generic. Other helper function that can be used for implementing this function are isInRangeOrd and isInRangeEnum. Note that the isRange method from Data.Ix is not a suitable default implementation of isInRange. Unlike isInRange, isRange is not required to be symmetric, and many isRange implementations are not symmetric in practice.
isInRange (lo, hi) x == isInRange (hi, lo) xRanges include their endpoints:
isInRange (lo, hi) lo == TrueWhen endpoints coincide, there is nothing else:
isInRange (x, x) y == x == yEndpoints are endpoints:
isInRange (lo, hi) x ==> isInRange (lo, x) hi == x == hiRanges are transitive relations:
isInRange (lo, hi) lo' && isInRange (lo, hi) hi' && isInRange (lo', hi') x ==> isInRange (lo, hi) xThere is a default implementation of isInRange via Generic. Other helper function that can be used for implementing this function are isInRangeOrd and isInRangeEnum. Note that the isRange method from Data.Ix is not a suitable default implementation of isInRange. Unlike isInRange, isRange is not required to be symmetric, and many isRange implementations are not symmetric in practice.