Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!europa.eng.gtefsd.com!howland.reston.ans.net!gatech!newsxfer.itd.umich.edu!nntp.cs.ubc.ca!news.bc.net!newsserver.sfu.ca!fornax!jamie
From: jamie@cs.sfu.ca (Jamie Andrews)
Subject: Prolog static typing via variable names
Message-ID: <1994Nov28.203607.26655@cs.sfu.ca>
Organization: Faculty of Applied Science, Simon Fraser University
Date: Mon, 28 Nov 1994 20:36:07 GMT
Lines: 43

     With so many heretics burning at the stake, I might as well
climb onto the bonfire...

     I've always been a fan of significant variable names.
I don't like the Fortran idea of imposing type according to name
of variable; but I would argue that in any good Prolog program,
parameters and variables corresponding to important data
structures are named according to their type.

     Why not have a painless typing scheme based on this?
We could declare, at the top of a module or program file,
something like

:- varname Tree:tree.

...meaning "wherever a variable ending in 'Tree' (or 'Tree1',
'Tree2' etc.) appears, require that that variable be of type
'tree', and wherever a variable ending in 'Trees' (or 'Trees1',
'Trees2' etc.) appears, require that that variable be of type
'list(tree)'."  We could give such a declaration for as many or
as few variable names as we want to.

     Then the system could do type inference based on this and
other variable name declarations.  All that's needed other than
these declarations is a module of type declarations.  I would
argue that this is a very painless method for typing, in that it
involves very little, er, typing (on the keyboard), and also in
that you can buy into it as little or as much as you want.
Buying into it a lot would allow you to catch lots of type
errors statically.

     [Picky detail:  not all English plurals are formed by
adding -s, and in order to be not Anglocentric, we should take
account of other languages as well.. so I guess we could also say

:- varname Box/Boxes:box, Biscotto/Biscotti:biscotto.

...with the obvious interpretation.  (Sorry, biscotto was the
only Italian word I could remember off the top of my head :-)) ]

--Jamie.
  jamie@cs.sfu.ca
"Make sure Reality is not twisted after insertion"
