7 ms·
Sure, but it introduces two new, even scarier names and isn't even as short as multiclamp = clamp >=> return clamp or as general as allclamp lims x = fol
by tel 17y ago
Sure, but it introduces two new, even scarier names and isn't even as short as
multiclamp = clamp >=> return clamp
or as general as
allclamp lims x = foldM (flip clamp) x lims
Haskell is easy to make very, very opaque at the promise of generality, but if you're just making Maybes there's no need to dig that deep.
- eru 17y agoYou are right. Though actually foldM is not that opaque once you get used to it.
- tel 17y agoOh, no. I like the foldM implementation. I like Kleisli arrows, too, but this application isn't even on the same planet of generality from where Kleisli lives on.
- loup-vaillant 17y agoErr, I don't know what >=> means. Do you have a pointer?
- tel 17y agoYeah, I had to introduce one more scary name to do it, but (>=>) is really a good one to learn. It's monadic composition. (>=>) :: (Monad m) => (a -> m b) -> (b -> m c) -> (a -> m c) (>=>) c1 c2 a = (c1 a) >>= c2 It really helps to clean up some names that normally would be carried all throughout do-less monadic code.