Giter Site home page Giter Site logo

rootmos / silly-ml Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 1.0 231 KB

A small ML-like, type-checked, interpreted or x86-64 compiled, language created because it's weekend

Makefile 1.32% OCaml 82.17% Standard ML 1.02% C 4.14% Assembly 10.33% Shell 1.01%
functional-language experimental silly ocaml compiler x86-64

silly-ml's Introduction

silly-ml

Build Status

silly-ml (aka vacation-ml) is a:

  • small ML-like, type-checked language,
  • interpreted in a REPL or compiled to x86-64 assembly (with garbage getting both marked and sweeped),
  • created because it's weekend and because I haven't written one before,
  • coded in OCaml and inspired by OCaml.

Disclaimer: the silly prefix indicates that this is a hobby project with no other purpose than to learn and explore and it should definently be interpreted as an homage to its big brothers.

Usage

Simplest way to try it out is by using Docker:

docker run -it rootmos/silly-ml

Examples

Here's an example session from the REPL:

> 7;;
7: int
> type foo = A | B of int;;
> A;;
A: foo
> B 7;;
B 7: foo
> let f x = match x with A -> 0 | B i -> i;;
> f;;
<fun>: foo -> int
> f A;;
0: int
> f (B 3);;
3: int
> type bar = C of foo;;
> C A;;
C A: bar
> f (C A);;
typed error: unification failed
> ((), 7);;
((), 7): (unit, int)
> 3 * (7 - (1 + 2));;
12: int
> let x = 7;;
> print_int x;; print_newline ();;
7
(): unit
> let f x y = x + y;;
> f;;
<fun>: int -> int -> int
> let g = f 1;;
> g;;
<fun>: int -> int
> let h = f 2;;
> h;;
<fun>: int -> int
> g 2;;
3: int
> h 2;;
4: int
> let sum n = let rec go acc i = match i with 0 -> acc | _ -> go (acc + i) (i - 1) in go 0 n;;
> sum;;
<fun>: int -> int
> sum 6;;
21: int
> let rec fib n = match n with 0 -> 0 | 1 -> 1 | n -> (fib (n - 1)) + (fib (n - 2));;
> fib 5;;
5: int
> fib 6;;
8: int
>

silly-ml's People

Contributors

rootmos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

iohub

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.