Giter Club home page Giter Club logo

jump's Introduction

Functional Jump

This is an example implementation of a simple pure ML-like functional language with a non-standard control flow mechanism, which we can call functional jump for now.

It is a simple generalized control flow mechanism for implementing both iteration and branching. Roughly speaking, it tries to unify the following concepts:

  • pattern matching
  • ad-hoc exception introduction and handling
  • goto (yay! the considered-harmful one!)
  • related to continuations

Example

A function computing the sum of the first n integers:

let sum = fun n ->
  >> (n, 0) where
  | (0, acc) -> acc
  | (k, acc) -> >> (k-1, acc+k)
  end

Goals

Potentially, this mechanism can be useful for simplifying recursive function definitions that describe iterations, but involve complicated logic or order of execution that is painful to express in a clear way with normal recursion.

It provides seamless integration of finite-automaton-like control flow into a functional language. Kinda wondering if there is any relation to co-induction or any other fancy topics.

It seems that the correctness of labels and jumps can be statically type-checked, but I haven't proved it yet.

How to build and run

You have to install ocaml compiler and menhir parser generator. It is recommended to use OCaml package manager opam to install menhir.

make
./jump < test/sum.jump

In addition, the file "jump.vim" provides some basic syntax highlighting for Vim text editor. (Please follow/search for the official Vim instructions for installing such syntax files.)

Status

  • Practically no error reporting.
  • No documentation about this control flow mechanism.

References

  1. Edsger Dijkstra (March 1968). "Go To Statement Considered Harmful". Communications of the ACM 11 (3): 147โ€“148.

License

The software is distributed under the conditions of the BSD 3-clause license.

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.