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

Ralph Becket rafe at cs.mu.OZ.AU
Fri Jul 16 12:17:25 AEST 2004


Peter Schachte, Friday, 16 July 2004:
> 
> The loss of type safety here is troubling.

Oh, I agree.  But there's a limit to how much belt-and-braces coding
one's programs can stand before they lose clarity.  Using equivalence
types sensibly requires a bit of nous.

> > 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.

And, indeed, write out the syntax correctly: `(func V_2)' is clearly an
output bug.

I have to admit, literate programming is one of those things I've
occasionally looked at, but never had the discipline to do.  I have a
nagging feeling that it's a way of obscuring both program and
documentation simultaneously, but I'd be happy to be shown I'm wrong.

> 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.

Please be our guest!

Be warned, however: type inference (a) of course won't generate
meaningful polymorphic type names, (b) won't use equivalence type names,
(c) will probably present its results including plenty of redundant
module qualifiers and (d) looks for the most general applicable type,
which is often more than your program needs and far less helpful when
generating error messages.

-- 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