[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Union tag comparison
- Subject: Re: Union tag comparison
- From: ori@xxxxxxxxxxxxxx
- Reply-to: myrddin-dev@xxxxxxxxxxxxxx
- Date: Tue, 11 Feb 2020 18:34:34 -0800
- To: mail@xxxxxxx, myrddin-dev@xxxxxxxxxxxxxx
> Hello,
>
> Say, I have a
> type expr = union
> `Oadd(expr#, expr#)
> `Oneg(expr#)
> ;;
>
> I want to compare two expr values to determine whether they are of the same Op.
> As I know, I can define a function that maps each variant into a distinct integer or string.
> But It'd be nice if it can be as simple as how C does: 'a.Op == b.Op'.
> I am thinking about a builtin function that retrieves the internal integer value of the union tag.
> Am I missing something?
Seems sane-enough. I'd prefer if instead of a function, it was a magic '.tag' member,
kind of like '.len' on arrays.