Giter VIP home page Giter VIP logo

monad-fp's Introduction

Monads for FP

Pure <--- monads --> Impure monads integrates impure effects into pure FP.

  • simple evaluator
  • monad laws
  • monads application
  • recusrive descent parsers

Evaluating monads

Pure functional langauages have this advantage: all flow of data is made explicit. disadvantage : sometimes it is painfully explicit

basic evaluator for simple terms

  • exceptions
  • state
  • output

Each of the variations on the intepreter has a similar structure, which may be abstracted to yield the notion of a monad.

A monad is a triple (M, unit, >>=)

  • M[T] : type constructor
  • unit[T] : T -> M[T], which means how to wrap value to default computation
  • bind[T, S] : M[T] -> (T -> M[S]) -> M[S], which means how to sequence two computations

Monad Laws

  • left unit ::= f = b => n; bind(unit(a), f) == f(a)
  • right unit ::= bind(m, a => unit(a)) == m
  • assosiative ::= bind(m, a => bind(n, b => o)) == bind(bind(m, a => n), b => o)

Parsers

Lists

If monads encapsulate effects and lists form a monad, do lists correspond to some effect? Indeed they do, and the effect they correspond to do is choice. In short, List[A] can be regarded as offering choice of value of type A.

Parsers

Parsers are represented in a way similar to state transformers. A parser m is unambiguous if for every input x the list of possible parses m x is either empty of has exactly one item.

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.