seanbaxter / circle

The compiler is available for download. Get it!
http://www.circle-lang.org/
2.42k stars 74 forks source link

Could `choice` support equality operation? #170

Open cmarcelo opened 1 year ago

cmarcelo commented 1 year ago

When porting code from std::variant to the new choice type, I've noticed == is not implemented for choice. It seems to me this could be possible for the compiler to generate the comparison of the type tag then delegate to the underlying type if that matches. Would such feature make sense for choice, or perhaps I am missing some feature of pattern matching that would make this easier?

Some sample code I'd expect to work:

#feature on choice

#include <iostream>

choice t {
    Integer(int),
    Boolean(bool),
};

int main() {
    t a = .Integer(12);
    t b = .Integer(13);
    t c = .Boolean(true);

    std::cout << "a == b ? " << (a == b) << "\n";
    std::cout << "a == c ? " << (a == c) << "\n";

    return 0;
}