aboutsummaryrefslogtreecommitdiff
path: root/source/lux/control/ord.lux
diff options
context:
space:
mode:
Diffstat (limited to 'source/lux/control/ord.lux')
-rw-r--r--source/lux/control/ord.lux41
1 files changed, 41 insertions, 0 deletions
diff --git a/source/lux/control/ord.lux b/source/lux/control/ord.lux
new file mode 100644
index 000000000..cb77e7042
--- /dev/null
+++ b/source/lux/control/ord.lux
@@ -0,0 +1,41 @@
+## Copyright (c) Eduardo Julian. All rights reserved.
+## This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+## If a copy of the MPL was not distributed with this file,
+## You can obtain one at http://mozilla.org/MPL/2.0/.
+
+(;import lux
+ (../eq #as E))
+
+## [Signatures]
+(defsig #export (Ord a)
+ (: (E;Eq a)
+ _eq)
+ (do-template [<name>]
+ [(: (-> a a Bool) <name>)]
+
+ [<] [<=] [>] [>=]))
+
+## [Constructors]
+(def #export (ord$ eq < >)
+ (All [a]
+ (-> (E;Eq a) (-> a a Bool) (-> a a Bool) (Ord a)))
+ (struct
+ (def _eq eq)
+ (def < <)
+ (def (<= x y)
+ (or (< x y)
+ (:: eq (= x y))))
+ (def > >)
+ (def (>= x y)
+ (or (> x y)
+ (:: eq (= x y))))))
+
+## [Functions]
+(do-template [<name> <op>]
+ [(def #export (<name> ord x y)
+ (All [a]
+ (-> (Ord a) a a a))
+ (if (:: ord (<op> x y)) x y))]
+
+ [max >]
+ [min <])