chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] [ANN] Monad Egg


From: Daniel Leslie
Subject: [Chicken-users] [ANN] Monad Egg
Date: Fri, 13 Apr 2012 11:43:04 -0700

I have written a small egg to ease the usage of lazily-evaluated monads.

For example, after defining the identity monad:

 (define-monad
   <id>
   (lambda (a) a)
   (lambda (a f) (f a)))
We can bind a chain of methods upon an initial value using it:

(doto-using <id> (+ 0 1)
  (lambda (x) (+ x 1))
  (lambda (y) (+ y 2)))
Or, alternatively, we can be explicit:

(using <id>
  (>>= (>>= (return (+ 0 1)) 
            (lambda (x) (+ x 1)))
       (lambda (y) (+ y 2))))
A short demo showing the behaviour:

#;1> (use monad)
#;2> (define m (doto-using <id> 1 (lambda (x) (display "Hi!\n") (+ x 1))))
#;3> m
Hi!
#<id> 2
#;4> m
#<id> 2
#;5> (define (m2 y) (doto-using <id> y (lambda (x) (display "Hi!\n") (+ x 1))))
#;6> (m2 1)
Hi!
#<id> 2
#;7> (m2 1)
Hi!
#<id> 2

The wiki has a fair amount of examples and documentation:
http://wiki.call-cc.org/eggref/4/monad

And the repository is on GitHub:
https://github.com/dleslie/monad-egg

Please have a look at the wiki for a more thorough introduction and comments.

Thanks for Chicken!
-Dan

reply via email to

[Prev in Thread] Current Thread [Next in Thread]