DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Currying in Calculus, PDEs, Programming, and Category Theory

Currying in Calculus, PDEs, Programming, and Category Theory

Currying is an important concept in both math and functional programming. Let's take a quick look at why this concept is so useful.

John Cook user avatar by
John Cook
·
Aug. 16, 18 · Presentation
Like (3)
Save
Tweet
Share
7.69K Views

Join the DZone community and get the full member experience.

Join For Free

Currying is a simple but useful tool in both math and functional programming. It's named after logician Haskell Curry [1] and has nothing to do with spicy cuisine. If you have a function of two variables, you can think of it as a function of one variable that returns a function of another variable. So, starting with a function f( x, y), we can think of this as a function that takes a number x and returns a function f( x, -) of y. The dash is a placeholder, which can be seen in this recent post.

Calculus: Fubini's Theorem

If you've taken calculus, then you saw this in the context of Fubini's theorem:

To integrate the function of two variables f( x, y), you can temporarily fix y and integrate the remaining function of x. This gives you a number, the value of an integral, for each y, so it's a function of y. You will need to integrate that function, and you have the value of the original function of two variables.

The first time you see this you may think it's a definition, but it's not. You can define the integral on the left directly, and it will equal the result of the two nested integrations on the right or, at least, the two sides will often be equal. The conditions on Fubini's theorem tells you exactly when the two sides are equal.

PDEs: Evolution Equations

A more sophisticated version of the same trick occurs in partial differential equations. If you have an evolution equation, a PDE for a function on a one-time variable, and several space variables, you can think of it as an ODE via currying. For each time value, t, you get a function of the spatial variables. So, you can think of your solution as a path in a space of functions. The spatial derivatives specify an operator on that space of functions.

I'm glossing over some of the details here because spelling everything out would take a lot of writing and might obscure the big idea. If you'd like the full story, you can check out my graduate advisor's book.

Haskell Programming

In the Haskell programming language, also named after Haskell Curry, you get currying for free. In fact, there's no other way to express a function of two variables. For example, suppose you want to implement the function f( x, y) = x² + y.

    Prelude> f x y = x**2 + y


Then, Haskell thinks of this as a function of one variable (i.e. x) that returns a function of one variable (i.e. f( x, -)), which itself returns a number (i.e. f( x, y)). You can see this by asking the REPL for the type of f:

    Prelude> :info f
    f :: Floating a => a -> a -> a


Technically, Haskell, just like lambda calculus, only has functions of one variable. You could create a product datatype consisting of a pair of variables and have your function take that as an argument, but it's still a function on one variable, though that variable is not atomic.

Category Theory

The way you'd formalize currying in the category theory is to say that the following is a natural isomorphism:

For more on what Hom means, check out this post.

Related Posts

[1] In concordance with Stigler's law of eponymy, currying was not introduced by Curry but Gottlob Frege. It was then developed by Moses Schönfinkel and developed further by Haskell Curry.

Haskell (programming language) IT Curry (programming language) Integration philosophy Space (architecture) POST (HTTP) Theorem Express Law (stochastic processes)

Published at DZone with permission of John Cook, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Apache Kafka Is NOT Real Real-Time Data Streaming!
  • Building a RESTful API With AWS Lambda and Express
  • mTLS Everywere
  • OpenVPN With Radius and Multi-Factor Authentication

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: