Skip to content

tttmmmyyyy/fixlang

Repository files navigation

Fix-lang: Fix Programming Language

Overview

Fix is a purely functional programming language designed to be easy to learn, easy to use, and enjoyable.

You can try Fix in the Fix playground.

Concepts:

  • Syntax that combines the advantages of functional and OOP languages
    • For example, if you have an array of integers called fib and you want to display it on the screen, you can write any of the following:
      • println(fib.to_iter.map(to_string).join(", "))
      • println $ fib.to_iter.map(to_string).join(", ")
      • fib.to_iter.map(to_string).join(", ").println
  • In-place update
    • Since Fix uses reference counting for memory management, it can update uniquely referenced values in place while being purely functional.
    • As an example, look at the program below that calculates the Fibonacci sequence. In this code, the array is never cloned when modified by the set function.
    • This allows Fix to implement algorithms naturally using arrays and hash tables, while remaining purely functional.
  • Performance
    • While Fix is still undergoing benchmarking and optimization, Fix can achieve performance comparable to C++ in a few simple programs that I have tested.
    • One of Fix's goals is to compile high-level code into high-performance code without introducing low-level concepts such as "reference" and "lifetime" into the language.

The following is an example program that calculates the Fibonacci sequence using Fix:

module Main;

calc_fib : I64 -> Array I64;
calc_fib = |n| (
    let arr = Array::fill(n, 0);
    let arr = arr.set(0, 1);
    let arr = arr.set(1, 1);
    let arr = loop((2, arr), |(idx, arr)|
        if idx == arr.get_size {
            break $ arr
        } else {
            let x = arr.@(idx-1);
            let y = arr.@(idx-2);
            let arr = arr.set(idx, x+y);
            continue $ (idx+1, arr)
        }
    );
    arr
);

main : IO ();
main = (
    let fib = calc_fib(30);
    println("The first 30 numbers of Fibonacci sequence are: ");;
    println $ fib.to_iter.map(to_string).join(", ")
);

Features

  • Functional paradigm and type system
    • Closures: |x| x + 42
    • Higher kinded types and traits: Array : Functor, IO : Monad, etc.
    • Associated types to traits: Iterator::Item
    • Syntax for combining monads (;; and *): main : IO () = println("I will echo you: ");; println(*input_line);
    • Syntax for using Lens to manipulate hierarchical data: array_of_vectors[2][^x].iset(3.0) // Update the "x" field of the struct at index 2 of an array of vectors
  • Syntax
    • Destructuring (pattern matching): let Rectangle { pos : (x, y) } = rect; ...
  • Memory management & mutability
    • In-place update of values which is uniquely referenced
    • Memory safety and thread safety
    • No memory leak achieved by avoiding cyclic references syntactically
  • Multithreading
  • Foreign function interface (FFI)
  • Tools
    • Dependency manager
    • Document generation
    • Language Server Protocol (LSP) support

Examples

Usage

  • See the tutorial for instructions on how to install and use Fix compiler.

Documents

Third-party licenses

See this page.

Discord

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages