Ivy

Source code: github.com/gtr/ivy

Ivy is a statically typed functional programming language: friendly enough for beginners, robust enough for experienced programmers. Built to be inspected, reasoned about, and trusted.

Ivy is still a work-in-progress. There are many features that are yet to be implemented, but it's decently useful at the moment. Stay tuned for more!

Features

Hindley-Milner type inference Algebraic data types Pattern matching First-class functions Interactive REPL Clean, minimal syntax

Ivy in action

-- Lists support pattern matching in function heads.

fn length([]) => 0;
fn length([_ :: tail]) => 1 + length(tail);

fn map(f, []) => [];
fn map(f, [head :: tail]) => f(head) :: map(f, tail);

let numbers = [1, 2, 3, 4, 5];
let doubled = map(fn (x) => x * 2, numbers);

println("Doubled: " ++ show(doubled));

Algebraic Types

-- Define a binary tree with a type parameter.

type Tree<a> =
| Empty
| Node(a, Tree<a>, Tree<a>)
;

fn count(Empty) => 0;
fn count(Node(_, left, right)) =>
    1 + count(left) + count(right);

let tree = Node(1, Node(2, Empty, Empty), Empty);
println("Nodes: " ++ show(count(tree)));

Interactive REPL

  _
 (_)_   ___   _
 | \ \ / / | | |
 | |\ V /| |_| |
 |_| \_/  \__, |
          |___/  v0.2

Ivy - the friendly functional programming language
Type :help for commands, :q to quit
ivy> :help
Ivy REPL Commands:

  :help, :h          Show this help message
  :quit, :q          Exit the REPL
  :reset, :r         Reset interpreter state (clear all definitions)
  :load <path>, :l   Load and execute a file
  :type <expr>, :t   Show the inferred type of an expression
  :env               Show all defined names in current scope

Multi-line input is supported. The REPL will continue prompting
with '...>' when it detects unclosed brackets or expressions.
ivy> :type length
length : List<a> -> Int
ivy> length([1, 2, 3, 4, 5])
5
ivy> map(fn (x) => x * x, [1, 2, 3])
[1, 4, 9]