NekoML is a high-order functional language with type inference. It can be seen as Neko with a powerful static type system. It is very suitable for complex data structure manipulation, such as is performed by compilers. NekoML is inspired by OCaml but walks different ways on some points.
NekoML comes with several builtin types, and you can define your own types quite easily :
Core types :
1234 : int
1.234 : float
"hello" : string
true : bool
'\n' : char
() : void
Tuples :
(1,true) : (int, bool)
("a",(),1.23) : (string, void, float)
Union types :
type t {
A;
B;
C : int;
D : (int , string);
}
A : t;
B : t;
C(0) : t;
D(1,"") : t;
D : int -> string -> t;
Records :
type t {
x : int;
y : int;
}
{ x = 1; y = 2 } : t
Mutable record fields :
type t {
mutable counter : int;
}
var x = { counter = 0 };
x.counter := 1;
Abstract types :
type t
Recursive types :
type t1 // declare as abstract
type t2 {
A : t1;
B : t2;
}
type t1 { // declare
C : t1;
D : t2;
}
Parametrized types :
type ('a,'b) pair {
fst : 'a;
snd : 'b;
}
Function Types :
function() { } : void -> void;
function(x,y) { x + y } : int -> int -> int
Lists :
[1; 2; 3] : int list
Lists contructors :
[] : 'a list;
0 :: [] : int list;
"a" :: "" :: [] : string list
The syntax of NekoML is similar to the syntax of Neko, but with some additional constructs.
Blocks :
{ f(); g(); h() }
Variables declaration :
var x = (expr);
Conditions :
if (expr) then (expr) [else (expr)]
Calls using parenthesis :
f(1,2,3);
g();
h((1,2)); // call with a tuple
Calls using spaces :
f 1 2 3;
g ();
h (1,2); // call with a tuple
Mixed calls :
f (1,2) g() h (1,2);
// means
f((1,2),g(),h,(1,2));
Function declarations : you can declare a function anonymously or with a name to add it to the local scope
var f = function() { ... };
// equivalent to
function f() {
...
}
Recursive functions. When several following functions are declared recursive (using rec
), they're mutually recursive so they can call each other :
function rec f() {
g()
}
function rec g() {
f()
}
If you're interested in NekoML, you can watch the Neko and NekoML compiler sources as well as the NekoML standard library, which are on the Neko CVS. You can also ask on the Neko mailing list.
© 2019 Haxe Foundation | Contribute to this page