From 0ebe340ec7231eb6bdaa4caebe5680a4f5737a16 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 7 Jul 2018 14:43:10 -0400 Subject: - Implemented ":share" macro for easier type-sharing when casting. --- stdlib/source/lux/lang/type.lux | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'stdlib') 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 Monoid Fold])) [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))))))))) -- cgit v1.2.3