Coconut

Coconut is a functional programming language that compiles to Python. Since all valid Python is valid Coconut, using Coconut will only extend and enhance what you're already capable of in Python.

Why use Coconut? Coconut is built to be fundamentally useful. Coconut enhances the repertoire of Python programmers to include the tools of modern functional programming, in such a way that those tools are easy to use and immensely powerful; that is, Coconut does to functional programming what Python did to imperative programming. And Coconut code runs the same on any Python version, making the Python 2/3 split a thing of the past.

Installing Coconut is as easy as

  1. installing Python,
  2. opening a command-line prompt,
  3. and entering:
pip install coconut

which will give you access to all the features of Coconut, which adds to Python built-in, syntactical support for:

"hello, world!" |> print
(x) -> x ** 2
range(10) |> map$((x) -> x ** 2) |> list
match [head] + tail in [0, 1, 2, 3]:
    print(head, tail)
{"list": [0] + rest} = {"list": [0, 1, 2, 3]}
5 `mod` 3 == 2
range(15) |> map$((*)$(2)) |> list
(f .. g .. h)(x, y, z)
(| first_elem() |) :: rest_elems()
range(100) |> parallel_map$((**)$(2)) |> list
def factorial(n, acc=1):
    case n:
        match 0:
            return acc
        match _ is int if n > 0:
            return factorial(n-1, acc*n)
    else:
        raise TypeError("the argument to factorial must be an integer >= 0")
data Empty()
data Leaf(n)
data Node(l, r)

def size(Empty()) = 0

@addpattern(size)
def size(Leaf(n)) = 1

@addpattern(size)
def size(Node(l, r)) = size(l) + size(r)

size(Node(Empty(), Leaf(10))) == 1

and much more!

Ready to get started? Here are some links to help you out: