diff options
author | Masaya Tojo <masaya@tojo.tokyo> | 2024-06-14 10:50:44 +0900 |
---|---|---|
committer | Masaya Tojo <masaya@tojo.tokyo> | 2024-06-14 10:50:44 +0900 |
commit | 1f60d4a7e3e4804ac68592bdbb7e9827fee1adbf (patch) | |
tree | a3f0c17b889c9f3faec7418d03f8fa19a93635df | |
parent | dee1a5f3fc8862e7356a60a387fedd254bea6434 (diff) |
Add semigroup
-rw-r--r-- | algebraic-structures.egg | 1 | ||||
-rw-r--r-- | algebraic-structures.semigroup.scm | 2 | ||||
-rw-r--r-- | tests/run.scm | 39 |
3 files changed, 33 insertions, 9 deletions
diff --git a/algebraic-structures.egg b/algebraic-structures.egg index 1c9e574..ba71745 100644 --- a/algebraic-structures.egg +++ b/algebraic-structures.egg @@ -8,6 +8,7 @@ (dependencies matchable) (test-dependencies test) (components + (extension algebraic-structures.semigroup) (extension algebraic-structures.monoid) (extension algebraic-structures.monoid.fold) (extension algebraic-structures.group) diff --git a/algebraic-structures.semigroup.scm b/algebraic-structures.semigroup.scm new file mode 100644 index 0000000..3912349 --- /dev/null +++ b/algebraic-structures.semigroup.scm @@ -0,0 +1,2 @@ +(functor ((algebraic-structures semigroup) (S (<>))) (<>) + (import S)) diff --git a/tests/run.scm b/tests/run.scm index 8d78396..6110b98 100644 --- a/tests/run.scm +++ b/tests/run.scm @@ -2,29 +2,43 @@ (test-begin "algebraic-structures") -(test-begin "monoid") +(test-begin "semigroup") -(import (algebraic-structures monoid)) +(import (algebraic-structures semigroup)) -(module (mod7 monoid) = (algebraic-structures monoid) +(module (mod7 semigroup) = (algebraic-structures semigroup) (import scheme (chicken module) (chicken base)) - (export <> unit) + (export <>) (define (<> x y) (assert (integer? x)) (assert (integer? y)) (assert (not (zero? x))) (assert (not (zero? y))) - (modulo (* x y) 7)) + (modulo (* x y) 7))) + +(import (prefix (algebraic-structures semigroup) mod7:<>)) + +(test 5 (mod7:<> 3 4)) + +(test-end "semigroup") + +(import (algebraic-structures monoid)) + +(module (mod7 monoid) = (algebraic-structures monoid) + (import scheme + (chicken module) + (chicken base)) + (reexport (mod7 semigroup)) + (export unit) (define unit 1)) (import (prefix (mod7 monoid) mod7:) (srfi 1)) -(test 5 (mod7:<> 3 4)) (test 1 mod7:unit) (test-end "monoid") @@ -95,18 +109,25 @@ (test-begin "monoid.fold") -(module (product monoid) = (algebraic-structures monoid) +(module (product semigroup) = (algebraic-structures semigroup) (import scheme (chicken base) (chicken module)) - (export <> unit) + (export <>) (define (<> x y) (assert (number? x)) (assert (not (zero? x))) (assert (number? y)) (assert (not (zero? y))) - (* x y)) + (* x y))) + +(module (product monoid) = (algebraic-structures monoid) + (import scheme + (chicken base) + (chicken module)) + (reexport (product semigroup)) + (export unit) (define unit 1)) |