aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/specification/lux/abstract/functor/contravariant.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/specification/lux/abstract/functor/contravariant.lux')
-rw-r--r--stdlib/source/specification/lux/abstract/functor/contravariant.lux31
1 files changed, 31 insertions, 0 deletions
diff --git a/stdlib/source/specification/lux/abstract/functor/contravariant.lux b/stdlib/source/specification/lux/abstract/functor/contravariant.lux
new file mode 100644
index 000000000..cba839e94
--- /dev/null
+++ b/stdlib/source/specification/lux/abstract/functor/contravariant.lux
@@ -0,0 +1,31 @@
+(.module:
+ [library
+ [lux #*
+ ["_" test (#+ Test)]
+ [abstract
+ [equivalence (#+ Equivalence)]
+ [monad (#+ do)]]
+ [control
+ ["." function]]
+ [math
+ ["." random]
+ [number
+ ["n" nat]]]]]
+ [\\library
+ ["." / (#+ Functor)]])
+
+(def: (identity equivalence value (^open "@//."))
+ (All [f a] (-> (Equivalence (f a)) (f a) (Functor f) Test))
+ (_.test "Law of identity."
+ (equivalence
+ (@//map function.identity value)
+ value)))
+
+(def: #export (spec equivalence value functor)
+ (All [f a] (-> (Equivalence (f a)) (f a) (Functor f) Test))
+ (do random.monad
+ [sample random.nat]
+ (<| (_.for [/.Functor])
+ ($_ _.and
+ (..identity equivalence value functor)
+ ))))