summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2017-07-01 14:43:21 -0700
committerOri Bernstein <ori@eigenstate.org>2017-07-03 23:27:02 -0700
commitca10a1ec838b7d468a2b43894af659c111a0e9b1 (patch)
tree16601ac01a6f644015188db074e1c2b69bdc5789 /test
parentddb327c92ebe3f96c5c816ec61996440551de401 (diff)
downloadmc-ca10a1ec838b7d468a2b43894af659c111a0e9b1.tar.gz
Add impl(type, name) to retrieve a particular implementation of a trait decl
This avoids having to create a temporary variable when you know what implementation your want for a generic constant or function with generic return value. Re-use the impl keyword for this expression to avoid invalidating existing programs.
Diffstat (limited to 'test')
-rw-r--r--test/implexpr.myr18
-rw-r--r--test/tests2
2 files changed, 19 insertions, 1 deletions
diff --git a/test/implexpr.myr b/test/implexpr.myr
new file mode 100644
index 0000000..d449a2a
--- /dev/null
+++ b/test/implexpr.myr
@@ -0,0 +1,18 @@
+use std
+
+trait favorite @a =
+ Fav : @a
+;;
+impl favorite int =
+ Fav = 12
+;;
+impl favorite char =
+ Fav = 'z'
+;;
+impl favorite byte[:] =
+ Fav = "hello"
+;;
+
+const main = {
+ std.put("{},{},{}\n", impl(Fav, int), impl(Fav, char), impl(Fav, byte[:]))
+}
diff --git a/test/tests b/test/tests
index ba4e075..937828b 100644
--- a/test/tests
+++ b/test/tests
@@ -164,4 +164,4 @@ B destructuretup E 0
B nestedgoto E 0
B initializer E 0
B fmtalign E 0
-
+B implexpr P 12,z,hello