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
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
replace
Int
with the name of your newly created struct
typeif you mean something like
my_list = List(Int, Float64, Point2d)
then this isn't possible atm but I would also like to see itCongrats @Ryulord, you just advanced to level 8!
You can use
variant
it's just not as ergonomic as it eventually (hopefully) will beBy the struct type do you mean literally the name of the struct?
from this def:
you should be able to just write
List[Cat]()
to construct a list that can hold things of that typeI guess that technically works for a list but doesn't for set since it isn't hashable
Oh yeah that works pretty well
I'm surprised there isn't conditional conformance for that
not too surprising since it's variant so it would need to conditionally conform to everything
yeah, definitely some work to be done to fill in some of those gaps
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
I think proper sum types will obviate most direct uses of variant anyway, tbh