From be51cd8fdbcb7a71bdb451ea5c67ff93da84eb76 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 22 Jul 2017 18:26:19 -0400 Subject: - Eliminated lux/math/simple. If you want simple math, use lux/type/auto with the relevant signatures. --- stdlib/source/lux/math/simple.lux | 306 -------------------------------------- 1 file changed, 306 deletions(-) delete mode 100644 stdlib/source/lux/math/simple.lux (limited to 'stdlib/source') diff --git a/stdlib/source/lux/math/simple.lux b/stdlib/source/lux/math/simple.lux deleted file mode 100644 index 752f5a5b5..000000000 --- a/stdlib/source/lux/math/simple.lux +++ /dev/null @@ -1,306 +0,0 @@ -(;module: {#;doc "Polymorphic arithmetic operators that work with all primitive numeric types, without requiring any prefixes."} - lux - (lux (control monad - ["p" parser]) - (data text/format - [product] - (coll [list])) - [macro] - (macro [code] - ["s" syntax #+ syntax: Syntax]) - [type] - (type [check]))) - -(def: (find-type-var id env) - (-> Nat Type-Context (Lux Type)) - (case (list;find (|>. product;left (n.= id)) - (get@ #;var-bindings env)) - (#;Some [_ (#;Some type)]) - (case type - (#;Var id') - (find-type-var id' env) - - _ - (:: macro;Monad wrap type)) - - (#;Some [_ #;None]) - (macro;fail (format "Unbound type-var " (%n id))) - - #;None - (macro;fail (format "Unknown type-var " (%n id))) - )) - -(def: (resolve-type var-name) - (-> Ident (Lux Type)) - (do macro;Monad - [raw-type (macro;find-type var-name) - compiler macro;get-compiler] - (case raw-type - (#;Var id) - (find-type-var id (get@ #;type-context compiler)) - - _ - (wrap raw-type)))) - -(do-template [ ] - [(syntax: #export ( [args ($_ p;alt - (p;seq (p;alt s;symbol s;any) - (p;some s;any)) - s;end!)]) - ## {#;doc (doc (= ( +1 +2) - ## ( +1 +2)) - ## (= ( 1 2) - ## ( 1 2)) - ## (= ( 1.0 2.0) - ## ( 1.0 2.0)) - ## (= ( .1 .2) - ## ( .1 .2)))} - (case args - (+0 [(#;Left x) ys]) - (do @ - [=x (resolve-type x) - op (cond (check;checks? Nat =x) - (wrap (` )) - - (check;checks? Int =x) - (wrap (` )) - - (check;checks? Real =x) - (wrap (` )) - - (check;checks? Deg =x) - (wrap (` )) - - (macro;fail (format "No operation for types: " (%type =x))))] - (wrap (list (` ($_ (~ op) (~ (code;symbol x)) (~@ ys)))))) - - (+0 [(#;Right x) ys]) - (do @ - [g!x (macro;gensym "g!x")] - (wrap (list (` (let [(~ g!x) (~ x)] - ( (~ g!x) (~@ ys))))))) - - (+1 []) - (do @ - [=e macro;expected-type - op (cond (check;checks? (-> Nat Nat Nat) =e) - (wrap (` )) - - (check;checks? (-> Int Int Int) =e) - (wrap (` )) - - (check;checks? (-> Real Real Real) =e) - (wrap (` )) - - (check;checks? (-> Deg Deg Deg) =e) - (wrap (` )) - - (macro;fail (format "No operation for type: " (%type =e))))] - (wrap (list op))) - ))] - - [+ ;;+ n.+ i.+ r.+ d.+] - [- ;;- n.- i.- r.- d.-] - [* ;;* n.* i.* r.* d.*] - [/ ;;/ n./ i./ r./ d./] - [% ;;% n.% i.% r.% d.%] - ) - -(do-template [ ] - [(syntax: #export ( [args ($_ p;alt - (p;seq (p;alt s;symbol s;any) - (p;some s;any)) - s;end!)]) - ## {#;doc (doc (= ( +1 +2) - ## ( +1 +2)) - ## (= ( 1 2) - ## ( 1 2)) - ## (= ( 1.0 2.0) - ## ( 1.0 2.0)) - ## (= ( .1 .2) - ## ( .1 .2)))} - (case args - (+0 [(#;Left x) ys]) - (do @ - [=x (resolve-type x) - op (cond (check;checks? Nat =x) - (wrap (` )) - - (check;checks? Int =x) - (wrap (` )) - - (check;checks? Real =x) - (wrap (` )) - - (check;checks? Deg =x) - (wrap (` )) - - (macro;fail (format "No operation for types: " (%type =x))))] - (wrap (list (` ($_ (~ op) (~ (code;symbol x)) (~@ ys)))))) - - (+0 [(#;Right x) ys]) - (do @ - [g!x (macro;gensym "g!x")] - (wrap (list (` (let [(~ g!x) (~ x)] - ( (~ g!x) (~@ ys))))))) - - (+1 []) - (do @ - [=e macro;expected-type - op (cond (check;checks? (-> Nat Nat Bool) =e) - (wrap (` )) - - (check;checks? (-> Int Int Bool) =e) - (wrap (` )) - - (check;checks? (-> Real Real Bool) =e) - (wrap (` )) - - (check;checks? (-> Deg Deg Bool) =e) - (wrap (` )) - - (macro;fail (format "No operation for type: " (%type =e))))] - (wrap (list op))) - ))] - - [= ;;= n.= i.= r.= d.=] - [< ;;< n.< i.< r.< d.<] - [<= ;;<= n.<= i.<= r.<= d.<=] - [> ;;> n.> i.> r.> d.>] - [>= ;;>= n.>= i.>= r.>= d.>=] - ) - -(do-template [ ] - [(syntax: #export ( [args ($_ p;alt - (p;seq (p;alt s;symbol s;any) - (p;some s;any)) - s;end!)]) - ## {#;doc (doc (= ( +1 +2) - ## ( +1 +2)) - ## (= ( 1 2) - ## ( 1 2)))} - (case args - (+0 [(#;Left x) ys]) - (do @ - [=x (resolve-type x) - op (cond (check;checks? Nat =x) - (wrap (` )) - - (check;checks? Int =x) - (wrap (` )) - - (macro;fail (format "No operation for types: " (%type =x))))] - (wrap (list (` ($_ (~ op) (~ (code;symbol x)) (~@ ys)))))) - - (+0 [(#;Right x) ys]) - (do @ - [g!x (macro;gensym "g!x")] - (wrap (list (` (let [(~ g!x) (~ x)] - ( (~ g!x) (~@ ys))))))) - - (+1 []) - (do @ - [=e macro;expected-type - op (cond (check;checks? (-> Nat Nat Nat) =e) - (wrap (` )) - - (check;checks? (-> Int Int Int) =e) - (wrap (` )) - - (macro;fail (format "No operation for type: " (%type =e))))] - (wrap (list op))) - ))] - - [min ;;min n.min i.min] - [max ;;max n.max i.max] - ) - -(do-template [ ] - [(syntax: #export ( [args ($_ p;alt - s;symbol - s;any - s;end!)]) - ## {#;doc (doc (= ( +1 +2) - ## ( +1 +2)) - ## (= ( 1 2) - ## ( 1 2)))} - (case args - (+0 x) - (do @ - [=x (resolve-type x) - op (cond (check;checks? Nat =x) - (wrap (` )) - - (check;checks? Int =x) - (wrap (` )) - - (macro;fail (format "No operation for type: " (%type =x))))] - (wrap (list (` ((~ op) (~ (code;symbol x))))))) - - (+1 x) - (do @ - [g!x (macro;gensym "g!x")] - (wrap (list (` (let [(~ g!x) (~ x)] - ( (~ g!x))))))) - - (+2 []) - (do @ - [=e macro;expected-type - op (cond (check;checks? (-> Nat Nat) =e) - (wrap (` )) - - (check;checks? (-> Int Int) =e) - (wrap (` )) - - (macro;fail (format "No operation for type: " (%type =e))))] - (wrap (list op))) - ))] - - [inc ;;inc n.inc i.inc] - [dec ;;dec n.dec i.dec] - ) - -(do-template [ ] - [(syntax: #export ( [args ($_ p;alt - s;symbol - s;any - s;end!)]) - ## {#;doc (doc (= ( +1 +2) - ## ( +1 +2)) - ## (= ( 1 2) - ## ( 1 2)))} - (case args - (+0 x) - (do @ - [=x (resolve-type x) - op (cond (check;checks? Nat =x) - (wrap (` )) - - (check;checks? Int =x) - (wrap (` )) - - (macro;fail (format "No operation for type: " (%type =x))))] - (wrap (list (` ((~ op) (~ (code;symbol x))))))) - - (+1 x) - (do @ - [g!x (macro;gensym "g!x")] - (wrap (list (` (let [(~ g!x) (~ x)] - ( (~ g!x))))))) - - (+2 []) - (do @ - [=e macro;expected-type - op (cond (check;checks? (-> Nat Bool) =e) - (wrap (` )) - - (check;checks? (-> Int Bool) =e) - (wrap (` )) - - (macro;fail (format "No operation for type: " (%type =e))))] - (wrap (list op))) - ))] - - [even? ;;even? n.even? i.even?] - [odd? ;;odd? n.odd? i.odd?] - ) -- cgit v1.2.3