diff options
author | Zahary Karadjov <zahary@gmail.com> | 2012-03-25 20:55:21 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2012-03-25 20:55:21 +0300 |
commit | bc2eb0ea9b8a806ddafdb7726c94363fbd2c2f20 (patch) | |
tree | d3a46fd2705e5f58f1d0b93a3d90ef253f642c5d /tests/compile | |
parent | 296ef07955b9b9813d3dbd0d8de3e483ff79ee08 (diff) | |
download | Nim-bc2eb0ea9b8a806ddafdb7726c94363fbd2c2f20.tar.gz |
generic types can be used like type classes. distinct can be applied to type classes.
Diffstat (limited to 'tests/compile')
-rw-r--r-- | tests/compile/ttypeclasses.nim | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/compile/ttypeclasses.nim b/tests/compile/ttypeclasses.nim new file mode 100644 index 000000000..e22ede1dc --- /dev/null +++ b/tests/compile/ttypeclasses.nim @@ -0,0 +1,34 @@ +type + TFoo[T] = object + val: T + + T1 = distinct expr + T2 = distinct expr + +proc takesExpr(x, y) = + echo x, y + +proc same(x, y: T1) = + echo x, y + +proc takesFoo(x, y: TFoo) = + echo x.val, y.val + +proc takes2Types(x,y: T1, z: T2) = + echo x, y, z + +takesExpr(1, 2) +takesExpr(1, "xxx") +takesExpr[bool, int](true, 0) + +same(1, 2) +same("test", "test") + +var f: TFoo[int] +f.val = 10 + +takesFoo(f, f) + +takes2Types(1, 1, "string") +takes2Types[string, int]("test", "test", 1) + |