All Projects → akabe → Evilml

akabe / Evilml

A compiler from ML to C++ template language

Programming Languages

javascript
184084 projects - #8 most used programming language
cpp
1120 projects
ocaml
1615 projects

Projects that are alternatives of or similar to Evilml

Redux Most
Most.js based middleware for Redux. Handle async actions with monadic streams & reactive programming.
Stars: ✭ 137 (-8.05%)
Mutual labels:  functional-programming
Monix
Asynchronous, Reactive Programming for Scala and Scala.js.
Stars: ✭ 1,819 (+1120.81%)
Mutual labels:  functional-programming
Rangeless
c++ LINQ -like library of higher-order functions for data manipulation
Stars: ✭ 148 (-0.67%)
Mutual labels:  functional-programming
Ramda Extension
🤘Utility library for functional JavaScript. With ❤️ to Ramda.
Stars: ✭ 139 (-6.71%)
Mutual labels:  functional-programming
Parjs
JavaScript parser-combinator library
Stars: ✭ 145 (-2.68%)
Mutual labels:  functional-programming
Kingly
Zero-cost state-machine library for robust, testable and portable user interfaces (most machines compile ~1-2KB)
Stars: ✭ 147 (-1.34%)
Mutual labels:  functional-programming
Conduit
High Performance Streams Based on Coroutine TS ⚡
Stars: ✭ 135 (-9.4%)
Mutual labels:  functional-programming
Meow Mtl
Next Level MTL for Scala
Stars: ✭ 149 (+0%)
Mutual labels:  functional-programming
Lazy Collections
Collection of fast and lazy operations
Stars: ✭ 146 (-2.01%)
Mutual labels:  functional-programming
Munus
Power of object-oriented programming with the elegance of functional programming in PHP.
Stars: ✭ 149 (+0%)
Mutual labels:  functional-programming
Marble
Marble.js - functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS.
Stars: ✭ 1,947 (+1206.71%)
Mutual labels:  functional-programming
Kefir
A Reactive Programming library for JavaScript
Stars: ✭ 1,769 (+1087.25%)
Mutual labels:  functional-programming
Rambdax
Extended version of Rambda
Stars: ✭ 148 (-0.67%)
Mutual labels:  functional-programming
Sup
Composable, purely functional healthchecks in Scala.
Stars: ✭ 138 (-7.38%)
Mutual labels:  functional-programming
Doobie
Functional JDBC layer for Scala.
Stars: ✭ 1,910 (+1181.88%)
Mutual labels:  functional-programming
Canoe
Functional Telegram Bot API for Scala
Stars: ✭ 137 (-8.05%)
Mutual labels:  functional-programming
Ip4s
Defines immutable, safe data structures for describing IP addresses, multicast joins, socket addresses and similar IP & network related data types
Stars: ✭ 145 (-2.68%)
Mutual labels:  functional-programming
Purescript Presto
Write Apps like Mathematical Equations!
Stars: ✭ 149 (+0%)
Mutual labels:  functional-programming
Cube Composer
A puzzle game inspired by functional programming
Stars: ✭ 1,845 (+1138.26%)
Mutual labels:  functional-programming
Typelang
🌳 A tiny language interpreter implemented purely in TypeScript's type-system
Stars: ✭ 149 (+0%)
Mutual labels:  functional-programming

Evil ML

Build Status

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?

Features

  • OCaml-like higher-order pure functional language (Hindley-Milner polymorphism, no value restriction).
  • Type inference is performed. Most types are automatically inferred.
  • Variant types are supported.
  • You can write raw C++ code in (*! ... *) 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:

  • Strings have type char list (type string does not exist).
  • Module system and separate compilation are not supported.
  • User-defined operators are not allowed.
  • type keyword in top level can only define variant types. You cannot declare aliases of types and records.
  • Pattern match is only performed by match. Patterns cannot appear in formal arguments and l.h.s. of let bindings.
  • Exhaustivity checking of pattern matching is not implemented. (future work)
  • Identifiers are defined as regular expression [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.
  • Top-level shadowing of identifiers (variables, types, and constructors) is prohibited.

Install

./configure
make
make install

Usage

You can compile foo.ml as follows:

evilml foo.ml

Demo: quick sort

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.

  1. Check the check box of "Generate stand-alone code (embedding evilml.hpp)"
  2. Push the button "Compile"
  3. Copy and paste the generated C++ code into file qsort.cpp
  4. Try to compile and run it:
$ 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.)

Bugs

  • 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.)
  • C++03 template prohibits operation of float-point values, so that this compiler outputs wrong code.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].