Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!udel!gatech!swrinde!pipex!uknet!festival!edcogsci!corin
From: corin@cogsci.ed.ac.uk (Corin Gurr)
Subject: Re: Why hasn't Prolog Taken over the World?
Message-ID: <CzEu1L.G83@cogsci.ed.ac.uk>
Organization: Centre for Cognitive Science, Edinburgh, UK
References: <3a6lf4$mk5@mozo.cc.purdue.edu> <3aal5c$b4d@ra.nrl.navy.mil> 	<citrin-1511941431140001@ecemac-citrin.colorado.edu> <D91A1BO.94Nov16141507@Ankara.meryl.csd.uu.se>
Date: Thu, 17 Nov 1994 11:47:32 GMT
Lines: 99

d91a1bo@Ankara.meryl.csd.uu.se (Alexander Bottema) writes:

>First, I do not agree that most errors in Prolog are type errors.  I
>have written quite large Prolog programs (including a Prolog -> WAM
>compiler; ok. it isn't that large) and my experiences are that type
>errors are uncommon. Why? Well, Prolog use Herbrand terms as
>fundamental data structures. There are some natural extensions due to
>efficiency such as integers, float numbers and such, but one rarely
>mixes these with Herbrand terms.

I disagree. I have also written quite large Prolog programs which had
errors that a type system would have detected and this has nothing to
do with Prolog using Herbrand terms. A lot of (in my experience)
common errors (eg: mis-spelled constant, functor and predicate names,
missing arguments in predicates, predicates with arguments in wrong
order etc) would be detected by a type-checker at *compile-time*
rather than spending hours tracing through program execution. 

I was convinced of the advantages of a typed logic programming
language when I started using Goedel. I have written some very large
programs in Goedel and I would estimate that at least 80% of the
errors I made when writing them were detected at compile-time by the
type-checker. Of course, I may simply be a very bad typist but I now
find untyped Prolog vastly inferior by comparison.

>Second, it isn't trivial to develop a type system for Prolog (or for
>logic programming languages). What is the type of a predicate? In
>functional languages the type inference mechanism is obvious; the type
>is simply derived from its components.

Well, while it is not trivial I think it is a lot more obvious than
you imply. Goedel's type system is based on the following:

@inproceedings{hill92,
   author = "P M Hill and R W Topor",
   booktitle = "Types in Logic Programming",
   editor = "F Pfenning",
   publisher = "MIT Press",
   title = "A Semantics for Typed Logic Programs",
   year = "1992",
   pages = "1--62"
}

Obviously this is not the only possible type system for logic
programming but it's pretty good. Developing a type system for 
logic programming languages *is* trivial if someone else has already
done it.

>However, one possible extension would be to introduce contraints on
>Prolog variables. Perhaps you would like this notation:

>	p(X:[int],Y:[int],Z:[int]) :-   ... X ... Y ... Z ...

>But this is the same as writing:

>	p(X,Y,Z) :- integer(X), integer(Y), integer(Z), ... X ... Y ... Z

In Goedel the equivalent type declaration would look like this:

  PREDICATE P : Integer * Integer * Integer.

I don't see that it takes any more effort/space to write this as
opposed to your suggestion.


>And a good Prolog compiler with global data flow analysis would of
>course optimize calls to this predicate by skipping the integer
>predicates if X, Y and Z are known to be integers before the call,
>e.g.

>        q :- X is 42, Y is 4711, Z is 17, p(X,Y,Z), ...

>So, instead of augmenting the language with syntactic sugar it would
>be much better to make the compilers more efficient, e.g. by
>introducing global data flow analysis.

This is a good suggestion - but I suspect that implementing a data
flow analysis of the kind you suggest would involve a lot of
work. If you already know the types of X, Y and Z because you
were using a typed language then you could perform the same compiler
optimisations without the compiler having to do the global analysis to
identify the types in the first place.

I have written large programs in Prolog and I have written large
programs in Goedel. I prefer Goedel for lots of reasons, but if its
*only* advantage were the type system, that would be enough. 

>--
> Alexander Jean-Claude Bottema, Email: d91a1bo@meryl.csd.uu.se
> University of Uppsala, Computing Science Department.
> #include <stddisclaim.h> LINUX,GCC,Eiffel,Haskell,ML,CAML-light,Prolog
> http://www.csd.uu.se/~d91a1bo/ LINUX LINUX LINUX LINUX LINUX LINUX


-- 
Corin Gurr
Human Communication Research Centre   Tel.: +41 31 650 4448
Edinburgh University                  Email: corin@cogsci.ed.ac.uk
2 Buccleuch Place                     FAX: +41 31 650 4587
