generic types can be used like type classes. distinct can be applied to type classes.

This commit is contained in:
Zahary Karadjov
2012-03-25 20:55:21 +03:00
parent 296ef07955
commit bc2eb0ea9b
11 changed files with 147 additions and 79 deletions

View File

@@ -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)