-
Notifications
You must be signed in to change notification settings - Fork 8
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
mutable sum types? #57
Comments
Hi @Tortar, yes the correct way to do this would be to wrap the contents in a You should definitely not be doing Instead, you should do something like s = A(Ref(0), Ref(0))
@cases s begin
A(x, _) => x[] = 3
B(x, _) => x[] = 3
end |
thanks for the prompt responses @MasonProtter, what I'd like to ask you is if you think that creating an interface in another package which mimics the working of structs, mutable structs would make sense (and would be possible) in your opinion? Because for example I'm thinking to use SumTypes for some heterogeneous data containers (multi-agent systems) in Agents.jl but I need a syntax equivalent to that of mutable structs to expose to users |
for example it seems maybe possible to wrap the cases macro in getproperty/setproperty |
I guess it would be possible to make a Sum Type appear like a regular struct for the purposes of a user-facing interface, but how to do it would be mostly up to you and would depend on your use-case. I don't really have enough information to give advice on this |
I'd like to use sum types for a package, but I would need mutable sum types, is it possible to support them?
For now I see that it is already possible with some
Base.RefValue
wrapping but I'm not sure this is the correct approach e.g.but I'm not sure neither if this is optimal (is this as fast as mutable structs?) nor if it safe since I'm using internal fields to modify data. I wonder if maybe a more "integrated" solution is possible.
The text was updated successfully, but these errors were encountered: