From f81fd718643bfbf81420d3904bfc35d44fa25ed4 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 27 Jan 2017 05:58:27 -0400 Subject: - Number no longer depends on Ord. --- stdlib/source/lux/control/number.lux | 8 +--- stdlib/source/lux/data/number.lux | 3 -- stdlib/source/lux/math/ratio.lux | 1 - stdlib/test/test/lux/data/number.lux | 92 +++++++++++++++++++----------------- 4 files changed, 50 insertions(+), 54 deletions(-) (limited to 'stdlib') diff --git a/stdlib/source/lux/control/number.lux b/stdlib/source/lux/control/number.lux index e24d61d9b..52ed7bf0f 100644 --- a/stdlib/source/lux/control/number.lux +++ b/stdlib/source/lux/control/number.lux @@ -1,14 +1,10 @@ (;module: - lux - (lux/control [ord])) + lux) ## [Signatures] (sig: #export (Number n) {#;doc "Everything that should be expected of a number type."} - - (: (ord;Ord n) - ord) - + (do-template [] [(: (-> n n n) )] [+] [-] [*] [/] [%]) diff --git a/stdlib/source/lux/data/number.lux b/stdlib/source/lux/data/number.lux index ab097e449..998b42ea8 100644 --- a/stdlib/source/lux/data/number.lux +++ b/stdlib/source/lux/data/number.lux @@ -36,7 +36,6 @@ ) (struct: #export _ (Number Nat) - (def: ord Ord) (def: + n.+) (def: - n.-) (def: * n.*) @@ -52,7 +51,6 @@ (do-template [ <+> <-> <*> <%> <=> <<> <0> <1> <-1>] [(struct: #export _ (Number ) - (def: ord ) (def: + <+>) (def: - <->) (def: * <*>) @@ -75,7 +73,6 @@ ) (struct: #export _ (Number Deg) - (def: ord Ord) (def: + d.+) (def: - d.-) (def: * d.*) diff --git a/stdlib/source/lux/math/ratio.lux b/stdlib/source/lux/math/ratio.lux index 5d23f6961..fb86b1fed 100644 --- a/stdlib/source/lux/math/ratio.lux +++ b/stdlib/source/lux/math/ratio.lux @@ -109,7 +109,6 @@ (def: >= q.>=)) (struct: #export _ (Number Ratio) - (def: ord Ord) (def: + q.+) (def: - q.-) (def: * q.*) diff --git a/stdlib/test/test/lux/data/number.lux b/stdlib/test/test/lux/data/number.lux index f2645cd2e..6f296a628 100644 --- a/stdlib/test/test/lux/data/number.lux +++ b/stdlib/test/test/lux/data/number.lux @@ -21,13 +21,14 @@ ["Nat" R;nat Eq Ord] ["Int" R;int Eq Ord] ["Real" R;real Eq Ord] - ["Deg" R;deg Eq Ord] + ["Deg" R;deg Eq Ord] ) -(do-template [category rand-gen ] +(do-template [category rand-gen ] [(test: (format "[" category "] " "Number") [x rand-gen - #let [(^open) ]] + #let [(^open) + (^open) ]] (assert "" (and (>= x (abs x)) ## abs(0.0) == 0.0 && negate(abs(0.0)) == -0.0 (or (Text/= "Real" category) @@ -39,15 +40,16 @@ (abs x)))))))] ## ["Nat" R;nat Number] - ["Int" R;int Number] - ["Real" R;real Number] - ["Deg" R;deg Number] + ["Int" R;int Number Ord] + ["Real" R;real Number Ord] + ["Deg" R;deg Number Ord] ) -(do-template [category rand-gen ] +(do-template [category rand-gen ] [(test: (format "[" category "] " "Enum") [x rand-gen] - (assert "" (let [(^open) ] + (assert "" (let [(^open) + (^open) ] (and (> x (:: succ x)) (< x @@ -59,53 +61,55 @@ (|> x (:: succ) (:: pred))) ))))] - ["Nat" R;nat Enum Number] - ["Int" R;int Enum Number] + ["Nat" R;nat Enum Number Ord] + ["Int" R;int Enum Number Ord] ) -(do-template [category rand-gen ] +(do-template [category rand-gen ] [(test: (format "[" category "] " "Interval") [x (|> rand-gen (R;filter )) - #let [(^open) ]] + #let [(^open) + (^open) ]] (assert "" (and (<= x (:: bottom)) (>= x (:: top)))))] - ["Nat" R;nat Number Interval (lambda [_] true)] - ["Int" R;int Number Interval (lambda [_] true)] + ["Nat" R;nat Number Ord Interval (lambda [_] true)] + ["Int" R;int Number Ord Interval (lambda [_] true)] ## Both min and max values will be positive (thus, greater than zero) - ["Real" R;real Number Interval (r.> 0.0)] - ["Deg" R;deg Number Interval (lambda [_] true)] + ["Real" R;real Number Ord Interval (r.> 0.0)] + ["Deg" R;deg Number Ord Interval (lambda [_] true)] ) -(do-template [category rand-gen ] +(do-template [category rand-gen ] [(test: (format "[" category "] " "Monoid") [x (|> rand-gen (:: @ map (|>. (:: abs) )) (R;filter )) #let [(^open) + (^open) (^open) ]] (assert "Appending to unit doesn't change the value." (and (= x (append unit x)) (= x (append x unit)) (= unit (append unit unit)))))] - ["Nat/Add" R;nat Number Add@Monoid (n.% +1000) (lambda [_] true)] - ["Nat/Mul" R;nat Number Mul@Monoid (n.% +1000) (lambda [_] true)] - ["Nat/Min" R;nat Number Min@Monoid (n.% +1000) (lambda [_] true)] - ["Nat/Max" R;nat Number Max@Monoid (n.% +1000) (lambda [_] true)] - ["Int/Add" R;int Number Add@Monoid (i.% 1000) (lambda [_] true)] - ["Int/Mul" R;int Number Mul@Monoid (i.% 1000) (lambda [_] true)] - ["Int/Min" R;int Number Min@Monoid (i.% 1000) (lambda [_] true)] - ["Int/Max" R;int Number Max@Monoid (i.% 1000) (lambda [_] true)] - ["Real/Add" R;real Number Add@Monoid (r.% 1000.0) (r.> 0.0)] - ["Real/Mul" R;real Number Mul@Monoid (r.% 1000.0) (r.> 0.0)] - ["Real/Min" R;real Number Min@Monoid (r.% 1000.0) (r.> 0.0)] - ["Real/Max" R;real Number Max@Monoid (r.% 1000.0) (r.> 0.0)] - ["Deg/Add" R;deg Number Add@Monoid (d.% .125) (lambda [_] true)] - ## ["Deg/Mul" R;deg Number Mul@Monoid (d.% .125) (lambda [_] true)] - ["Deg/Min" R;deg Number Min@Monoid (d.% .125) (lambda [_] true)] - ["Deg/Max" R;deg Number Max@Monoid (d.% .125) (lambda [_] true)] + ["Nat/Add" R;nat Number Ord Add@Monoid (n.% +1000) (lambda [_] true)] + ["Nat/Mul" R;nat Number Ord Mul@Monoid (n.% +1000) (lambda [_] true)] + ["Nat/Min" R;nat Number Ord Min@Monoid (n.% +1000) (lambda [_] true)] + ["Nat/Max" R;nat Number Ord Max@Monoid (n.% +1000) (lambda [_] true)] + ["Int/Add" R;int Number Ord Add@Monoid (i.% 1000) (lambda [_] true)] + ["Int/Mul" R;int Number Ord Mul@Monoid (i.% 1000) (lambda [_] true)] + ["Int/Min" R;int Number Ord Min@Monoid (i.% 1000) (lambda [_] true)] + ["Int/Max" R;int Number Ord Max@Monoid (i.% 1000) (lambda [_] true)] + ["Real/Add" R;real Number Ord Add@Monoid (r.% 1000.0) (r.> 0.0)] + ["Real/Mul" R;real Number Ord Mul@Monoid (r.% 1000.0) (r.> 0.0)] + ["Real/Min" R;real Number Ord Min@Monoid (r.% 1000.0) (r.> 0.0)] + ["Real/Max" R;real Number Ord Max@Monoid (r.% 1000.0) (r.> 0.0)] + ["Deg/Add" R;deg Number Ord Add@Monoid (d.% .125) (lambda [_] true)] + ## ["Deg/Mul" R;deg Number Ord Mul@Monoid (d.% .125) (lambda [_] true)] + ["Deg/Min" R;deg Number Ord Min@Monoid (d.% .125) (lambda [_] true)] + ["Deg/Max" R;deg Number Ord Max@Monoid (d.% .125) (lambda [_] true)] ) -(do-template [ ] +(do-template [ ] [(test: (format "[" "] " "Codec") [x ] (assert "Can encode/decode values." @@ -113,18 +117,18 @@ (:: encode) (:: decode) (case> (#;Right x') - (:: = x x') + (:: = x x') (#;Left _) false))))] - ["Nat" R;nat Number Codec] - ["Int" R;int Number Codec] - ["Real" R;real Number Codec] - ["Deg" R;deg Number Codec] + ["Nat" R;nat Eq Codec] + ["Int" R;int Eq Codec] + ["Real" R;real Eq Codec] + ["Deg" R;deg Eq Codec] ) -(do-template [ ] +(do-template [ ] [(test: (format "[" "] " "Alternative formats") [x ] (assert "Can encode/decode values." @@ -132,12 +136,12 @@ (:: encode) (:: decode) (case> (#;Right x') - (:: = x x') + (:: = x x') (#;Left _) false))))] - ["Nat/Binary" R;nat Number Binary@Codec] - ["Nat/Octal" R;nat Number Octal@Codec] - ["Nat/Hex" R;nat Number Hex@Codec] + ["Nat/Binary" R;nat Eq Binary@Codec] + ["Nat/Octal" R;nat Eq Octal@Codec] + ["Nat/Hex" R;nat Eq Hex@Codec] ) -- cgit v1.2.3