Evil ML is a joke compiler from ML to C++ template language (not ordinary C++ code). Please, don't use this for practical purposes.
C++ template is a higher-order pure functional programming language traditionally used for compile-time computation, while its syntax is verbose and hard to use. ML, a higher-order functional programming language, is simple, practical and easy to understand, so that we jokingly implemented this compiler. You can easily use black magic in C++ template programming. This will give you nightmares.
P.S. constexpr (supported C++11 or above) is useful. Why don't you use it?
(*! ... *) in top level.#use "foo.ml" loads .ml files in top level (double semi-colons ;;
are not needed at the end). The .ml files you can load are found in
directory evilml/include.Difference from OCaml:
char list (type string does not exist).type keyword in top level can only define variant types. You cannot
declare aliases of types and records.match. Patterns cannot appear in formal
arguments and l.h.s. of let bindings.[a-zA-Z_][a-zA-Z0-9_]*.
Primes cannot be used, and names that begin __ml_ are
reserved by this compiler. Identifiers of data constructors begin capital
letters../configure
make
make install
You can compile foo.ml as follows:
evilml foo.ml
examples/quicksort/qsort.ml implements quick sort of a list of 8 elements. You can compile the ML program into C++ template as online demo.
qsort.cpp$ g++ qsort.cpp
$ ./a.out
1 2 3 4 5 6 7 8
In order to make sure that sorting is executed in compile time,
we suggest to use g++ -S qsort.cpp and open qsort.s:
...
movl $1, 4(%esp) ; pass 1 to printf
movl $.LC0, (%esp)
call printf
movl $2, 4(%esp) ; pass 2 to printf
movl $.LC0, (%esp)
call printf
movl $3, 4(%esp) ; pass 3 to printf
movl $.LC0, (%esp)
call printf
movl $4, 4(%esp) ; pass 4 to printf
movl $.LC0, (%esp)
call printf
movl $5, 4(%esp) ; pass 5 to printf
movl $.LC0, (%esp)
call printf
movl $6, 4(%esp) ; pass 6 to printf
movl $.LC0, (%esp)
call printf
movl $7, 4(%esp) ; pass 7 to printf
movl $.LC0, (%esp)
call printf
movl $8, 4(%esp) ; pass 8 to printf
movl $.LC1, (%esp)
call printf
...
(Of course, you can use std::cout to print integers in qsort.cpp,
however we make use of printf for readable assembly code.)
let rec diverge _ = diverge () should be infinite loop, but generated C++
code causes compilation error. let rec diverge n = diverge (n+1) passes C++
compilation. (I don't know the formal definition of reduction rules of C++
template expressions.)JavaScript
52.3%
OCaml
44.6%
CSS
1.1%
Evil ML is a joke compiler from ML to C++ template language (not ordinary C++ code). Please, don't use this for practical purposes.
C++ template is a higher-order pure functional programming language traditionally used for compile-time computation, while its syntax is verbose and hard to use. ML, a higher-order functional programming language, is simple, practical and easy to understand, so that we jokingly implemented this compiler. You can easily use black magic in C++ template programming. This will give you nightmares.
P.S. constexpr (supported C++11 or above) is useful. Why don't you use it?
(*! ... *) in top level.#use "foo.ml" loads .ml files in top level (double semi-colons ;;
are not needed at the end). The .ml files you can load are found in
directory evilml/include.Difference from OCaml:
char list (type string does not exist).type keyword in top level can only define variant types. You cannot
declare aliases of types and records.match. Patterns cannot appear in formal
arguments and l.h.s. of let bindings.[a-zA-Z_][a-zA-Z0-9_]*.
Primes cannot be used, and names that begin __ml_ are
reserved by this compiler. Identifiers of data constructors begin capital
letters../configure
make
make install
You can compile foo.ml as follows:
evilml foo.ml
examples/quicksort/qsort.ml implements quick sort of a list of 8 elements. You can compile the ML program into C++ template as online demo.
qsort.cpp$ g++ qsort.cpp
$ ./a.out
1 2 3 4 5 6 7 8
In order to make sure that sorting is executed in compile time,
we suggest to use g++ -S qsort.cpp and open qsort.s:
...
movl $1, 4(%esp) ; pass 1 to printf
movl $.LC0, (%esp)
call printf
movl $2, 4(%esp) ; pass 2 to printf
movl $.LC0, (%esp)
call printf
movl $3, 4(%esp) ; pass 3 to printf
movl $.LC0, (%esp)
call printf
movl $4, 4(%esp) ; pass 4 to printf
movl $.LC0, (%esp)
call printf
movl $5, 4(%esp) ; pass 5 to printf
movl $.LC0, (%esp)
call printf
movl $6, 4(%esp) ; pass 6 to printf
movl $.LC0, (%esp)
call printf
movl $7, 4(%esp) ; pass 7 to printf
movl $.LC0, (%esp)
call printf
movl $8, 4(%esp) ; pass 8 to printf
movl $.LC1, (%esp)
call printf
...
(Of course, you can use std::cout to print integers in qsort.cpp,
however we make use of printf for readable assembly code.)
let rec diverge _ = diverge () should be infinite loop, but generated C++
code causes compilation error. let rec diverge n = diverge (n+1) passes C++
compilation. (I don't know the formal definition of reduction rules of C++
template expressions.)JavaScript
52.3%
OCaml
44.6%
CSS
1.1%