Which is the most idiomatic way to "lift up" by some transformation both arguments of a binary function in Haskell? Let this operator be named "lift", so I expect it's type will be
lift :: (a -> b) -> (b -> b -> c) -> (a -> a -> c)
and a naive definition will be
lift t f = \x y -> f (t x) (t y)
It's called on
(from Data.Function
), although with flipped arguments:
on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
-- lift = flip on
Note that you could have found the function easily with a Hoogλe query. Also note that there's already a function lift
, which is used in a completely other setting, namely monad transformers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With