Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!spool.mu.edu!uwm.edu!caen!msunews!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!conway
From: conway@munta.cs.mu.OZ.AU (Thomas Charles CONWAY)
Subject: Re: In defense of Prolog's dynamic typing
Message-ID: <9434021.28025@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU
Organization: Computer Science, University of Melbourne, Australia
References: <3aviu6$7dq@hitchcock.dfki.uni-sb.de> 	<PEREIRA.94Nov23222128@alta.research.att.com> 	<3b1q1v$kqu@hitchcock.dfki.uni-sb.de> <3b2dst$q54@elna.ethz.ch> <THOMASL.94Nov25131424@arnold.csd.uu.se>
Date: Tue, 6 Dec 1994 10:56:12 GMT
Lines: 93

thomasl@arnold.csd.uu.se (Thomas Lindgren) writes:

>In article <3b2dst$q54@elna.ethz.ch> marti@inf.ethz.ch (Robert Marti) writes:
>   Even better, use a typed language which provides automatic garbage
>   collection: CLU, Eiffel, ML, Modula-3, and Oberon come to mind -- and
>   of course Goedel.  In other words:  Ideally, I want both typing and
>   automatic memory management to save me from stupid mistakes. 
>
>One of the pains of Goedel is that you must write type declarations
>for every procedure, which is the same as type declaring each case
>statement or while-loop in an imperative language. 
>
>Goedel programs, from what I have seen and my few own programming examples,
>seem to consist of equal parts of type declarations and program. A language
>such as the recently proposed Mercury had even more declarations: in the
>paper I read, a toy example had 14 lines of declarations and 4 lines of
>program code. (Since the authors are probably reading this, maybe they 
>can inform us on the amount of typing required for a larger system? As I
>recall, the compiler is written in the language itself and is fairly large.)

The following stats were produced by a very simple awk script run on the
current compiler sources. You will notice that some of the percentages
do not quite add up. This is because the awk script is fooled by
declarations that cross line boundaries, and so on.

Number of types:                   339
Number of insts:                    17
Number of predicates:             2177
Number of modes:                  2209
        - det:                    1858 ( 84.11%)
        - semidet:                 344 ( 15.57%)
        - nondet:                   38 (  1.72%)
Average modes per predicate:     1.015

Blank lines:                      9195 ( 20.73%)
Comment lines:                    4638 ( 10.46%)
Total whitespace/comment lines:  13833 ( 31.19%)

Predicate declaration lines:      2884 (  6.50%)
Mode declaration lines:           2278 (  5.14%)
Type declaration lines:           1069 (  2.41%)
Inst declaration lines:             45 (  0.10%)
Module declaration lines:          895 (  2.02%)
Total declaration lines:          7171 ( 16.17%)

Code lines:                      23353 ( 52.65%)

Total number of lines:           44357 (100.00%)

The declarations for the begining of modules, to import modules
and delineate the interface and implementation sections of
programs act as a fairly constant overhead for each module.

The smallest modules need about 5 lines of declarations for these
things, and the largest rarely need more than about 10 (the extras
are accounted for by the fact that a large module usually needs to
import more external modules).

Again and again I hear people complain about having to write
declarations, and that they take too much time and effort.

Well, you get what you pay for. You choose - either pay the
cost once and spend an extra ten seconds for each predicate
typing the declaration (if you're writing the predicate, you
usually know what types you want it to operate on, and in
which modes you want it to operate) and let the compiler
find the errors, or spend an extra ten to 100 minutes in the
debugger sweating blood to find the errors yourself.

Of course, if it was only that the Mercury type, mode and
determinism systems reduced your stress level by enabling
the compiler to find most of your bugs, then perhaps you
might be forgiven for feeling that the extra few seconds
was more than you could stand. However, our benchmark results
just keep getting better. Our results for a fairly standard
suite of Prolog benchmark programs are quite unabiguous -
Mercury is the fastest logic programming system in the world.

What is more, we do not use global analysis to achieve this
performance. We perform local type, mode and determinism
analysis, and peephole optimisation. The output of the
compiler is GNU C which is much much more portable than
the output of the high performance Prolog implementations
which generate achitecture specific object code.

We are close to bootstrapping the compiler. When we have,
you can be sure we will be letting everyone know. :-)

pax
Thomas
-- 
Thomas Conway                                           conway@cs.mu.oz.au
AD DEUM ET VINUM
