[mercury-users] Higher order programming

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Apr 22 17:17:08 AEST 1999


Lee Naish <lee at cs.mu.OZ.AU> wrote:
> Fergus wrote:
> >Ralph Becket <rwab1 at cam.sri.com> wrote:
> >> I'm a great advocate of higher-order programming, but I find that it's
> >> not as easy in Mercury as it ought to be,
> >
> >There's several reasons for this, some of which are technical, but
> >many of which are just historical.
> >
> >> library predicates not being
> >> provided in `forward only' versions or not taking `function' HO args.
> >...
> >> The problem, of course, is that the compiler doesn't like HO arguments
> >> that have multiple modes.
> 
> I think this problem would be easier to solve if there was less
> distinction between predicates and functions.

That could solve the problem of predicates not taking `function' HO args.

But I don't think it would solve the problem of the compiler not being
able to infer the modes for higher-order terms.

> Treating functions as a
> syntactic sugar for det predicates has several advantages, including
> having a simpler "core" language (which would be nice for people working
> on the semantics).  A predicate can have several modes, one of which (a
> det one) can be associated with the "function" of the same name (ie, the
> syntactic sugar).

Why would only one mode be associated with the function?  If a predicate
has more than one det mode, which one would the compiler choose?

> In the case of higher order, you can have a predicate
> such as map2 with an identified functional mode which takes a function as
> an argument.  Similarly the predicate plus/3 has an identified
> functional mode.  A goal map2(plus, As, Bs, Cs) may give the compiler a
> hard time (as present), but for a functional expression map2(plus, As, Bs)
> the compiler should be able to figure out easily that its the functional
> modes of both map2 and plus which must be used.  Maybe I'm missing some
> tricky things of course...

Well, in Mercury functions are allowed to have more than one mode.
The `+' function may be reversible.  So a goal using a functional
expression like `Cs = map2((+), As, Bs)' might be computing
As from Bs and Cs rather than computing Cs from As and Bs.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the users mailing list