Is there a Struct type or something similar?

I'm trying to create a Set / List which can hold structs, but I'm not sure how to initialise this sort of type.
15 Replies
sb
sb2mo ago
You should just be able to create your own type with a name and then use that name as a parameter to the collection types
sb
sb2mo ago
replace Int with the name of your newly created struct type
No description
Ryulord
Ryulord2mo ago
if you mean something like my_list = List(Int, Float64, Point2d) then this isn't possible atm but I would also like to see it
ModularBot
ModularBot2mo ago
Congrats @Ryulord, you just advanced to level 8!
sb
sb2mo ago
You can use variant it's just not as ergonomic as it eventually (hopefully) will be
banananas
banananasOP2mo ago
By the struct type do you mean literally the name of the struct?
sb
sb2mo ago
from this def:
No description
sb
sb2mo ago
you should be able to just write List[Cat]() to construct a list that can hold things of that type
Ryulord
Ryulord2mo ago
I guess that technically works for a list but doesn't for set since it isn't hashable
banananas
banananasOP2mo ago
Oh yeah that works pretty well
sb
sb2mo ago
I'm surprised there isn't conditional conformance for that
Ryulord
Ryulord2mo ago
not too surprising since it's variant so it would need to conditionally conform to everything
sb
sb2mo ago
yeah, definitely some work to be done to fill in some of those gaps
Ryulord
Ryulord2mo ago
I don't think you actually want variant to conditionally conform to every trait. I think that would be better served with dynamic polymorphism when we eventually get it since that basically is all it would be doing
sb
sb2mo ago
I think proper sum types will obviate most direct uses of variant anyway, tbh
Want results from more Discord servers?
Add your server