clamp function in base

Sandy Maguire sandy at sandymaguire.me
Sat Aug 15 03:30:24 UTC 2020


Yay! I've opened !3876 at
https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3876

On Fri, Aug 14, 2020 at 5:45 PM Carter Schonwald <carter.schonwald at gmail.com>
wrote:

>
>
> 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/0bb94c07/attachment.html>


More information about the Libraries mailing list