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

Ralph Becket rwab1 at cam.sri.com
Tue Jul 8 23:10:28 AEST 1997


Fergus Henderson wrote on 8 Jul:
> ...
> 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.

io__write_many seems to be sufficient for all that stuff.  Although
it's nice to have `print whatever' procedures in an interactive/
debugging environment, I'm not sure I see what it buys you otherwise.
Why not have a programmer extensible overloaded function with
universal scope, for example:

:- func fmt(my_thing::in)=string::out.

fmt(X) = S :-
  X = case1(...), string__format("...", [...], S);
  ...

Programmers would similarly be expected to provide unmarshalling
procedures for reading things in.

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

Maybe... it just doesn't feel in the Mercury spirit.  By all means
provide these things as built-ins, such as standard ordering, where
the programmer can pretend they're overloaded functions.

I can see the point in having these things around, I'd just like to
see them as well hidden as possible.

'Nuff whingeing from me,

Ralph



More information about the users mailing list