23 Replies
No, it is impossible to do properly without traits. You need a way to constrain the Key type to just hashable types, and that's just not implemented yet.
@TeamPuzel Has anyone even made a proper hash function yet?
I don't know, I doubt it
You could maybe implement a dictionary assuming the Key type can only be a string
PriNova is working making one it seems.
https://discord.com/channels/1087530497313357884/1098713601386233997/1153695347026186342
Yeah that seems to be avoiding the problem by limiting it to strings keys
Cool, not sure what the
object
thing doesIts a type thats supposedly easier to use than
AnyType
Oh, yeah, it looks like a runtime dynamic type feature
Thanks for your answers
IIRC the object type is just a Variant over some internal structures, like
_RefCountedListRef
and _ImmutableString
. Definitely wouldn't recommend messing with them too much.I thought the
object
type was supposed to be the nicer AnyType
...I'm not sure what AnyType actually is TBH. When Mojo spits MLIR errors about it, it seems to be of
!kgen.mlirtype
which doesn't tell us all that much.Is
object
safe to use?Hmm, that's a hard question. I think as long as you're using the basic Bool and Float values it is, but I really don't know how to deal with the
_RefCountedListRef
, _Function
, and similar values. Probably best to stay away from them. (It also looks like they don't necessarily have attached / visible properties [or if they do have some there's very few], so messing with them at all might be hard. Maybe a couple MLIR ops are dedicated to them, I wouldn't know.)
Just for reference, this is what the LSP lists o._value.value
as (if o
is of type object
).
I just have so many issues come up with using
AnyType
.The interesting part is:
the underlying _ObjectImpl type, which can be used for conversion purposes and other stuff. The underlying type is the Variant type (MLIR type)
This seems similar to what is used as DodgyType in a community repo I saw.
The documentation misses a lot of functions, which can only be seen by the completion in a IDE.