[mercury-users] clause/1, functor/3, arg/3 ...

Fergus Henderson fjh at cs.mu.oz.au
Tue Jul 8 21:04:08 AEST 1997


Ralph Becket, you wrote:
> I'm sure I'm being a bit dense here, but given Mercury's type scheme,
> surely one can just use a switch and pattern matching to decide the
> functor/arity/arguments of any structure?  I thought Prolog only
> needed them *because* it doesn't have a (strong) type scheme.
> What does functor/3 and arg/3 get you in Mercury?  I'm intrigued (or
> very dim)!

For any given type, you can use a switch and pattern matching,
but if you want to write a single predicate that works for every type,
then you need something like arg/3 & functor/3.

An immediate application of this is the io__print, io__write, io__read,
io__write_binary, and io__read_binary predicates that will be included
in the next release.  The io__print predicate subsumes the functionality
of io__write_int, io__write_string, io__write_float, etc.

Another application of this sort of thing is for writing a generic
hash function.  

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the users mailing list