[mercury-users] Is there a better way to write is_list/1?

Ralph Becket rbeck at microsoft.com
Tue May 23 23:09:40 AEST 2000


> :- pred is_list_2(T).
> :- mode is_list_2(in) is semidet.
> 
> is_list_2(X) :-
>     type_ctor_and_args(type_of(X),  ListTypeCtor, _),
>     type_ctor_and_args(type_of([]), ListTypeCtor, _).
> 
> 
> I feel there ought to be a better way of doing this.  Any ideas?

For bonus points, given an X that satisfies is_list(X), how does
one go about coercing it into an object of type list(T) for type
variable T?

Bailing out to C is considered naughty.

Ralph
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list