diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-03-14 20:08:58 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-03-14 20:08:58 +0100 |
commit | a4a7edd487d4d2207829462d06c40578dc757337 (patch) | |
tree | 0c65527665b628b64a09d1ea001727e9a64d7da2 /control/monad/procedures.scm | |
parent | Remove empty file state-monad.scm. (diff) | |
download | scheme-monad-a4a7edd487d4d2207829462d06c40578dc757337.tar.gz scheme-monad-a4a7edd487d4d2207829462d06c40578dc757337.tar.xz |
Generilified return, monads now truly functors.
Diffstat (limited to 'control/monad/procedures.scm')
-rw-r--r-- | control/monad/procedures.scm | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/control/monad/procedures.scm b/control/monad/procedures.scm index 4be85ae..707dc0b 100644 --- a/control/monad/procedures.scm +++ b/control/monad/procedures.scm @@ -1,16 +1,27 @@ (define-module (control monad procedures) #:use-module (oop goops) #:use-module (srfi srfi-1) ; concatenate! - #:export (>> >>=)) + #:export (>> >>= return)) + +(define-generic return) +(define-method (return (a <top>)) identity) +(define-method (return (a <pair>)) list) (define-generic >>=) +(define-method (>>= (a <top>) (proc <procedure>)) + (proc a)) + (define-method (>>= (this <null>) proc) '()) (define-method (>>= (this <pair>) (proc <procedure>)) (concatenate! (map proc this))) (define-generic >>) + +(define-method (>> (a <top>) (b <top>)) + (>>= a (lambda args b))) + (define-method (>> (a <null>) (b <null>)) '()) (define-method (>> (a <pair>) (b <null>)) '()) (define-method (>> (a <null>) (b <pair>)) '()) |