Haskell Curry (and Uncurry)

  1. the function takes two parameters of type a and b and returns a type c. [i.e. (a → b) → c ]
  2. Or, the function takes a parameter of type a and returns a function of type b → c . [i.e. a → (b → c) ]
add :: Int -> Int -> Int
add x y = x+y
ghci> let add2 = add 3
ghci> add2 4
7
ghci> add 3 4
7
curry :: ((a, b) -> c) -> a -> b -> c
uncurry :: (a -> b -> c) -> ((a, b) -> c)
cur1 :: (Num a) => a -> a -> a                                                           cur1 x y = x+yghci>add1 = uncurry cur1
ghci> add1 (1,2)
3
ghci> add1 1
**ERROR**
uncur1 :: (Num a) => (a,a) -> a
uncur1 x = fst x + snd x
ghci> add1 = curry uncur1
ghci> add1 1 2
3
ghci> let add2 = add1 1
ghci> add2 2
3

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Digging deeper: working as an iOS developer at Bornfight

[LeetCode]#167. Two Sum II — Input array is sorted

Backbone, Marionette — simple form validation with Backbone Model, Marionette’s regions and child…

Code Smell 03 — Functions Are Too Long

The Rust programing language ebook

Wrapper Classes in Java | Use, Example

250+ pcs new animals 3d stl models for cnc router 3d-printer artcam aspire cut3d -Download

250+ pcs new animals 3d stl models for cnc router 3d-printer artcam aspire cut3d -Download

🏷️Terraform Introduction(Easy)

Terraform files, which have the extension as .tf for every file(filename.tf), can be produced separately for each of the file categories like main.tf, variables.tf, outputs.tf, locals.tf etc. The flow of infrastructure development is pictured above.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Priyanka Mondal

Priyanka Mondal

More from Medium

COP chromatic aberration

Celsius Network money laundering

Eagle : The Great Image Organiser

“Fools rush in where fools have been”-Must this be the school environment?