All Projects → Quramy → pico-ml

Quramy / pico-ml

Licence: MIT license
A toy programming language which is a subset of OCaml.

Programming Languages

typescript
32286 projects
CSS
56736 projects

Projects that are alternatives of or similar to pico-ml

yggdrasil-decision-forests
A collection of state-of-the-art algorithms for the training, serving and interpretation of Decision Forest models.
Stars: ✭ 156 (+333.33%)
Mutual labels:  ml
vision-camera-image-labeler
VisionCamera Frame Processor Plugin to label images using MLKit Vision
Stars: ✭ 62 (+72.22%)
Mutual labels:  ml
material-yew
Yew wrapper for Material Web Components
Stars: ✭ 116 (+222.22%)
Mutual labels:  wasm
wasm.cljc
Spec compliant WebAssembly compiler, decompiler, and generator
Stars: ✭ 178 (+394.44%)
Mutual labels:  wasm
web logger
Rust Logger for Web Browsers
Stars: ✭ 19 (-47.22%)
Mutual labels:  wasm
tune
Make xenharmonic music and create synthesizer tuning files for microtonal scales.
Stars: ✭ 73 (+102.78%)
Mutual labels:  wasm
WebAssembly-in-Action
Source code for the book "WebAssembly in Action" (https://www.manning.com/books/webassembly-in-action)
Stars: ✭ 44 (+22.22%)
Mutual labels:  wasm
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging 🤗
Stars: ✭ 20 (-44.44%)
Mutual labels:  wasm
SkyEmu
Game Boy, Game Boy Color, and Game Boy Advanced Emulator
Stars: ✭ 59 (+63.89%)
Mutual labels:  wasm
odahu-flow
No description or website provided.
Stars: ✭ 12 (-66.67%)
Mutual labels:  ml
swaplink
Site to perform peer to peer atomic swaps on the Algorand blockchain
Stars: ✭ 15 (-58.33%)
Mutual labels:  wasm
MixingBear
Package for automatic beat-mixing of music files in Python 🐻🎚
Stars: ✭ 73 (+102.78%)
Mutual labels:  ml
rust-monaco
Rust WASM bindings for the Monaco Editor
Stars: ✭ 23 (-36.11%)
Mutual labels:  wasm
webp-wasm
Webp image convertor (webassembly, works offline in browser)
Stars: ✭ 18 (-50%)
Mutual labels:  wasm
proxy-wasm-cpp-host
WebAssembly for Proxies (C++ host implementation)
Stars: ✭ 55 (+52.78%)
Mutual labels:  wasm
rust-wasm-loader
Webpack loader for Rust
Stars: ✭ 81 (+125%)
Mutual labels:  wasm
wasmfun
Getting the hang of WASM - generate WASM from Python
Stars: ✭ 34 (-5.56%)
Mutual labels:  wasm
whistle
🕴 One hella programming language
Stars: ✭ 27 (-25%)
Mutual labels:  wasm
wasm-bindgen-webcam-stream
A small example on how to get webcam stream on rust-wasm
Stars: ✭ 11 (-69.44%)
Mutual labels:  wasm
reactr
Function scheduler for Go & WebAssembly
Stars: ✭ 264 (+633.33%)
Mutual labels:  wasm

PicoML

github actions npm version

A toy programming language which is a subset of OCaml.

let rec fact n = if n < 2 then 1 else n * fact(n - 1) in
let rec range s e = if s >= e then [] else s::(range (s + 1) e) in
let rec map f list = match list with [] -> [] | x::y -> (f x)::(map f y) in
map fact (range 1 7) (* ==> int list: [ 1, 2, 6, 24, 120, 720 ] *)

Features

  • Interpreter
  • Type inference
  • Compile to WASM

Web Playground

Playground

You can try PicoML here.

How to use

Install

$ npm i -g pico-ml

REPL

You can REPL with ipml command.

$ ipml

# Input ML expression to evaluate
> let add = fun a -> fun b -> a + b in add 1 2;;

The REPL allows multiple line input. Enter ;; to evaluate the input expression.

Compiler

(* example.ml *)

let add = fun a -> fun b -> a + b in add 1 2

To compile Web Assembly module, use pmlc command.

$ pmlc example.ml

The generated module exports main function to evaluate the input expression.

// Execute in browser

const instance = await WebAssembly.instatiateStreaming(fetch("example.wasm"), {});
const result = instance.exports["main"]();
console.log(result);
// Execute in Node.js

const fs = require("fs/promises");

(async () => {
  const source = await fs.readFile("example.wasm");
  const { instance } = await WebAssembly.instantiate(source, {});
  const result = instance.exports["main"]();
  console.log(result);
})();

And pmlc can also outputs WAT file with -t option.

$ pmlc example.ml -t

Language

BNF

expr    ::= id |
            int |
            decimal |
            bool |
            "[]" |
            expr expr |
            unop expr |
            expr binop expr |
            expr "::" expr |
            "if" expr "then" expr "else" expr |
            "match" expr "with" clause |
            "fun" id "->" expr |
            "let" id id* "=" expr "in" expr |
            "let" "rec" id "=" "fun" id "->" expr "in" expr |
            "let" "rec" id id+ "=" expr "in" expr

clause  ::= pat "->" expr | pat "->" expr "|" clause

pat     ::= id | "[]" | "_" | pat "::" pat

id      ::= (letter | "_"){ letter | digit | "_" | "'" }

unop    ::= "-" | "-."

binop   ::= "+" | "-" | "*" | "/" | +." | "-." | "*." |"/." | "<" | ">" | "<=" | ">=" | "=" | "<>" | "==" | "!=" | "&&" | "||"

bool    ::= "true" | "false"

int     ::= (digit)+

decimal ::= digit+"."digit*

letter  ::= "a" | ... | "z" | "A" | ... | "Z"

digit   ::= "0" | ... | "9"

License

MIT

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].