I would like to create the following declaration:
data Color = B | W deriving Read
type Cell = (Color, Int) where 1 <= Int <= 255
Is there any solution to this problem ? The type, as it is, accepts any Int but those outside that range shouldn’t compile.
>Solution :
Not quite, but if you import Data.Word, there is the type Word8.
This is an "8-bit unsigned integer type", so its values range from 0-255, rather than 1-255 as you wished.
If that is not suitable for you, then the techniques in the answers to the question Noughtmare referred to in their comment are additional things to consider.