[mercury-users] Idea for another handy convention (preds, thi s time).
Ralph Becket
rbeck at microsoft.com
Thu Jul 27 20:23:43 AEST 2000
> From: David Overton [mailto:dmo at cs.mu.OZ.AU]
>
> IMHO, a predicate that does not have the mode/determinism
> `p(in, ..., in) is semidet' is a lot less `unusual' than a function
> that does not have mode `f(in, ..., in) = out is det'. E.g. at least
> 95% (conservative guess) of the predicates I write have at least one
> output argument and determinism `det'.
My preferred style is to use functions for single-output, monomoded
relations and predicates for all others (although it is *occasionally*
very handy to have multimoded functions).
In pretty much any non-logic language, a predicate is taken to be a
function returning a boolean, and, in the absence of explicit modes,
I'm suggesting we use a similar convention, albeit without a return
value.
Almost all other predicates, in my experience, have more than one output
and hence need the explicit mode annotation.
> Also, currently when there is no mode declaration for a predicate,
> this is an indication that the compiler should try to infer the
> mode(s) for that predicate (it can presently only do this for
> predicates that aren't exported from a module).
This doesn't work for my pred lambda example. I have to write
Evens = list__filter((pred(X::in) is semidet :- X mod 2 = 0), Xs)
to avoid a whole slew of errors.
> However, since we don't do mode inference of lambda expresssions,
Ah.
> perhaps `pred(in, ..., in) is semidet' would be a reasonable default
> for these, especially since they are the kinds of predicates you are
> most likely to use if programming in a functional style, as in the
> example Ralph gives of `list__filter'.
How many on this list make use of automatic mode inference, rather than
supplying explicit modes for preds? Personally I suspect I'd find it
quite hard to understand code including multi-output predicates that did
not supply mode declarations for them. I know this sort of thing led to
all sorts of grief with inadequately documented predicates when I worked
on a very large, multideveloper Prolog project.
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