-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generics: error with multiple types and constraints #7794
Comments
Even this doesn't work: type
Element*[U: float64] = ref object
value*: U
Data*[T: int, U: float64] = ref object
xs*: seq[T]
e*: Element[U]
let e = Element[float64](value:2'f64)
let xs = new_seq[int](10)
var d = Data[int, float64](xs: xs, e: e) |
or this: type
Data*[T:SomeNumber, U:SomeReal] = ref object
x*: T
value*: U
var d = Data[int, float64](x:10.int, value:2'f64) |
well as close as I can get between working and non working with non-essential parts removed. type
# this works
DataA*[T, U] = object
xs*: seq[T]
e*: U
# this doesn't
DataB*[T:SomeNumber; U:SomeNumber] = object
xs*: seq[T]
e*: U
var a = DataA[int, float64](xs: @[1,2,3], e: 12.3)
var b = DataB[int, float64](xs: @[1,2,3], e: 12.3) |
There are two factors contributing to this:
CC @zah |
Regarding your point 2, you seem to be missing the fact that each named type class is a "bind once" type by default. This is briefly explained in the type classes section of the manual: In this sense, Brent's example is the best when it comes to solving this issue, because it doesn't invoke this extra complexity: type
Data*[T:SomeNumber, U:SomeReal] = ref object
x*: T
value*: U
var d = Data[int, float64](x:10.int, value:2'f64) With that said, I'll mention for completeness that there are indeed problems with the |
There's definitely more than it meets the eye.
Yeah, I noticed some comments about this in the compiler.
Oh, I've completely missed that bit.
Definitely Resetting |
Sounds like a plausible solution, but as usual the test suite will tell you if there are problems. |
The flag should not be carried out across different parameters. Fixes nim-lang#7794
That's not true, |
The flag should not be carried out across different parameters. Fixes nim-lang#7794
The flag should not be carried out across different parameters. Fixes #7794
That's a problem only due to the heavy use of |
No, it's not an implementation problem, it's language design / spec problem: |
I don't disagree with this, but it doesn't contradict anything I said. |
the code below fails with:
Error: cannot instantiate Data got: <type int, type float64> but expected: <T: SomeNumber, U: SomeNumber>
The text was updated successfully, but these errors were encountered: