An open API service indexing awesome lists of open source software.

https://github.com/giulioz/mlem

👨🏼‍💻👅 A Tiny ML-like language for research purposes
https://github.com/giulioz/mlem

compiler functional haskell language ml nearley ocaml parser types

Last synced: about 1 month ago
JSON representation

👨🏼‍💻👅 A Tiny ML-like language for research purposes

Awesome Lists containing this project

README

        

# MLem

**Meta Language Extensions and Manipulation**

![logo](logo.png)

### Syntax

Whole program is a big expression, use parentheses to avoid ambiguities.

- `let` binding
```
let name = value; expression
```

- Function apply — functions have only one parameter
```
inc 2
```

- Lambda abstraction
```
\x -> x
```

- Pattern matching
```
match exp with
| case -> value
| _ -> fallback
```

- Data Types
- Numeric integer literal `number`
- Tuples `(a,b,...)`
- String literal, between `""`

- Custom Types:
```
type Boolean = true | false;
type MaybeTwo = Just of number * number | Nothing;
```

Use Y Combinator for recursion (native recursion not yet supported).

#### Example program

```
type Boolean = true | false;
type MaybeTwo = Just of number * number | Nothing;

let Y = \f -> ((\x -> (x x)) (\y -> (f (\x -> ((y y) x)))));
let sub = \x -> \y -> (sum x (neg y));

let fibonacci = Y (\f -> \x ->
match x with
| 0 -> 0
| 1 -> 1
| x -> (
let a = (sub x) 1;
let b = (sub x) 2;
let fa = f a;
let fb = f b;
sum fa fb
)
);

match (fibonacci 8) with
| 21 -> true
| _ -> false
```

### Usage

Place your code in `test.mml`.

```
yarn install
yarn start
```

#### Rebuild grammar

```
yarn build
```