[mercury-users] Why is --infer-all not the deafult?

Peter Schachte schachte at cs.mu.OZ.AU
Fri Jul 16 10:50:08 AEST 2004


On Thu, Jul 15, 2004 at 12:00:45PM +1000, Ralph Becket wrote:

> :- type filename == string.
> :- type timestamp == int.
> 
> There's no need for wrapping/unwrapping of these values.  The new type
> names give the reader more information about what a particular argument
> is supposed to represent (although you don't get the same level of type
> safety as you would using a wrapper type.)

The loss of type safety here is troubling.  Eg, given a predicate

	:- pred write_string_to_file(string, filename, io, io).

a call

	write_string_to_file(Filename, Text, !IO)

would be accepted.

But worse still is that equivalence types don't actually provide the
abstraction they would seem to.  For example, the function call

	concat(Filename, ".m")

would also be allowed.  This means you can't later redefine the
filename type to be, for example,

	:- type filename ---> filename(directory, basename, extension).

This makes equivalence types much less attractive from a software
engineering point of view.

> the compiler reports
> 
> foo.m:006: Inferred :- func r((list.list(T))) = (list.list(T)).
> foo.m:009: Inferred :- func m(((func V_2) = T), (list.list(V_2))) = (list.list(T)).
> 
> I'm sure you could write a tool that took these inferred declarations
> and inserted them into your code in the appropriate places.

Agreed.  It would make a nice feature for a Mercury literate
programming tool.  The generated output would need a bit of cleanup
first, removing the extra parentheses and module names, and use T2
instead of V_2.

In fact, I'll bet some clever Emacs hacker could get these to appear
in your source code as you edited it, highlighted to show it was
inferred, rather than part of the source code.  With that, I'll bet a
lot of people would be happy to let the compiler infer the types,
modes, and determinisms of many of their utility predicates.  What I'd
really like is for the compiler to infer the types and modes of
predicates I've written calls to, but haven't coded yet, and inject
them into my editor buffer as I code.  It would make a really handy
TODO list.

-- 
Peter Schachte              I believe we are on an irreversible trend toward
schachte at cs.mu.OZ.AU        more freedom and democracy -- but that could
www.cs.mu.oz.au/~schachte/  change.
Phone: +61 3 8344 1338          -- Dan Quayle 
--------------------------------------------------------------------------
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