[m-users.] Multi predicate of entire enum
jfischer at opturion.com
Mon Jul 20 15:27:16 AEST 2020
On Sun, 19 Jul 2020, Ace wrote:
> So say I have some enum:
> `:- type ex ---> a; b; c.`
> And I want to generate a function similar to:
> :- pred ex_mul(ex::out) is multi.
> Any kind of standard library predicate I can use so I don't have to
> add a new case to the predicate for every instance of the enum?
You could use RTTI to implement such a predicate, although it will be more
expensive than than the simple form above, e.g. something like:
:- pred ex_mul(ex::out) is multi.
TypeDesc = type_desc.type_of(V),
NumFunctors = construct.det_num_functors(TypeDesc),
int.nondet_int_in_range(0, NumFunctors - 1, FunctorNum),
Univ = construct.construct(TypeDesc, FunctorNum, )
error("should not get here")
More information about the users