6

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)
Mokosha
  • 2,737
  • 16
  • 33
ramntry
  • 83
  • 4

1 Answers1

15

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.

Zeta
  • 103,620
  • 13
  • 194
  • 236
  • Wow, thank you very much for the fast answer and the link to hoogle especially! – ramntry Jul 28 '14 at 11:59
  • @ramntry: You might want to look at the [haskell tag info](http://stackoverflow.com/tags/haskell/info), it contains some good resources. – Zeta Jul 28 '14 at 12:03