Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Does a type Int in the rage of 1 <= x <= 255 exist?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading