diff options
author | Eduardo Julian | 2018-07-07 14:43:10 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-07-07 14:43:10 -0400 |
commit | 0ebe340ec7231eb6bdaa4caebe5680a4f5737a16 (patch) | |
tree | 36da231be79f93ae55eda1ba2bd77bab5d4f556c /stdlib/source | |
parent | b6ef43d722d60bb82f939025f239ff7a8f160011 (diff) |
- Implemented ":share" macro for easier type-sharing when casting.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/lang/type.lux | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/stdlib/source/lux/lang/type.lux b/stdlib/source/lux/lang/type.lux index 96ea1a9b0..793d1c8be 100644 --- a/stdlib/source/lux/lang/type.lux +++ b/stdlib/source/lux/lang/type.lux @@ -10,7 +10,7 @@ (coll [list #+ "list/" Functor<List> Monoid<List> Fold<List>])) [macro] (macro [code] - ["s" syntax #+ syntax:]) + ["s" syntax #+ Syntax syntax:]) )) ## [Utils] @@ -351,7 +351,11 @@ (wrap (list (` (.let [(~ g!value) (~ valueC)] (..:log! (~ g!value))))))))) -(syntax: #export (:cast {type-vars (s.tuple (p.some s.local-symbol))} +(def: type-parameters + (Syntax (List Text)) + (s.tuple (p.some s.local-symbol))) + +(syntax: #export (:cast {type-vars type-parameters} input output {value (p.maybe s.any)}) @@ -364,3 +368,22 @@ (#.Some value) (wrap (list (` ((~ casterC) (~ value)))))))) + +(type: Typed + {#type Code + #expression Code}) + +(def: typed + (Syntax Typed) + (s.record (p.seq s.any s.any))) + +(syntax: #export (:share {type-vars type-parameters} + {exemplar typed} + {computation typed}) + (macro.with-gensyms [g!_] + (let [shareC (` (: (All [(~+ (list/map code.local-symbol type-vars))] + (-> (~ (get@ #type exemplar)) + (~ (get@ #type computation)))) + (.function ((~ g!_) (~ g!_)) + (:assume (~ (get@ #expression computation))))))] + (wrap (list (` ((~ shareC) (~ (get@ #expression exemplar))))))))) |