-
Notifications
You must be signed in to change notification settings - Fork 3
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
parametric type on only some of variants #11
Comments
Hi, this is intentional because variants TL;DR, you should specify the type parameter for GADTs at construction. julia> AT.B{Int}(1.0)
Main.AT.Type{Int64}(Main.AT.var"##Storage#B"{Int64}(1.0)) This is the same in Rust, e.g enum AT<T> {
A(T),
B(f64),
} writing the following will cause an error let x = AT::B(1.0); gives
the reason why a singleton can have a constructor is that, for a singleton, we can use We cannot do this for other variants because this is not always true for variants with fields and we cannot make the type parameter adaptive, e.g, what if my type parameters are annotating units
Then we don't know what to do when expecting |
Thanks for the very detailed explanation (and for the very nice package), it is clearer now. I think it would be worth to add some example/explanation about this in the docs, what do you think? (unless it's already there somewhere and I did not find it while reading yesterday) |
Definitely! As you can see, the documentation still needs to be completed. (that's why I created the gotcha label, in case I forget) |
Hello,
I was trying out the package and wanted to reproduce the very simple example in the README of DynamicSumTypes.jl to compare synthax/performance.
That example (slightly adapted) creates a sumtype like so:
I tried creating something similar with Moshi doing this:
The problem with the Moshi version is that
AT.B
has no constructor, it seems a constructor forB
is correctly generated only in the following two cases:B
has no fieldsB
has at least one field of typeX
Is there any alternative way to create variants that do not use the parametric type but still have fields?
The text was updated successfully, but these errors were encountered: