You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the following overload resolution scenario:
typeParameterizedType[T] =objecttypeCustomTypeClass= generic
true# Definition A: precedence level 1 (highest)procp[T](x: ParameterizedType[T]) =static: echo"x as ParameterizedType[T]"# Definition B: precedence level 2 (lowest)procp(x: ParameterizedType) =static: echo"x as ParameterizedType"# Definition C: precedence level 2 (lowest)procp(x: CustomTypeClass) =static: echo"x as CustomTypeClass"p(ParameterizedType[int]()) # Definition A is called.
The signature of definition B is just the point-free equivalent of the signature of definition A, but it has a lower precedence in overload resolution. Also, a compiler error is raised if definition A is removed, because definitions B and C have the same precedence, even though definition B seems more concrete/specific (though I suppose this is subjective).
To clarify, the behavior I expected for overload resolution:
"is this"-style types (like ParameterizedType and ParameterizedType[T]) are treated equally, whether or not they are typeclasses.
"is this"-style types are preferred to "does this"-style types (like "CustomTypeClass").
The current behavior:
There is no distinction between "is this"- and "does this"-style types.
Signatures with explicit generic parameters are preferred to signatures with implicit generic parameters, even if they are semantically equivalent.
I'm not sure if this is a conscious design decision or a bug, since it's not mentioned in the manual, but I figured I'd mention it.
The text was updated successfully, but these errors were encountered:
Update: It looks like this is actually a problem with all typeclasses, not just user-defined typeclasses:
type A {.inheritable.} =objecttype B =objectof A
procp[X](x: X): string="generic"procp[X: A](x: X): string="specialized"echop(B()) # prints "generic"
This is unfortunate, because it prohibits implementing common operations (==, $, repr, len, etc.) for instances of typeclasses. Currently, I'm trying to implement == and $ for generic n-dimensional arrays, but procedures in the system module keep hijacking my implementations. Can anyone suggest a workaround?
Consider the following overload resolution scenario:
The signature of definition B is just the point-free equivalent of the signature of definition A, but it has a lower precedence in overload resolution. Also, a compiler error is raised if definition A is removed, because definitions B and C have the same precedence, even though definition B seems more concrete/specific (though I suppose this is subjective).
To clarify, the behavior I expected for overload resolution:
ParameterizedType
andParameterizedType[T]
) are treated equally, whether or not they are typeclasses.The current behavior:
I'm not sure if this is a conscious design decision or a bug, since it's not mentioned in the manual, but I figured I'd mention it.
The text was updated successfully, but these errors were encountered: