diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-03-18 18:43:51 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-03-18 18:43:51 +0100 |
commit | e650a80856edc1d1df1f163c3f84082455717fa0 (patch) | |
tree | 4848ad975d95f5765980980d0e10ed0752e553f9 /monad/either.scm | |
parent | Assorted comments and cleanup. (diff) | |
download | scheme-monad-e650a80856edc1d1df1f163c3f84082455717fa0.tar.gz scheme-monad-e650a80856edc1d1df1f163c3f84082455717fa0.tar.xz |
Compleately redid file structure.
Diffstat (limited to 'monad/either.scm')
-rw-r--r-- | monad/either.scm | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/monad/either.scm b/monad/either.scm new file mode 100644 index 0000000..c597a60 --- /dev/null +++ b/monad/either.scm @@ -0,0 +1,30 @@ +;;; TODO UNFINISHED + +(define-module (data either) + #:use-module (oop goops) + #:use-module (ice-9 match)) + +(define-class <either> () + (slot #:init-keyword #:slot) + (dir #:init-keyword #:dir #:init-value 'left)) + +(define (left val) + "Error values" + (make <either> #:slot val #:dir 'left)) + +(define (right val) + "Good values" + (make <either> #:slot val #:dir 'right)) + +(define-method (write (this <either>) port) + (format port "[~a ~s]" + (slot-ref this 'dir) + (slot-ref this 'slot))) + +(define-method (>>= (this <either>) + (proc <procedure>)) + (case (slot-ref this 'dir) + ((left) this) + ((right) (match this (($ <either> slot) (proc slot)))))) + +(define return-either right) |