diff options
-rw-r--r-- | control/monad/procedures.scm | 33 | ||||
-rw-r--r-- | monad.scm (renamed from control/monad.scm) | 39 | ||||
-rw-r--r-- | monad/either.scm (renamed from data/either.scm) | 0 | ||||
-rw-r--r-- | monad/monoid.scm (renamed from data/monoid.scm) | 2 | ||||
-rw-r--r-- | monad/optional.scm (renamed from data/optional.scm) | 4 | ||||
-rw-r--r-- | monad/stack.scm (renamed from data/stack.scm) | 6 | ||||
-rw-r--r-- | monad/state.scm (renamed from control/monad/state.scm) | 4 | ||||
-rw-r--r-- | monad/writer.scm (renamed from data/writer.scm) | 6 |
8 files changed, 46 insertions, 48 deletions
diff --git a/control/monad/procedures.scm b/control/monad/procedures.scm deleted file mode 100644 index 707dc0b..0000000 --- a/control/monad/procedures.scm +++ /dev/null @@ -1,33 +0,0 @@ -(define-module (control monad procedures) - #:use-module (oop goops) - #:use-module (srfi srfi-1) ; concatenate! - #:export (>> >>= return)) - -(define-generic return) -(define-method (return (a <top>)) identity) -(define-method (return (a <pair>)) list) - -(define-generic >>=) - -(define-method (>>= (a <top>) (proc <procedure>)) - (proc a)) - -(define-method (>>= (this <null>) proc) '()) -(define-method (>>= (this <pair>) - (proc <procedure>)) - (concatenate! (map proc this))) - -(define-generic >>) - -(define-method (>> (a <top>) (b <top>)) - (>>= a (lambda args b))) - -(define-method (>> (a <null>) (b <null>)) '()) -(define-method (>> (a <pair>) (b <null>)) '()) -(define-method (>> (a <null>) (b <pair>)) '()) -(define-method (>> (a <pair>) (b <pair>)) - (concatenate! (map (const b) a))) - -;; bind :: Monad m => m a -> (a -> m b) -> m b -;; return :: Monad m => a -> m a -;; map :: Functor f => (a -> b) -> f a -> f b diff --git a/control/monad.scm b/monad.scm index 4b756c7..97f4af6 100644 --- a/control/monad.scm +++ b/monad.scm @@ -1,12 +1,43 @@ -(define-module (control monad) - #:use-module (control monad procedures) +(define-module (monad) #:use-module (srfi srfi-1) #:use-module (ice-9 match) #:use-module (ice-9 curried-definitions) + #:use-module (oop goops) #:replace (do) #:export (sequence mapM - fmap <$> cmap <*>) - #:re-export (>> >>= return)) + fmap <$> cmap <*> + >> >>= return)) + +(define-generic return) +(define-method (return (a <top>)) identity) +(define-method (return (a <pair>)) list) + +(define-generic >>=) + +(define-method (>>= (a <top>) (proc <procedure>)) + (proc a)) + +(define-method (>>= (this <null>) proc) '()) +(define-method (>>= (this <pair>) + (proc <procedure>)) + (concatenate! (map proc this))) + +(define-generic >>) + +(define-method (>> (a <top>) (b <top>)) + (>>= a (lambda args b))) + +(define-method (>> (a <null>) (b <null>)) '()) +(define-method (>> (a <pair>) (b <null>)) '()) +(define-method (>> (a <null>) (b <pair>)) '()) +(define-method (>> (a <pair>) (b <pair>)) + (concatenate! (map (const b) a))) + +;; bind :: Monad m => m a -> (a -> m b) -> m b +;; return :: Monad m => a -> m a +;; map :: Functor f => (a -> b) -> f a -> f b + +;;; ---------------------------------------- (define-syntax do (syntax-rules (<- let =) diff --git a/data/either.scm b/monad/either.scm index c597a60..c597a60 100644 --- a/data/either.scm +++ b/monad/either.scm diff --git a/data/monoid.scm b/monad/monoid.scm index d33557e..4b10a72 100644 --- a/data/monoid.scm +++ b/monad/monoid.scm @@ -1,5 +1,5 @@ ;;; ??? -(define-module (data monoid) +(define-module (monad monoid) #:use-module (oop goops) #:use-module (srfi srfi-1) #:export (null mappend <>)) diff --git a/data/optional.scm b/monad/optional.scm index 61543d2..1aa1e92 100644 --- a/data/optional.scm +++ b/monad/optional.scm @@ -1,7 +1,7 @@ -(define-module (data optional) +(define-module (monad optional) #:use-module (oop goops) #:use-module (ice-9 match) - #:use-module (control monad) + #:use-module (monad) #:use-module (ice-9 curried-definitions) #:export (from-just wrap-maybe nothing just diff --git a/data/stack.scm b/monad/stack.scm index d470394..8d25303 100644 --- a/data/stack.scm +++ b/monad/stack.scm @@ -1,7 +1,7 @@ -(define-module (data stack) +(define-module (monad stack) #:export (pop peek push) - #:use-module (control monad) - #:use-module (control monad state)) + #:use-module (monad) + #:use-module (monad state)) ;;; Simple stateful stack module for showing the state monad ;;; in action. These functions assume that they are in a diff --git a/control/monad/state.scm b/monad/state.scm index b5fefe3..471e756 100644 --- a/control/monad/state.scm +++ b/monad/state.scm @@ -1,7 +1,7 @@ -(define-module (control monad state) +(define-module (monad state) #:use-module (oop goops) #:use-module (ice-9 match) - #:use-module (control monad) + #:use-module (monad) #:export (return-state run-state get put modify) #:re-export (>>= >> fmap return)) diff --git a/data/writer.scm b/monad/writer.scm index bf391c2..8be72c2 100644 --- a/data/writer.scm +++ b/monad/writer.scm @@ -1,8 +1,8 @@ -(define-module (data writer) +(define-module (monad writer) #:use-module (oop goops) #:use-module (ice-9 match) - #:use-module (data monoid) - #:use-module (control monad) + #:use-module (monad monoid) ; ? + #:use-module (monad) #:export (writer return-writer)) (read-enable 'curly-infix) |