Skip to content

You can't really check for the type of Data without expect #709

Description

@KristianBalaj

What is your idea? Provide a use case.

You can't really do the following:

type MyDatumA {...}
type MyDatumB {...}

let some_datum: Data = ...

when some_datum is {
   MyDatumA {..} -> ...
   MyDatumB {..} -> ...
   _ -> ...
}

You have to use expect and that will make the code fail, so you can't properly handle it if you want to.

Also the MyDatumA/B can have multiple constructors, so there needs to be some good approach for this.

Why is it a good idea?

It's a necessary feature in my opinion. You want to be able to pattern match the Data type without failing.

The problem is that constructors of different types can have the same index so the whole structure has to be compared and a compiler error needs to be raised in case of ambiguous pattern match (when 2 constructors can't be differentiated).

What is the current alternative and why is it not good enough?

You need to have MyDatumA and MyDatumB as constructors in the same type which makes it inconvenient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    🚀 Released

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions