From ca1584a5c87c2952af08c74ce80b1cb2a75a1d19 Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Thu, 13 Jun 2024 02:11:07 +0900 Subject: Rename modules from ( ... make) to () --- algebraic-structures.alternative.make.scm | 10 -------- algebraic-structures.alternative.scm | 10 ++++++++ algebraic-structures.applicative.make.scm | 28 ---------------------- algebraic-structures.applicative.scm | 28 ++++++++++++++++++++++ algebraic-structures.foldable.make.scm | 39 ------------------------------- algebraic-structures.foldable.scm | 39 +++++++++++++++++++++++++++++++ algebraic-structures.functor.make.scm | 3 --- algebraic-structures.functor.scm | 3 +++ algebraic-structures.group.make.scm | 16 ------------- algebraic-structures.group.scm | 16 +++++++++++++ algebraic-structures.monad.make.scm | 32 ------------------------- algebraic-structures.monad.scm | 32 +++++++++++++++++++++++++ algebraic-structures.monoid.fold.scm | 4 ++++ algebraic-structures.monoid.make.fold.scm | 4 ---- algebraic-structures.monoid.make.scm | 3 --- algebraic-structures.monoid.scm | 3 +++ examples/optional.scm | 12 +++++----- examples/state.scm | 12 +++++----- tests/run.scm | 34 +++++++++++++-------------- 19 files changed, 164 insertions(+), 164 deletions(-) delete mode 100644 algebraic-structures.alternative.make.scm create mode 100644 algebraic-structures.alternative.scm delete mode 100644 algebraic-structures.applicative.make.scm create mode 100644 algebraic-structures.applicative.scm delete mode 100644 algebraic-structures.foldable.make.scm create mode 100644 algebraic-structures.foldable.scm delete mode 100644 algebraic-structures.functor.make.scm create mode 100644 algebraic-structures.functor.scm delete mode 100644 algebraic-structures.group.make.scm create mode 100644 algebraic-structures.group.scm delete mode 100644 algebraic-structures.monad.make.scm create mode 100644 algebraic-structures.monad.scm create mode 100644 algebraic-structures.monoid.fold.scm delete mode 100644 algebraic-structures.monoid.make.fold.scm delete mode 100644 algebraic-structures.monoid.make.scm create mode 100644 algebraic-structures.monoid.scm diff --git a/algebraic-structures.alternative.make.scm b/algebraic-structures.alternative.make.scm deleted file mode 100644 index 29f8352..0000000 --- a/algebraic-structures.alternative.make.scm +++ /dev/null @@ -1,10 +0,0 @@ -(functor ((algebraic-structures alternative make) (A (pure map map2 alt empty))) - (pure map map2 alt empty guard) - (import (except scheme map apply) - (only (chicken base) void) - A) - - (define (guard b) - (if b - (pure (void)) - empty))) diff --git a/algebraic-structures.alternative.scm b/algebraic-structures.alternative.scm new file mode 100644 index 0000000..c397304 --- /dev/null +++ b/algebraic-structures.alternative.scm @@ -0,0 +1,10 @@ +(functor ((algebraic-structures alternative) (A (pure map map2 alt empty))) + (pure map map2 alt empty guard) + (import (except scheme map apply) + (only (chicken base) void) + A) + + (define (guard b) + (if b + (pure (void)) + empty))) diff --git a/algebraic-structures.applicative.make.scm b/algebraic-structures.applicative.make.scm deleted file mode 100644 index 10a5663..0000000 --- a/algebraic-structures.applicative.make.scm +++ /dev/null @@ -1,28 +0,0 @@ -(functor ((algebraic-structures applicative make) (A (pure map map2))) - (pure map map2 map* apply) - (import (rename scheme (map scheme:map) (apply scheme:apply)) - (only (chicken base) sub1 add1 foldl case-lambda) - A - matchable) - - (define (curry-n f n) - (let rec ((i n) - (k (lambda (args) - (scheme:apply f args)))) - (if (= i 1) - (lambda (x) (k (list x))) - (lambda (x) - (rec (sub1 i) - (lambda (args) - (k (cons x args)))))))) - - (define map* - (case-lambda - ((f x) (map f x)) - ((f x y) (map2 f x y)) - ((f x . xs) - (let ((g (curry-n f (add1 (length xs))))) - (foldl apply (apply (pure g) x) xs))))) - - (define (apply a1 a2) - (map2 (lambda (f x) (f x)) a1 a2))) diff --git a/algebraic-structures.applicative.scm b/algebraic-structures.applicative.scm new file mode 100644 index 0000000..ac3028a --- /dev/null +++ b/algebraic-structures.applicative.scm @@ -0,0 +1,28 @@ +(functor ((algebraic-structures applicative) (A (pure map map2))) + (pure map map2 map* apply) + (import (rename scheme (map scheme:map) (apply scheme:apply)) + (only (chicken base) sub1 add1 foldl case-lambda) + A + matchable) + + (define (curry-n f n) + (let rec ((i n) + (k (lambda (args) + (scheme:apply f args)))) + (if (= i 1) + (lambda (x) (k (list x))) + (lambda (x) + (rec (sub1 i) + (lambda (args) + (k (cons x args)))))))) + + (define map* + (case-lambda + ((f x) (map f x)) + ((f x y) (map2 f x y)) + ((f x . xs) + (let ((g (curry-n f (add1 (length xs))))) + (foldl apply (apply (pure g) x) xs))))) + + (define (apply a1 a2) + (map2 (lambda (f x) (f x)) a1 a2))) diff --git a/algebraic-structures.foldable.make.scm b/algebraic-structures.foldable.make.scm deleted file mode 100644 index 197eb48..0000000 --- a/algebraic-structures.foldable.make.scm +++ /dev/null @@ -1,39 +0,0 @@ -(functor ((algebraic-structures foldable make) (F (foldl foldr))) - (foldl foldr length find any every ->list) - (import (except scheme length) F - (only (chicken base) add1 call/cc)) - - (define (length xs) - (foldl (lambda (acc _) (add1 acc)) - 0 - xs)) - - (define (find p? xs) - (call/cc - (lambda (k) - (foldl (lambda (acc e) - (if (p? e) - (k e) - acc)) - #f - xs)))) - - (define (any pred xs) - (call/cc - (lambda (return) - (foldl (lambda (acc e) - (cond ((pred e) => return) - (else acc))) - #f - xs)))) - - (define (every pred xs) - (call/cc - (lambda (return) - (foldl (lambda (acc e) - (or (pred e) (return #f))) - #t - xs)))) - - (define (->list xs) - (foldr cons '() xs))) diff --git a/algebraic-structures.foldable.scm b/algebraic-structures.foldable.scm new file mode 100644 index 0000000..3ab1f6e --- /dev/null +++ b/algebraic-structures.foldable.scm @@ -0,0 +1,39 @@ +(functor ((algebraic-structures foldable) (F (foldl foldr))) + (foldl foldr length find any every ->list) + (import (except scheme length) F + (only (chicken base) add1 call/cc)) + + (define (length xs) + (foldl (lambda (acc _) (add1 acc)) + 0 + xs)) + + (define (find p? xs) + (call/cc + (lambda (k) + (foldl (lambda (acc e) + (if (p? e) + (k e) + acc)) + #f + xs)))) + + (define (any pred xs) + (call/cc + (lambda (return) + (foldl (lambda (acc e) + (cond ((pred e) => return) + (else acc))) + #f + xs)))) + + (define (every pred xs) + (call/cc + (lambda (return) + (foldl (lambda (acc e) + (or (pred e) (return #f))) + #t + xs)))) + + (define (->list xs) + (foldr cons '() xs))) diff --git a/algebraic-structures.functor.make.scm b/algebraic-structures.functor.make.scm deleted file mode 100644 index c095717..0000000 --- a/algebraic-structures.functor.make.scm +++ /dev/null @@ -1,3 +0,0 @@ -(functor ((algebraic-structures functor make) (F (map))) - (map) - (import F)) diff --git a/algebraic-structures.functor.scm b/algebraic-structures.functor.scm new file mode 100644 index 0000000..70d5496 --- /dev/null +++ b/algebraic-structures.functor.scm @@ -0,0 +1,3 @@ +(functor ((algebraic-structures functor) (F (map))) + (map) + (import F)) diff --git a/algebraic-structures.group.make.scm b/algebraic-structures.group.make.scm deleted file mode 100644 index 7568ac9..0000000 --- a/algebraic-structures.group.make.scm +++ /dev/null @@ -1,16 +0,0 @@ -(functor ((algebraic-structures group make) (M (<> unit inv))) - (<> unit inv pow) - (import M - scheme - (chicken base)) - - (define (pow x n) - (assert (exact-integer? n)) - (if (negative? n) - (pow (inv x) (- n)) - (let loop ((i n) - (acc unit)) - (if (= i 0) - acc - (loop (sub1 i) - (<> acc x))))))) diff --git a/algebraic-structures.group.scm b/algebraic-structures.group.scm new file mode 100644 index 0000000..6e38eaf --- /dev/null +++ b/algebraic-structures.group.scm @@ -0,0 +1,16 @@ +(functor ((algebraic-structures group) (M (<> unit inv))) + (<> unit inv pow) + (import M + scheme + (chicken base)) + + (define (pow x n) + (assert (exact-integer? n)) + (if (negative? n) + (pow (inv x) (- n)) + (let loop ((i n) + (acc unit)) + (if (= i 0) + acc + (loop (sub1 i) + (<> acc x))))))) diff --git a/algebraic-structures.monad.make.scm b/algebraic-structures.monad.make.scm deleted file mode 100644 index b06b908..0000000 --- a/algebraic-structures.monad.make.scm +++ /dev/null @@ -1,32 +0,0 @@ -(functor ((algebraic-structures monad make) (M (pure map map2 >>=))) - (pure map map2 >>= do) - (import (rename scheme (map scheme:map) (do scheme:do)) - M) - (import-for-syntax matchable - (chicken syntax) - (only (srfi 1) last)) - - (define-syntax do - (ir-macro-transformer - (lambda (expr inject compare) - (match expr - [(_ body ...) - (foldr (lambda (binding acc) - (match binding - [(var stx expr) - (if (and (symbol? var) - (symbol? stx) - (compare stx '<-)) - `(>>= ,expr (lambda (,var) ,acc)) - `(>>= ,binding (lambda (_) ,acc)))] - [(let-stx var =-stx expr) - (cond ((and (symbol? var) - (symbol? let-stx) (compare let-stx (inject 'let)) - (symbol? =-stx) (compare =-stx (inject '=))) - `((lambda (,var) ,acc) ,expr)) - (else - `(>>= ,binding (lambda (_) ,acc))))] - [expr - `(>>= ,expr (lambda (_) ,acc))])) - (last body) - (butlast body))]))))) diff --git a/algebraic-structures.monad.scm b/algebraic-structures.monad.scm new file mode 100644 index 0000000..fd5ff82 --- /dev/null +++ b/algebraic-structures.monad.scm @@ -0,0 +1,32 @@ +(functor ((algebraic-structures monad) (M (pure map map2 >>=))) + (pure map map2 >>= do) + (import (rename scheme (map scheme:map) (do scheme:do)) + M) + (import-for-syntax matchable + (chicken syntax) + (only (srfi 1) last)) + + (define-syntax do + (ir-macro-transformer + (lambda (expr inject compare) + (match expr + [(_ body ...) + (foldr (lambda (binding acc) + (match binding + [(var stx expr) + (if (and (symbol? var) + (symbol? stx) + (compare stx '<-)) + `(>>= ,expr (lambda (,var) ,acc)) + `(>>= ,binding (lambda (_) ,acc)))] + [(let-stx var =-stx expr) + (cond ((and (symbol? var) + (symbol? let-stx) (compare let-stx (inject 'let)) + (symbol? =-stx) (compare =-stx (inject '=))) + `((lambda (,var) ,acc) ,expr)) + (else + `(>>= ,binding (lambda (_) ,acc))))] + [expr + `(>>= ,expr (lambda (_) ,acc))])) + (last body) + (butlast body))]))))) diff --git a/algebraic-structures.monoid.fold.scm b/algebraic-structures.monoid.fold.scm new file mode 100644 index 0000000..b18c03c --- /dev/null +++ b/algebraic-structures.monoid.fold.scm @@ -0,0 +1,4 @@ +(functor ((algebraic-structures monoid fold) (M (<> unit)) (F (foldl foldr))) (fold) + (import scheme M F) + + (define (fold x) (foldl <> unit x))) diff --git a/algebraic-structures.monoid.make.fold.scm b/algebraic-structures.monoid.make.fold.scm deleted file mode 100644 index 0334ab6..0000000 --- a/algebraic-structures.monoid.make.fold.scm +++ /dev/null @@ -1,4 +0,0 @@ -(functor ((algebraic-structures monoid make fold) (M (<> unit)) (F (foldl foldr))) (fold) - (import scheme M F) - - (define (fold x) (foldl <> unit x))) diff --git a/algebraic-structures.monoid.make.scm b/algebraic-structures.monoid.make.scm deleted file mode 100644 index 58575ba..0000000 --- a/algebraic-structures.monoid.make.scm +++ /dev/null @@ -1,3 +0,0 @@ -(functor ((algebraic-structures monoid make) (F (<> unit))) - (<> unit) - (import F)) diff --git a/algebraic-structures.monoid.scm b/algebraic-structures.monoid.scm new file mode 100644 index 0000000..936d0f1 --- /dev/null +++ b/algebraic-structures.monoid.scm @@ -0,0 +1,3 @@ +(functor ((algebraic-structures monoid) (F (<> unit))) + (<> unit) + (import F)) diff --git a/examples/optional.scm b/examples/optional.scm index ff444de..a15fe16 100644 --- a/examples/optional.scm +++ b/examples/optional.scm @@ -46,13 +46,13 @@ [($ opt: x) (f x)] [($ opt:) (opt:none)]))) -(import (only (algebraic-structures functor make)) - (only (algebraic-structures applicative make)) - (only (algebraic-structures monad make))) +(import (only (algebraic-structures functor)) + (only (algebraic-structures applicative)) + (only (algebraic-structures monad))) -(module (data optional functor) = ((algebraic-structures functor make) (data optional monad base))) -(module (data optional applicative) = ((algebraic-structures applicative make) (data optional monad base))) -(module (data optional monad) = ((algebraic-structures monad make) (data optional monad base))) +(module (data optional functor) = ((algebraic-structures functor) (data optional monad base))) +(module (data optional applicative) = ((algebraic-structures applicative) (data optional monad base))) +(module (data optional monad) = ((algebraic-structures monad) (data optional monad base))) (import (prefix (data optional) opt:) (prefix (data optional functor) opt:) diff --git a/examples/state.scm b/examples/state.scm index b1aedc6..21efc1b 100644 --- a/examples/state.scm +++ b/examples/state.scm @@ -35,12 +35,12 @@ [(x* . st**) ((f x) st*)]) (cons x* st**))))) -(import (only (algebraic-structures functor make)) - (only (algebraic-structures applicative make)) - (only (algebraic-structures monad make))) -(module (data state functor) = ((algebraic-structures functor make) (data state))) -(module (data state applicative) = ((algebraic-structures applicative make) (data state))) -(module (data state monad) = ((algebraic-structures monad make) (data state))) +(import (only (algebraic-structures functor)) + (only (algebraic-structures applicative)) + (only (algebraic-structures monad))) +(module (data state functor) = ((algebraic-structures functor) (data state))) +(module (data state applicative) = ((algebraic-structures applicative) (data state))) +(module (data state monad) = ((algebraic-structures monad) (data state))) (import (prefix (data state) st:) (prefix (data state functor) st:) diff --git a/tests/run.scm b/tests/run.scm index 2a5c941..0d76cda 100644 --- a/tests/run.scm +++ b/tests/run.scm @@ -4,9 +4,9 @@ (test-begin "monoid") -(import (algebraic-structures monoid make)) +(import (algebraic-structures monoid)) -(module (mod7 monoid) = (algebraic-structures monoid make) +(module (mod7 monoid) = (algebraic-structures monoid) (import scheme (chicken module) (chicken base)) @@ -31,8 +31,8 @@ (test-begin "group") -(import (algebraic-structures group make)) -(module (mod7 group) = (algebraic-structures group make) +(import (algebraic-structures group)) +(module (mod7 group) = (algebraic-structures group) (import scheme (chicken base) (chicken module) @@ -67,9 +67,9 @@ (test-begin "foldable") -(import (algebraic-structures foldable make)) +(import (algebraic-structures foldable)) -(module (data list foldable) = (algebraic-structures foldable make) +(module (data list foldable) = (algebraic-structures foldable) (import (chicken module)) (reexport (only (chicken base) foldl foldr))) @@ -97,7 +97,7 @@ (test-begin "monoid.fold") -(module (product monoid) = (algebraic-structures monoid make) +(module (product monoid) = (algebraic-structures monoid) (import scheme (chicken base) (chicken module)) @@ -112,8 +112,8 @@ (define unit 1)) -(import (algebraic-structures monoid make fold)) -(module (product fold) = ((algebraic-structures monoid make fold) (product monoid) (data list foldable))) +(import (algebraic-structures monoid fold)) +(module (product fold) = ((algebraic-structures monoid fold) (product monoid) (data list foldable))) (import (prefix (product monoid) product:)) (import (prefix (product fold) product:)) @@ -124,8 +124,8 @@ (test-begin "functor") -(import (algebraic-structures functor make)) -(module (data list functor) = (algebraic-structures functor make) +(import (algebraic-structures functor)) +(module (data list functor) = (algebraic-structures functor) (import scheme (chicken module)) (export map)) @@ -137,8 +137,8 @@ (test-begin "applicative") -(import (algebraic-structures applicative make)) -(module (data list applicative) = (algebraic-structures applicative make) +(import (algebraic-structures applicative)) +(module (data list applicative) = (algebraic-structures applicative) (import (except scheme map) (chicken module) (srfi 1) @@ -185,8 +185,8 @@ (test-begin "monad") -(import (algebraic-structures monad make)) -(module (data list monad) = (algebraic-structures monad make) +(import (algebraic-structures monad)) +(module (data list monad) = (algebraic-structures monad) (import (except scheme map) (chicken module) (srfi 1)) @@ -215,8 +215,8 @@ (test-begin "alternative") -(import (algebraic-structures alternative make)) -(module (data list alternative) = (algebraic-structures alternative make) +(import (algebraic-structures alternative)) +(module (data list alternative) = (algebraic-structures alternative) (import (except scheme map) (chicken module) (chicken base) -- cgit v1.2.3