У меня возникли проблемы с определением концепции с типом auto
внутри. Похоже, Ним жалуется, что type T = auto
становится untyped
.
Вот минимальный пример (запустите его онлайн здесь), взятый в основном из из документации):
import sugar, typetraits
type
Functor[A] {.explain.} = concept f
type MatchedGenericType = genericHead(typeof(f))
# `f` will be a value of a type such as `Option[T]`
# `MatchedGenericType` will become the `Option` type
# f.val is A
# The Functor should provide a way to obtain
# a value stored inside it
type T = auto
map(f, A -> T) is MatchedGenericType[T]
# And it should provide a way to map one instance of
# the Functor to an instance of a different type, given
# a suitable `map` operation for the enclosed values
import options
echo Option[int] is Functor # should print true but doesn't!
# The above came straight from
# <https://nim-lang.org/docs/manual_experimental.html#concepts-generic-concepts-and-type-binding-rules>
proc f(x: Functor) = echo "yes!"
f(some(1))
Вот соответствующая часть ошибки (помимо того факта, что в документах говорится, что Option[int] is Functor
должно быть true
, но это не так):
proc map[T, R](self: Option[T]; callback: proc (input: T): R): Option[R]
first type mismatch at position: 2
required type for callback: proc (input: T): R{.closure.}
but expression 'proc (i0: A): T' is of type: type proc (i0: int): untyped{.closure.}
В основном я копирую и вставляю документы здесь. Что я делаю не так?