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.
I think that would be my repo with the DodgyString 😄.
So maybe you can substitute the Dodgy types with an 'object' as a test.
The DodgyType was due to Strings not being passable so a special type was needed to be created, though maybe I'm misunderstanding your statement.
Ok, understand.
Congrats @PriNova, you just advanced to level 10!
AnyType looks a lot like the most generic of traits/protocols
Its syntax also looks like a trait
It and Object have nothing in common, not sure where you heard that
Object is a dynamic runtime object and AnyType is for constraining generics
I guess AnyType might feel a bit like boilerplate until you can also use other traits in its place 🤔
The
!kgen
seems to be a Fortran Kernel generator and is used for AST generation and manipulation.Yeah, the
kgen
dialect seems to contain lots of special types for use in the AST or other. I was sort of surprised by the fact they moved !pop.pointer
to !kgen.pointer
, and there's probably more examples of types that might not belong. I'd guess the organization / categorization isn't perfect.
There's also examples like !kgen.declref
that definitely make sense