clamp function in base

Carter Schonwald carter.schonwald at gmail.com
Sat Aug 15 00:45:27 UTC 2020


hey sandy!
i absolutely support this,

theres one gotcha to this definition, handling nans!  I also think that
this is version of the definition you propose may benefit from being
written less point free (eg   =  \ val -> min high $ max low a) for clarity
and for how ghc optimizes

theres several ways we could make it play nice with nans, but maybe this
should go in as is, to force me to get irate about ord for floats and
finish some long overdue patches to Ord on Float and double :)

either way, please throw a PR onto gitlab and @ myself and other folks for
review



On Fri, Aug 14, 2020 at 5:38 PM Sandy Maguire <sandy at sandymaguire.me> wrote:

> Hi all,
>
> It seems to me that base is missing the very standard function `clamp ::
> Ord a => a -> a -> a -> a`:
>
> ```haskell
> clamp :: Ord a => a -> a -> a -> a
> clamp low high = min high .max low
> ```
>
> I propose it be added to Data.Ord. It's useful, generic, and non-trivial
> to get right (the "big" number goes with "min" -- causes me cognitive
> dissonance every time.)
>
> Thanks,
> Sandy
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20200814/488d5326/attachment.html>


More information about the Libraries mailing list