aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lux-mode/lux-mode.el2
-rw-r--r--stdlib/source/lux/lang/type.lux27
2 files changed, 26 insertions, 3 deletions
diff --git a/lux-mode/lux-mode.el b/lux-mode/lux-mode.el
index 6e2a684a4..9961dd7ca 100644
--- a/lux-mode/lux-mode.el
+++ b/lux-mode/lux-mode.el
@@ -225,7 +225,7 @@ Called by `imenu--generic-function'."
"abstract:"
"unit:" "scale:"
"import:"
- ":" ":coerce" ":assume" ":cast" ":abstraction" ":representation" "^:representation"
+ ":" ":coerce" ":assume" ":cast" ":share" ":abstraction" ":representation" "^:representation"
"function" "case" "undefined" "ident-for" "static"
"and" "or"
"char"
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)))))))))