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> mHi!
#<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
_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users