blob: d6e0f7383037122ac5e86f6430673201cded4e66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
(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)
|