[Haskell-beginners] Data constraint?

Galaxy Being borgauf at gmail.com
Thu Jun 3 22:40:41 UTC 2021


If I have a type

type WaterChem = CaHardness NaturalChem | Alkalinity NaturalChem

and I want to have the values of CaHardness and Alkalinity constrained to
positive Int and between certain high and low values, I could do a newtype to
creater a NaturalChem number, thus never less than 0, but what is the best
practice to insure these values are between a certain range? Types in
Haskell can't go that far, can they? Reading this
<https://www.haskell.org/tutorial/moretypes.html> tells me I can have some
of what I want. How are type values that need to be constrained handled
best practices? Again, the type world of Haskell seems to do some of the
lifting, but I'd like some advice if I want to have both of my constraints.




-- 
⨽
Lawrence Bottorff
Grand Marais, MN, USA
borgauf at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20210603/c142b140/attachment.html>


More information about the Beginners mailing list