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
fiband 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
- For example, if you have an array of integers called
- 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
setfunction. - 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(", ")
);
- 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
- Closures:
- Syntax
- Destructuring (pattern matching):
let Rectangle { pos : (x, y) } = rect; ...
- Destructuring (pattern matching):
- 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
- Basic syntax
- Array and loop
- Structs
- Unions
- Traits
- Iterators
- Index Syntax
- For more, see examples.
- See the tutorial for instructions on how to install and use Fix compiler.
- Tutorial and language specification
- チュートリアルと言語仕様(日本語)
- Document for all modules in the default registry
- Change log
- 紹介(日本語):HaskellとRustを足して2で割ったような関数型言語Fixを作っている話
See this page.
- https://discord.gg/ad4GakEA7R
- Mostly Japanese speakers here, but English is also welcome!