From b491768c9377f474c130b4b27b893ae9504929ac Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 2 Jan 2019 17:50:31 -0800 Subject: Add example for state transformer monad. --- monads.lisp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'monads.lisp') diff --git a/monads.lisp b/monads.lisp index 8586f5b..0bda2ac 100644 --- a/monads.lisp +++ b/monads.lisp @@ -234,6 +234,19 @@ ;;; State transformer monad, with operations expressed using comprehensions ;;; over the identity monad, featuring multiple-value binding. ;;; +;;; Example: +;;; +;;; (let ((transformer (state-xform-comp (list x y z) +;;; (x (lambda (state) +;;; (values `(:stage x ,state) (1+ state)))) +;;; (y (lambda (state) +;;; (values `(:stage y ,state) (+ 10 state)))) +;;; (z (lambda (state) +;;; (values `(:stage z ,state) nil)))))) +;;; (funcall transformer 42)) +;;; +;;; -> ((:STAGE X 42) (:STAGE Y 43) (:STAGE Z 53)) +;;; (define-monad state-xform-monad :comprehension state-xform-comp :map ((f) -- cgit v1.2.3