Skip to content

Instantly share code, notes, and snippets.

@onlyshk
Created December 7, 2011 07:04
Show Gist options
  • Save onlyshk/1441804 to your computer and use it in GitHub Desktop.
Save onlyshk/1441804 to your computer and use it in GitHub Desktop.
Lifting functions more than 1 parameter
lift0 :: a -> Pair a
lift0 x = Pair x x
lift2 :: (a -> b -> r) -> (Pair a -> Pair b -> Pair r)
lift2 f (Pair x1 x2) (Pair y1 y2) = Pair (f x1 y1) (f x2 y2)
plus :: Pair Int -> Pair Int -> Pair Int
plus = lift2 (+)
-- plus (Pair 1 2) (Pair 3 4) ---> Pair 4 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment