Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Data constraint? (Galaxy Being)


----------------------------------------------------------------------

Message: 1
Date: Thu, 3 Jun 2021 17:40:41 -0500
From: Galaxy Being <borg...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Data constraint?
Message-ID:
        <CAFAhFSV5PoH+4LvTve=jzgkcupe8j7pb6zazwhuzs3o60yg...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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
borg...@gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20210603/c142b140/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 155, Issue 1
*****************************************

Reply via email to