Last active
March 1, 2016 16:40
-
-
Save gmpreussner/6424afb5d8dd181cde4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
Foo[T] = concept x | |
x.foo(T) | |
proc foobar[T](f: Foo[T]) = | |
f.foo(42) | |
type | |
FooImpl[T, U] = object | |
a: T | |
b: U | |
proc foo[T, U](f: FooImpl[T, U], t: T) = | |
echo $t | |
when isMainModule: | |
var f: FooImpl[int, float] | |
echo f is Foo[int] # true | |
f.foo(42) # 42 | |
f.foobar # Error: type mismatch: got (FooImpl[system.int, system.float]) | |
# but expected one of: | |
# foo.foobar(f: Foo[foobar.T]) |
Workaround:
type
Foo[T] = concept x
type Z = x.T # <---
x.foo(Z)
proc foobar(f: Foo) = # <---
f.foo(42)
type
FooImpl[T, U] = object
a: T
b: U
proc foo[T, U](f: FooImpl[T, U], t: T) =
echo $t
when isMainModule:
var f: FooImpl[int, float]
echo f is Foo[int] # true
f.foo(42) # 42
f.foobar # 42
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
even T is not needed in the impl type: