Reputation: 1189
Could I put a case to be within a certain range or another number?
say ...
case x of
+/- 3 -> yes
...
Would that be something Haskell should understand?
Update: In short, would i be able to match to an interval rather than a number?
Upvotes: 0
Views: 255
Reputation: 52290
no but you can use abs
and turn it around:
for a interval around p
with radius r
you can use
if abs (x-p) <= r then yes else ...
example:
Prelude> let inInterval p r x = abs (x-p) <= r
Prelude> inInterval 5 3 1
False
Prelude> inInterval 5 3 2
True
Prelude> inInterval 5 3 8
True
Prelude> inInterval 5 3 9
False
Upvotes: 5