[mercury-users] support for Prolog variables

Warwick HARVEY warwick at cs.mu.OZ.AU
Tue Sep 8 12:36:02 AEST 1998


Fergus writes:
> However, occaisionally you do want to do some constraint solving on
> Herbrand terms.  We do want to have a solution for those relatively
> rare occaisions, and that is what the `var' module is for.
>
> We might well provide more direct support for this kind of thing at
> some point in the future.  For example, we might one day allow some
> kind of annotation on declarations for user-defined types to indicate
> that values of that type may have inst `any'.  This would allow you to
> use a type `foo' directly rather than using the type `var(foo)'; that
> could improve efficiency as well as adding a little notational convenience.
> (The HAL project, which is using Mercury as a target language, has already
> given us some initiative in this direction, and indeed I believe that
> Warwick Harvey was experimenting with a version of the Mercury compiler
> modified along these lines.)

I certainly am.  How usable it will be for writing Mercury programs I don't
know, as it is primarily intended to support this feature in HAL.  For
example, at this stage I don't know whether the Herbrand solver will be
implemented at the HAL level or the Mercury level - if it's at the HAL
level, it won't be much use for Mercury.  :-)  Also, the Herbrand operations
will probably need to be called manually: we assume such calls are generated
by the HAL compiler.

There is of course a run-time cost.  One must have trailing enabled, which
as Fergus noted incurs a cost throughout the whole program, not just the
part that uses the feature.  It also reserves a primary tag, which can mean
some data types are represented less efficiently, and means that the current
scheme does not work at all for some types (e.g. unboxed ints, floats,
etc.).

At this stage there is no annotation for Mercury types - whether this
feature is wanted or not for a given type is annotated at the HAL level (and
in fact all suitable Mercury types have the tag reserved).

Anyway, the required modifications to the Mercury compiler are almost done;
testing and fixing are proving to be slow however, as it's hard to get more
than one compile/bootcheck/install cycle per day.

Warwick



More information about the users mailing list