Giter Site home page Giter Site logo

miniml's Introduction

MiniML—A tiny functional language

Installation

Needs a C++11 compiler, lemon, and ragel to build. (The release contains pre-made versions of the output files.) Then make should Just Work (tested with GCC 4.9 on Debian and Xcode's version of clang on OS X).

Quick language guide

  • Has types int, bool, string, tuples (written (type₁, type₂, ...), and (higher-order) functions (written type₁ -> type₂).

  • Operators: <-> || && < <= > >= == != + - * / with what is hopefully the obvious precedence.

    • <-> is "iff", i.e. equality on booleans, with the lowest precedence. Writing this, I just realised == doesn't work on strings, only ints. Sorry about that.
  • Other expressions:

    • if branch then_case else_case
    • fn (x: type) => expr
    • expr: type (type ascription, though not actually useful…)
    • expr₁; expr₂ (sequencing)
    • (expr₁, expr₂, ...) (tuples, also ())
    • tuple.0, tuple.1, etc (0-based projection)
      • I don't mean to say it needs to be a tuple literal, just something of some tuple type with enough elements.
  • REPL inputs terminated with ;;.

  • Declarations:

    val x: type = def       // type optional
    val rec x: type = def   // recursive; type not optional
    fun x (y: type₁) (...): type₂ = def
        // abbreviation for:
        // val rec x: type₁ -> … -> type₂ =
        //     fn (y: type₁) => ... => def
    
  • Builtins (defined in src/init_env.cxx for magic functions or prelude.mml for nonmagic ones):

    // magic:
    print: string -> ()
    app: string -> string -> string
    string_int: int -> string
    newline: () -> ()
    use: string -> ()
    // in prelude:
    println: string -> ()
    print_int: int -> ()
    even, odd: int -> bool
    

    Since use needs a reference to the environment, it's defined in Repl's constructor instead (src/repl.cxx).

  • “Modules” (well, files) have syntax name => decl₁ decl₂ .... Note that ;; isn't used in files, only interactively.

  • As you probably notced by now, comments are of the // variety.

Notes

  • GCC doesn't check exhaustiveness of switch, which is what the #ifdef __GNUC__ business is all about.
  • #pragma GCC diagnostic is understood by Clang too.
  • If something seems redundant (say, non-builtin type names), it probably is. There was going to be a lot more to this but I ran out of time.

miniml's People

Contributors

andy-morris avatar

Watchers

 avatar  avatar

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.