3 ms·
I'm writing a new functional language using Rust as a side project. The repository is not yet opensource because it's in a very early stage (syntax/grammar not
by linkdd 5y ago
I'm writing a new functional language using Rust as a side project.
The repository is not yet opensource because it's in a very early stage (syntax/grammar not definitive, AST not definitive, ...), but if you'd like to help, feel free to contact me (my email is public on github: https://github.com/linkdd https://github.com/linkdd
The key features of the language are:
1. values does not have a single type, instead a type declares what values it has:
class int(n: number) check
frac(n) = 0
end
42 is int # true
42 is number # true
42 is string # false
2. Equations that have one or more solutions yields a boolean (need to implement a SAT solver)
class even(n: int) check
thereis k: int, n = 2 * k
end
42 is int # true
42 is even # true
43 is even # false
3. Expressive type definitions:
class odd(n: int & !even)
43 is even # false
43 is odd # true
class result(r: (:ok | :error, any))
(:ok, 42) is result # true
(:error, "oops") is result # false
# NB: `:ok` and `:error` are atoms like in Erlang/Elixir
4. Generics:
class ok<T>(val: (:ok, T))
class err<T>(val: (:error, T))
class result<T, E>(r: ok<T> | err<E>)
ok<int>(42) is result<int, string> # true
err<string>("oops") is result<int, string> # true
5. Set builder notation:
let s = { x: int | x > 0 }
s is set<int> # true
let russel_paradox = { x: set | x not in x }
# impossible:
# set class does not exist, but the generic class set<T> does
# set<T> can only contains T, therefore:
# { x: set<int> | x not in x }
# is invalid as well, since set<int> is not an int
6. Map/Filter/Reduce operators:
let sum_of_even_ints_below_10 = { x: int }
|map x => x * 2
|filter x => x < 10
|reduce[0] acc, x => x + acc
7. First order logic operators:
(true ==> true) = true
(true ==> false) = false
(false ==> true) = true
(false ==> false) = true
(true <==> true) = true
(true <==> false) = false
(false <==> true) = false
(false <==> false) = true
8. Rust-like Pattern matching:
x := 42
y := match x {
42 => true
_ => false
}
9. Goroutines and streams
func worker(s: stream<int>) -> :ok
do
let val: int
s >> val
s << (val * 2)
:ok # single point of return, last expression is the return statement
end
func main() -> (:ok | :error)
do
let s: stream<int>
run worker(s)
s << 1
let val: int
s >> val
match val {
2 => :ok,
_ => :error
}
end
10. For now, it's an interpreted language, but I'd like to compile to LLVM IR instead