From e650a80856edc1d1df1f163c3f84082455717fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 18 Mar 2019 18:43:51 +0100 Subject: Compleately redid file structure. --- monad/either.scm | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 monad/either.scm (limited to 'monad/either.scm') 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 () + (slot #:init-keyword #:slot) + (dir #:init-keyword #:dir #:init-value 'left)) + +(define (left val) + "Error values" + (make #:slot val #:dir 'left)) + +(define (right val) + "Good values" + (make #:slot val #:dir 'right)) + +(define-method (write (this ) port) + (format port "[~a ~s]" + (slot-ref this 'dir) + (slot-ref this 'slot))) + +(define-method (>>= (this ) + (proc )) + (case (slot-ref this 'dir) + ((left) this) + ((right) (match this (($ slot) (proc slot)))))) + +(define return-either right) -- cgit v1.2.3