Contents

1 Problem

Question:

The compiler doesn't accept

a <= x <= b

. Why?

Answer:
The expression cannot be parsed,

because the infix symbol

<=

has no (left or right) associativity.

In languages like C
the expression is parsed as (a <= x) <= b which is even worse.
The first part is evaluated to a boolean value,
which is then compared with b.
(For C "boolean" and "integer" are the same type.)

2 Solutions

2.1 simple

You must be aware, that the mathematical notation is shorthand for . Consequently a possible Haskell solution is

a <= x && x <= b

.

Another fine mathematical notation is . You can roll your own function