Quickstart
Code Example
import sqrt from "math"
// Approximate the golden ratio
let golden = {depth ->
let recur =
{d -> if d <= 0 then 1 else 1 + 1 / recur(d - 1)}
in recur(depth)
} in golden(10) // ≈ 1.618
// Composition and pipes
let add1 = {x -> x + 1},
double = {x -> x * 2}
in 5 |> (add1 >> double) // 12
// Partial Application
{a, b, c -> a+b+c}(_, 5, _)
// {a,c -> a+5+c}
// Assertions
sqrt(49) ---> $ == 7
Install from PyPI
pip install numfu-lang
Start an interactive REPL
numfu repl
Run a file
numfu example.nfu
What Makes NumFu Special?
- Functions First: Everything is a function. You can curry, compose, and pass functions freely; partial application is natively supported.
- Tail Call Optimization: NumFu automatically optimizes tail-recursive calls so you don't run into stack overflow issues.
- Clean Syntax: Intuitive syntax inspired by math, designed to be readable even for those who don’t use functional languages daily.
- Customizable Precision: Numbers use arbitrary precision by default, powered by native GNU MPFR bindings.
- Designed for Learning & Extensibility: NumFu is minimal by design, making it easy to explore, understand, and modify. It is 100% written in Python.
A quick demo
{x, y, z -> x + y + z}(_, 2);
// {x, z -> x+2+z}
[5, 12, 3] |> filter(_, _ > 4) |> map(_, _ * 2)
// [10, 24]
// Efficient tail-recursive sum
let sum_to = {n, acc ->
if n <= 0 then acc
else sum_to(n - 1, acc + n)
} in
sum_to(100000, 0) // 5000050000
let distance = {x1, y1, x2, y2 ->
let dx = x2 - x1, dy = y2 - y1 in
sqrt(dx^2 + dy^2)
} in
distance(0, 0, 3, 4) // 5
0.1 + 0.2 == 0.3
// true