clamp function in base

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Sat Aug 15 09:23:38 UTC 2020


At the risk of bikeshedding, I don't think "clamp" is a very
descriptive/findable name for this.  What about "bounded"?

Otherwise, +1

On Sat, 15 Aug 2020 at 13:40, David Feuer <david.feuer at gmail.com> wrote:

> Strict. Making the function lazy to be extra efficient when given
> useless arguments means demand analysis will be worse for no good
> reason.
>
> On Fri, Aug 14, 2020 at 11:56 PM Carter Schonwald
> <carter.schonwald at gmail.com> wrote:
> >
> > Wonderful! Your aside about inverted Lo and hi clamping arguments does
> raise a fun question about strictness for the value argument!  When  low
> and hi are equal, the result is constant. Should the value arg be strict or
> lazy when it’s essentially the constant function?
> >
> > On Fri, Aug 14, 2020 at 11:30 PM Sandy Maguire <sandy at sandymaguire.me>
> wrote:
> >>
> >> 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
> >
> > _______________________________________________
> > Libraries mailing list
> > Libraries at haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>


-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
http://IvanMiljenovic.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20200815/06c70834/attachment.html>


More information about the Libraries mailing list