From 8a629bbbb0bd4950fb0f3c6d14c1a9a0ba057174 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 2 Mar 2019 21:09:39 -0400 Subject: Added the capacity to extract type-information from values to create new types based on that. --- lux-mode/lux-mode.el | 2 +- stdlib/source/lux/control/thread.lux | 2 +- stdlib/source/lux/tool/compiler/meta/archive.lux | 2 +- stdlib/source/lux/type.lux | 9 +++++++++ stdlib/source/test/lux/type.lux | 10 ++++++++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lux-mode/lux-mode.el b/lux-mode/lux-mode.el index 53aecac83..f43034057 100644 --- a/lux-mode/lux-mode.el +++ b/lux-mode/lux-mode.el @@ -245,7 +245,7 @@ Called by `imenu--generic-function'." (control//contract (altRE "pre" "post")) ;; Type (type//syntax (altRE "|" "&" "->" "All" "Ex" "Rec" "primitive" "\\$" "type")) - (type//checking (altRE ":" ":coerce" ":~" ":assume" ":of" ":cast" ":share")) + (type//checking (altRE ":" ":coerce" ":~" ":assume" ":of" ":cast" ":share" ":extract")) (type//abstract (altRE "abstract:" ":abstraction" ":representation" ":transmutation" "\\^:representation")) (type//unit (altRE "unit:" "scale:")) (type//poly (altRE "poly:" "derived:")) diff --git a/stdlib/source/lux/control/thread.lux b/stdlib/source/lux/control/thread.lux index b83acabc9..c4625d6f5 100644 --- a/stdlib/source/lux/control/thread.lux +++ b/stdlib/source/lux/control/thread.lux @@ -7,7 +7,7 @@ [data [collection ["." array (#+ Array)]]] - [type (#+ :share) + [type abstract] [tool [compiler diff --git a/stdlib/source/lux/tool/compiler/meta/archive.lux b/stdlib/source/lux/tool/compiler/meta/archive.lux index e34edf0d4..eb9761ab9 100644 --- a/stdlib/source/lux/tool/compiler/meta/archive.lux +++ b/stdlib/source/lux/tool/compiler/meta/archive.lux @@ -11,7 +11,7 @@ format] [collection ["." dictionary (#+ Dictionary)]]] - [type (#+ :share) + [type abstract] [world [file (#+ File)]]] diff --git a/stdlib/source/lux/type.lux b/stdlib/source/lux/type.lux index 8d0dcad7d..a760180c5 100644 --- a/stdlib/source/lux/type.lux +++ b/stdlib/source/lux/type.lux @@ -390,3 +390,12 @@ ## TODO: this should use : instead of :assume (:assume (~ (get@ #expression computation))))))] (wrap (list (` ((~ shareC) (~ (get@ #expression exemplar))))))))) + +(syntax: #export (:extract {type-vars type-parameters} + {exemplar typed} + {extraction s.any}) + (wrap (list (` (:of (:share [(~+ (list/map code.local-identifier type-vars))] + {(~ (get@ #type exemplar)) + (~ (get@ #expression exemplar))} + {(~ extraction) + (:assume [])})))))) diff --git a/stdlib/source/test/lux/type.lux b/stdlib/source/test/lux/type.lux index b4796911a..c7daced97 100644 --- a/stdlib/source/test/lux/type.lux +++ b/stdlib/source/test/lux/type.lux @@ -166,3 +166,13 @@ ($_ seq ))))) + +(def: extraction + Test + (_.test "Can extract types." + (let [example (: (Maybe Nat) + #.Nonae)] + (type/= (type (List Nat)) + (:extract [a] + {(Maybe a) example} + (List a)))))) -- cgit v1.2.3