Question: How to make a type identity valid in procedure parameters

Consider the following simple procedure:
 

restart;
p:=proc(x::{realcons,{set,list}(realcons)} ) x end proc;
p(8);
p({8,9});
p([7,8]);

I would like to be able to do something like this instead:

q:=proc(x::{ID,set,list}(realcons) ) x end proc;
## ID(realcons) should just be realcons.
q(8); ## Obviously we get an error.
q({8,9}); #OK
q([7,8]); #OK

In Q below ID is simply s->s, but that won't work in q.
Q works because the type check evaluates its arguments first.
 

Q:=proc(x) 
    if type(x,{s->s,list,set}(realcons)) then 
      x 
    else 
      error "%1 expects its first argument to be of type %2", procname,{s->s,list,set}(realcons)
    end if
end proc;
Q(8);
Q({8,9});
Q([7,8]);

I believe that Carl Love had a solution on MaplePrimes some years ago, but I can't find it.

Please Wait...