npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pico-ml

v0.12.0

Published

A toy programming language witch is a subset of OCaml

Downloads

44

Readme

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