[mercury-users] how to import legacy Prolog code

Paul Bone pbone at csse.unimelb.edu.au
Tue Jul 6 10:34:50 AEST 2010

On Sat, Jul 03, 2010 at 10:46:06AM +0200, Jean-Marc Vanel wrote:
> 2010/7/3 Paul Bone <pbone at csse.unimelb.edu.au>:
> > On Fri, Jul 02, 2010 at 03:07:27PM +0200, Jean-Marc Vanel wrote:
> >> For the generation of statements pred, mode, the idea is that since
> >> the Mercury compiler can detect an inconsistency between the
> >> hand-written declaration and the implementation of the body, it can as
> >> well produce a (tentative) declaration coherent with the
> >> implementation body.
> > Okay, are you asking a question about this?  I don't know how to respond.
> Sorry Paul, while taking notes I pasted too much in the mail.
> I deleted all but the necessary part above.
> I 'm asking if writing an importer assistant along this idea is
> something feasible.
> This importer assistant would take as input a prolog source and output
> the prolog source with guessed pred and mode declarations added.

The compiler supports the following options.

                Abbreviation for `--infer-types --infer-modes --infer-det'.
                If there is no type declaration for a predicate or function,
                try to infer the type, rather than just reporting an error.
                If there is no mode declaration for a predicate,
                try to infer the modes, rather than just reporting an error.
        --no-infer-det, --no-infer-determinism
                If there is no determinism declaration for a procedure,
                don't try to infer the determinism, just report an error.
        --type-inference-iteration-limit <n>
                Perform at most <n> passes of type inference (default: 60).
        --mode-inference-iteration-limit <n>
                Perform at most <n> passes of mode inference (default: 30).

I don't know how good the inference is, AFAIK no one has tried it in order to
port legacy code to Mercury.  I don't think there is a way to create a new
version of the source file with the inferred types in it.

The other thing is that if you're using atoms that don't belong to an existing
type the compiler won't be able to help you construct a type with the atoms you
want.  In other words, you will have to write your type definitions manually
anyway, or import standard library modules yourself.

Good luck.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/users/attachments/20100706/466b9223/attachment.sig>

More information about the users mailing list