Coconut: A Novel Language for Functional Programming in Python

Evan Hubinger


Coconut ( is a functional programming language that compiles to Python. All valid Python 3 is valid Coconut, and Coconut compiles to universal, version-independent Python—thus, using Coconut will only extend and enhance what you're already capable of in Python to include simple, elegant, Pythonic functional programming. * Coconut improves the code it compiles, optimizing away tail calls and producing universal code that runs the same on any Python version, making the 2/3 split a thing of the past. * Coconut extends Python syntax to include new constructs for pattern matching, algebraic data types, partial application, lazy lists, and much more, making functional programming in Python beautiful and elegant in a truly Pythonic style. Functional programming in Python is often difficult—some things work but are ugly (lambda, functools.partial) and many things don't work at all (tail call optimization, pattern matching, algebraic data types). Coconut solves this problem, doing to functional programming what Python did for imperative programming, and bringing the powerful tools of modern functional programming to Python programmers everywhere.