aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/specification/lux/abstract/apply.lux
diff options
context:
space:
mode:
authorEduardo Julian2021-07-15 00:45:15 -0400
committerEduardo Julian2021-07-15 00:45:15 -0400
commit0abd5bd3c0e38e352e9ba38268e04e1c858ab01e (patch)
treefe0af9e70413e9fc4f3848e0642920fca501c626 /stdlib/source/specification/lux/abstract/apply.lux
parent89ca40f2f101b2b38187eab5cf905371cd47eb57 (diff)
Re-named "spec" hierarchy to "specification".
Diffstat (limited to 'stdlib/source/specification/lux/abstract/apply.lux')
-rw-r--r--stdlib/source/specification/lux/abstract/apply.lux73
1 files changed, 73 insertions, 0 deletions
diff --git a/stdlib/source/specification/lux/abstract/apply.lux b/stdlib/source/specification/lux/abstract/apply.lux
new file mode 100644
index 000000000..691e8c01c
--- /dev/null
+++ b/stdlib/source/specification/lux/abstract/apply.lux
@@ -0,0 +1,73 @@
+(.module:
+ [library
+ [lux #*
+ ["_" test (#+ Test)]
+ [abstract
+ [monad (#+ do)]]
+ [control
+ ["." function]]
+ [math
+ ["." random]
+ [number
+ ["n" nat]]]]]
+ [\\library
+ ["." / (#+ Apply)]]
+ [//
+ [functor (#+ Injection Comparison)]])
+
+(def: (identity injection comparison (^open "\."))
+ (All [f] (-> (Injection f) (Comparison f) (Apply f) Test))
+ (do {! random.monad}
+ [sample (\ ! map injection random.nat)]
+ (_.test "Identity."
+ ((comparison n.=)
+ (\apply (injection function.identity) sample)
+ sample))))
+
+(def: (homomorphism injection comparison (^open "\."))
+ (All [f] (-> (Injection f) (Comparison f) (Apply f) Test))
+ (do {! random.monad}
+ [sample random.nat
+ increase (\ ! map n.+ random.nat)]
+ (_.test "Homomorphism."
+ ((comparison n.=)
+ (\apply (injection increase) (injection sample))
+ (injection (increase sample))))))
+
+(def: (interchange injection comparison (^open "\."))
+ (All [f] (-> (Injection f) (Comparison f) (Apply f) Test))
+ (do {! random.monad}
+ [sample random.nat
+ increase (\ ! map n.+ random.nat)]
+ (_.test "Interchange."
+ ((comparison n.=)
+ (\apply (injection increase) (injection sample))
+ (\apply (injection (function (_ f) (f sample))) (injection increase))))))
+
+(def: (composition injection comparison (^open "\."))
+ (All [f] (-> (Injection f) (Comparison f) (Apply f) Test))
+ (do {! random.monad}
+ [sample random.nat
+ increase (\ ! map n.+ random.nat)
+ decrease (\ ! map n.- random.nat)]
+ (_.test "Composition."
+ ((comparison n.=)
+ (_$ \apply
+ (injection function.compose)
+ (injection increase)
+ (injection decrease)
+ (injection sample))
+ ($_ \apply
+ (injection increase)
+ (injection decrease)
+ (injection sample))))))
+
+(def: #export (spec injection comparison apply)
+ (All [f] (-> (Injection f) (Comparison f) (Apply f) Test))
+ (_.for [/.Apply]
+ ($_ _.and
+ (..identity injection comparison apply)
+ (..homomorphism injection comparison apply)
+ (..interchange injection comparison apply)
+ (..composition injection comparison apply)
+ )))