aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2019-03-02 21:09:39 -0400
committerEduardo Julian2019-03-02 21:09:39 -0400
commit8a629bbbb0bd4950fb0f3c6d14c1a9a0ba057174 (patch)
tree7d0de954b940609660b061c6eb5155b940ba771b
parent0b6be3e4022acfa4650f09f53b9aa5a5e7818cf7 (diff)
Added the capacity to extract type-information from values to create new types based on that.
-rw-r--r--lux-mode/lux-mode.el2
-rw-r--r--stdlib/source/lux/control/thread.lux2
-rw-r--r--stdlib/source/lux/tool/compiler/meta/archive.lux2
-rw-r--r--stdlib/source/lux/type.lux9
-rw-r--r--stdlib/source/test/lux/type.lux10
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
<quant-tests>
)))))
+
+(def: extraction
+ Test
+ (_.test "Can extract types."
+ (let [example (: (Maybe Nat)
+ #.Nonae)]
+ (type/= (type (List Nat))
+ (:extract [a]
+ {(Maybe a) example}
+ (List a))))))