【发布时间】:2015-09-30 22:22:07
【问题描述】:
我有一个这样的concept:
type Foo = concept x, y
x.test(y) is bool
然后是尝试定义实现concept的方法的类型:
type Bar = object
s: string
proc test(x: Bar, y: string): bool =
x.s == y
还有一个具有通用字段T: Foo 的类型,其构造函数接收T: Foo:
type Baz[T: Foo] = object
f: T
proc make[T: Foo](f: T): auto =
result = Baz[T](f: f)
当我创建一个新的Bar 并将其传递给make proc 以创建一个新的Baz 时,它不会编译:
let bar = Bar(s: "whatever")
let made = make[Bar](bar)
错误:类型不匹配:得到 (Bar) 但预期为 'T'
但是,如果我在概念中删除 y,例如 x.test is bool 并相应地更新 test proc,它会编译。
我做错了什么?
【问题讨论】:
标签: nim-lang