From 6269a1345996b96e2194a54c34028ab73d27a004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 16 Nov 2018 00:09:13 +0100 Subject: Add fmap instance for state monad. --- control/monad/state.scm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/control/monad/state.scm b/control/monad/state.scm index 603e387..f7190af 100644 --- a/control/monad/state.scm +++ b/control/monad/state.scm @@ -2,8 +2,9 @@ #:use-module (oop goops) #:use-module (ice-9 match) #:use-module (control monad) - #:re-export (>>= >>)) - #:export (return-state run-state get put modify)) + #:use-module (data functor) + #:export (return-state run-state get put modify) + #:re-export (>>= >> fmap)) ;; Alternative implementation of get. @@ -71,7 +72,11 @@ ((r s) (list '() (proc s))))) +(define-stateful-method ((fmap (f ) (s )) st-list) + (match ((proc s) st-list) + ((r st) + (list (f r) st)))) + (define-method (run-state (st ) init) "Exec state with init as starting state value and st." ((proc st) (list init init))) - -- cgit v1.2.3