Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is the most idiomatic way to "lift up" by some transformation both arguments of a binary function in Haskell?

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)
like image 913
ramntry Avatar asked Jul 28 '14 11:07

ramntry


1 Answers

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.

like image 68
Zeta Avatar answered Sep 21 '22 12:09

Zeta