Skip to content

Instantly share code, notes, and snippets.

@Nil-Zil Nil-Zil/add4ways.hs
Last active Jan 20, 2018

Embed
What would you like to do?
4 ways to implement `add` in Haskell.
add :: (Int, Int) -> Int -- function with 2 parameters
add (x, y) = x + y
add2 :: Int -> (Int -> Int) -- Curry
add2 x y = x + y
-- return partially applied functions
addone = add2 1
addlambda :: Int -> Int -> Int
addlambda = \x y -> x + y
addlambda2 :: Int -> (Int -> Int)
addlambda2 x = \y -> x + y
normalAdd :: Num a => a -> a -> a
normalAdd x y = x + y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.