
Evil ML: ML to C++ template language - ingve
http://akabe.github.io/evilml/
======
dunkelheit
Neat hack :) Actually whenever I need to do some C++ template metaprogramming
I first imagine a functional program that would perform the task and then
translate it into templates. Turns out it is much easier than starting with
templates directly!

~~~
dman
That is a neat hack - I will try this out soon.

------
srean
If ML and C++ excites you, don't miss out on Felix. [http://felix-
Lang.org](http://felix-Lang.org) You will get more out of it if ML excites you
more than C++, rather it is the possibility of talking to C++ with minimal or
no glue that excites you.

It wont be totally wrong to say that it is to C++ what F# is to C#, or perhaps
little more accurately Scala to Java.

It is plenty fast too. A toy brainfuck interpreter written in it turned out to
be speedier than C++, D, Go, but got beaten by an interpreter written in nim.
Can post the link once I get off the phone.

EDIT: Here it is
[https://github.com/kostya/benchmarks/blob/master/README.md#b...](https://github.com/kostya/benchmarks/blob/master/README.md#benchb)

Something I find interesting is that it has had fibres and coroutines long
before go was a thing. The author(not me) used it in his projects on telco
switches.

~~~
nly
Benchmark is rubbish. The Nim version is using a standard nim 'table' for the
bracket_map, which is a hash table. The C++ version is using std::map which is
a red-black tree.

A quick once-over with gprof shows the C++ interpreter running bench.b shows
it is spending 30% of its time allocating rb-tree nodes and another 30%
searching it.

Swapping it out for a unordered_map (a hash table) actually makes it slower,
but ~40% of the runtime is then sunk in to inserting in to the hash table.
Probably allocating

I couldn't be bothered to drill in any further.

~~~
srean
Just so that you know neither the Felix author nor me are involved in the
benchmark. More tellingly the benchmarked codes were user contributed.
Regardless I did not get your point, just in case you had any. Different
implementations used their idiomatic data structures and got what they got.
You ranted about the choice and tried an alternative and it turned out to be
slower and dismissed it entirely saying none of this is worth your time. And
you said all these because ...? There is probably a reason and an underlying
conclusion you wanted to convey, but frankly it escapes me so I couldn't be
bothered with following up further on a middle brow dismissal either.

------
nickpsecurity
That's pretty cool. A long time ago, I had a mock-up of C/C++ in LISP that let
me use LISP macro's instead of C++'s metaprogramming. A generator produced
C/C++ from it when I was done with the algorithm. Much automation of
boilerplate, portability, security, etc w/ some 4GL-style stuff for
productivity and LISP's incremental (per function) compilation. Miss that
tool.

Anyway, just mentioning it because it's best of two worlds and someone else
might want to re-create the concept. I saw one person do something similar for
C just for interactive development. However, my old toolkit showed it could do
a lot more. Some bright people could probably take it way further than what I
did.

------
Rexxar
Nice but I will nitpick a little:

\- double underscores at the beginning of names are reserved for compiler/STL.

\- Using a namespace instead of "__ml_" seems more appropriate.

------
jlarocco
Looks neat, but I can't get it to compile. I get hundreds of warnings about
interfaces existing in multiple locations, and then finally an error that
module Location is defined in src/location.cmx and ocamlcommon.cmxa.

------
vvanders
Oh god, I don't even want to think about the compile times.

~~~
nickpsecurity
In my LISP/C/C++ system I referenced, I was able to largely eliminate compile
times by doing the development in LISP until it was correct and batching
overnight an extraction to C/C++ w/ compilation and tests. So, if it's done
right, it should be faster to iterate than a C++ tool even on older hardware.
Don't do a lot of work with the ML's or this tool so I can't remember if they
have the interactive option or at a good speed.

