Re: "dict"ionary typing?

"Richard A. O'Keefe" <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 5/12/2013, at 11:01 PM, Michael Hendricks wrote:
> I dislike declarations when they can be inferred from usage.

They can only be inferred from usage if you are willing either
(1) to follow an ML-style **strict** definition before use policy,
    which has never been the Prolog Way, or
(2) take two passes to process the source file,
    which is also contrary to Prolog practice.
>  I
> particularly dislike function declarations in Prolog because they imply
> that a predicate can only be used as a function in a single "mode".

There is no such implication.  Change it to ':- active', then.
They're the perfect place to put type information, even if it is
currently just treated as commentary.

>  One
> might reasonably use append/3 as a function in three different modes.  I
> haven't implemented it yet, but I'm considering a new feature for
> library(func) inspired by Ciao's notation.  Specifically, a single ~ marks
> the argument to be used as output for *this* call.
> 
>  ?- writeln(append([a,b],[c,d],~)).

It's just too bad that ~ is a perfectly good data term
as it stands and append([a,b],[c,d],~) is also a perfectly
good data term as it stands, so this query is perfectly
meaningful right now, meaning something else.  This is a
recipe for confusion.

I've seen something similar done in Eiffel "agent expressions",
and it's nearly as unattractive there.

You can get something of the same effect using definitions like

	ret1(G) = X :- arg(1, G, X), call(G).
	ret2(G) = X :- arg(2, G, X), call(G).
	ret3(G) = X :- arg(3, G, X), call(G).
...
	ret3(append([a,b], [c,d], _))


Oh yes, there is a >> logical << approach to functions in
Prolog called "narrowing".  There's been quite a lot written
about it.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.