-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: - Contextual does not have any contexts for monoids, despite the fundamental nature of monoids. Solution: - Make a context class for monoid operators. - Derive monoid operators from monad-plus operators.
- Loading branch information
Showing
5 changed files
with
129 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
(in-package :cl-user) | ||
|
||
(defpackage :contextual-monoid-test | ||
(:use :cl :5am :contextual) | ||
(:shadowing-import-from :5am :fail) | ||
(:export #:run-all-tests!)) | ||
|
||
(in-package :contextual-monoid-test) | ||
|
||
(defun run-all-tests! () | ||
(run! 'monoid)) | ||
|
||
(def-suite monoid) | ||
|
||
(in-suite monoid) | ||
|
||
(test placeholder | ||
(is (= (+ 1 2) 3))) | ||
|
||
|
||
(defun make-list-monoid-context () | ||
(make-instance 'monoid-operators | ||
:mempty (lambda () nil) | ||
:mappend #'append)) | ||
|
||
|
||
(test monoid-context | ||
(let ((context (make-list-monoid-context))) | ||
(is (equal nil (ctx-run context (mempty)))) | ||
(let ((xs '(a b)) | ||
(ys '(c d))) | ||
(is (equal xs (ctx-run context (mappend xs (mempty))))) | ||
(is (equal ys (ctx-run context (mappend (mempty) ys)))) | ||
(is (equal (append xs ys) (ctx-run context (mappend xs ys))))))) | ||
|
||
|
||
(defun make-addition-monoid-context () | ||
(make-instance 'monoid-operators | ||
:mempty (lambda () 0) | ||
:mappend (lambda (x y) (+ x y)))) | ||
|
||
(test addition-monoid-context | ||
(let ((context (make-addition-monoid-context))) | ||
(let ((x 3) | ||
(y 4)) | ||
(is (= x (ctx-run context (mappend x (mempty))))) | ||
(is (= y (ctx-run context (mappend (mempty) y)))) | ||
(is (= (+ x y) (ctx-run context (mappend x y))))))) |