Operation in MLIR

I’m trying to model sum types in mlir. And as I discussed in a previous topic, I want for example to have a declaration of a sum type in that form !mytype = !sumType<Small+Big>, and from what I understood mlir does not know Small and Big, and cannot associate them to an mlir::type. So the idea is to do an mlir operation in mydialect, that have String Attributes. So I defined an operation (as you can see at the screenshot). So can anyone please confirm my idea of implementation, and if it’s relevant ? (There’s also a screenshot of how I think my operation should be used in mlir)
Screenshot from 2023-06-20 16-27-44

Can anyone help please

Your question isn’t clear to me actually:

I don’t quite get why “Small” and “Big” aren’t just type themselves?

It’s not clear to me how you jumped from defining a “sum type” to “an operation with string attributes”?

Your op description says “turning a type declaration into an instance”: what is your IR modeling? Are you trying to manipulate types themselves (instead of instances of these types)?

Yes, I’m sorry if my question wasn’t clear. The idea is that I want to define my own types to handle both sum types and product types in a .mlir file. My plan is to create a class in .mlir, similar to the StructType example in Toy, that can handle both sum types and product types. Users of my dialect should be able to define their own sum types with specific constructors. For example, they could define a sum type with constructors like “Small” and “Big,” or another sum type with constructors like “Red,” “Black,” and “White.”

In my MLIR implementation, I need to handle this in a generic way. I’m not sure if you understood me better now, but my question is: How can I store the “Small” and “Big” constructors using MLIR? In another discussion, a member mentioned using operations with stringAttributes, but I didn’t fully grasp their explanation. Could you please explain how I can model my sum types in a generic way in MLIR? If I define new sum types with my own constructors, where are they stored and how can I store them? Can I use operations with stringAttributes or define new types for the constructors?

(You can see at the screenshot, when I do the parsing of the new types defined in the .mlir. The constructor of the sum types should be mlir::type).

Can you clarify what you mean by “constructors”?
That is: the MLIR type has to correspond to some C++ class, we can sketch it (in a simpler form that what it would end up being):

class SumType : mlir::Type {
    std::vector<mlir::Type> types;
    // Creates a new sum type with the provided list of types.
    SumType(llvm::ArrayRef<mlir:Type> types) : types(types) {}

Now if you provide this to users, they can create arbitrary sum types, but there is not “constructor” involved.

Since a sum type is a container for other types, it means that “Small” and “Big” have to be types themselves right?