diff options
Diffstat (limited to 'monad/monoid.scm')
-rw-r--r-- | monad/monoid.scm | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/monad/monoid.scm b/monad/monoid.scm new file mode 100644 index 0000000..4b10a72 --- /dev/null +++ b/monad/monoid.scm @@ -0,0 +1,26 @@ +;;; ??? +(define-module (monad monoid) + #:use-module (oop goops) + #:use-module (srfi srfi-1) + #:export (null mappend <>)) + +(define-generic null) +(define-generic mappend) + +(define (<> . args) + (fold mappend (null (car args)) (reverse args))) + +;;; Lists + +(define-method (mappend (a <pair>) (b <pair>)) + (append a b)) +(define-method (mappend (a <pair>) (b <null>)) a) +(define-method (mappend (a <null>) (b <pair>)) b) +(define-method (mappend (a <null>) (b <null>)) '()) +(define-method (null (a <pair>)) '()) +(define-method (null (a <null>)) '()) + +;;; Strings +(define-method (mappend (a <string>) (b <string>)) + (string-append a b)) +(define-method (null (a <string>)) "") |