GithubHelp home page GithubHelp logo

monads's Introduction

monads.asd

Monads in Common Lisp

This package defines a fairly trivial implementation of monads in common lisp. It relies on the ‘seq’ moacro from vip-utils to implement something very much like Haskell’s ‘do’ notation (but with extra destructuring superpowers).

Silly Example

The following uses the :list monad to return pairs of numbers where the first is double the second from a list of numbers from 1 to 20.

(in-package :monads)

(let ((numbers (loop for i from 1 to 20 collect i)))
  (with-monad :list
    a <- numbers
    b <- numbers
    (when (= a (* 2 b))
      (unit (list a b)))))

Defining a Monad

To define a monad you should provide:-

  1. #'bind method
  2. #'fmap method
  3. #'monad-return method
  4. #'check-monad-return-type method (possibly).

Defining those are sufficient to get a fully functional monad which works as above. See list.lisp or continuation.lisp for trivial examples.

The monads are ‘named’ with a keyword symbol. This works around lack of return type polymorphism in Common Lisp. I think.

monads's People

Contributors

ppymdjr avatar

Stargazers

Jorge Gomez avatar Oleg Pykhalov avatar Bruno Dias avatar

Watchers

James Cloos avatar  avatar

Forkers

jgarte

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.