Giter Club home page Giter Club logo

fantasy-land's Introduction

Fantasy Land Specification

(aka "Algebraic JavaScript Specification")

This project specifies interoperability of common algebraic structures:

  • Functor
  • Monad

General

An algebra is a set of values, a set of operators that it is closed under and some laws it must obey.

Terminology

  1. "value" is any JavaScript value, including any which have the structures defined below.

Algebras

Functor

Functor values MUST implement map function that complies to a following rules:

  1. map(u, function(a) { return a; }) equals u
  2. map(u, function(x) { return f(g(x)); }) equals map(map(u, g), f)

map function

A value which has a functor must provide a map implementation. That takes functor value and f function:

map.define(u, function(u, f) {
  // ...
})
  1. f must be a function,

    1. If f is not a function, the behaviour of map is unspecified.
    2. f can return any value.
  2. map must return a value of the same functor

Monad

A value which satisfies the specification of a monad do not need to implement: Functor's map as it's defined by default:

map.define(Object, function(wrapped, f) {
   return flatMap(wrapped, function(unwrapped) {
      return derive(wrapped, f(unwrapped));
   });
});
  1. of(a).then(f) equals f(a)
  2. flatMap(m, function(u) { return derive(m, u) }) equals m
  3. m.then(of) equals m
  4. m.then(f).then(g) equals m.then(function(x) { return f(x).then(g); })

flatMap function

A value which is a monad must provide a flatMap implementation. The flatMap function takes m monad and f function as arguments:

flatMap(m, f)
  1. f must be a function which returns a value

    1. If f is not a function, the behaviour of flatMap is unspecified.
    2. f must return a value of the same monad
  2. flatMap must return a value of the same monad

derive function

A value which has a monad must provide derive implementation. Implementation must take source argument and value:

derive(m, a)
  1. derive must provide a value of the same monad

    1. No parts of a should be checked

fantasy-land's People

Contributors

gozala avatar puffnfresh avatar raynos 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.