Skip to content

Virtual-Insurance-Products/monads

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published