[mercury-users] Math Module

Peter Schachte schachte at cs.mu.OZ.AU
Tue Oct 22 11:57:30 AEST 2002


On Tue, Oct 22, 2002 at 11:30:11AM +1000, Ralph Becket wrote:
> Nancy Mazur, Monday, 21 October 2002:
> > 
> > Darn, i never liked the functions anyway ;-) I guess you are using
> > version 0.10 of the compiler and its libraries? In these libraries you 
> > can find that there are two math_round thingies: 
> > 	- a math__round predicate
> > 	- a math__round function
> 
> In v.2 of the libraries I hope we can avoid this sort of thing.

That would be good, but I don't think it's just a library problem.
Programmers can cause the same problems easily and naturally enough in
their own code.

The problem arises from overloading.  In this case, it's func/pred
overloading.  It'd be easy enough to just have the function, and write
N = round(R) when you would want the relational version.  But the same
problem can arise from arity overloading.  Eg, if there are functions

	:- func reverse(list(T)) = list(T).
	:- func reverse(list(T),list(T)) = list(T).

(the second reverses the first argument and appends the second to the
end), then

	reverse(L)

could be a function call or a closure.  If the context doesn't
disambiguate, there's a problem.

How do other strongly typed languages with currying and overloading
handle this?

Maybe both arity and func/pred overloading should go?  Or maybe
currying should go?  The latter could be as simple and painless as
requiring you to write something like "func reverse(L)" when you mean
the closure (ie, all closures would be written as func/1 or pred/1
terms).  If this would fix this class of pitfalls, it sounds like a
good idea to me.

-- 
Peter Schachte              ....I have not failed. I've just found 10,000 ways
schachte at cs.mu.OZ.AU        that won't work.
www.cs.mu.oz.au/~schachte/      -- Thomas Edison 
Phone: +61 3 8344 9166      
--------------------------------------------------------------------------
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