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/monoid.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/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>)) "") |