[updated] Functional programming language for C programmers and friends

Just for you:

module main {
    import std (range);
    import std.io (printf, IO);
    /* print the Fahrenheit-Celcius table
        for fahr = 0, 20, ..., 300 */
    function main(mutable IO io) {
        Int lower = 0;   // lower bound
        Int upper = 300; // upper bound
        Int step = 20;   // step
        for (Int fahr in range(lower, upper, step)) {
            Double celcius = 5 * (fahr - 32) / 9;
            std.io.printf(io, "%3d\t%6.1f\n", fahr, celcius);

It does not really look like it, but this language is purely functional. It represents side effects using unique types. If you declare a mutable parameter, you basically declare a unique input parameter and a unique output parameter.

I’m also giving you a list implementation

module std.container.list {

    /** The standard singly-linked list type */
    type List[E] {
        Nil;                    /** empty list */
        Node {
            E value;            /** current value */
            List[E] next;       /** remaining list */

Thus are only excerpts from a document with tens of pages and the reference implementation of the standard library. The incomplete working draft for the language is attached: JAK Programming Language Early Working Draft (28 pages).

Update: Fixed the link.

4 thoughts on “[updated] Functional programming language for C programmers and friends

    1. I forgot to mention it everywhere, but the function keyword and part of the syntax is actually inspired by JavaScript. Once an initial version of the language is available, it should also get type inference, so you can do cool code that looks like JavaScript.

  1. Make semicolons and brackets optional (as with a compiler option) to have any chance of interest from Python crowd. Any language with so many extra syntax characters looks messy and dirty to a Python programmer.

Comments are closed.