Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.mathworks.com!zombie.ncsc.mil!simtel!harbinger.cc.monash.edu.au!aggedor.rmit.EDU.AU!news.unimelb.EDU.AU!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: type checking
Message-ID: <9523000.25882@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
References: <3vkdvq$cpv@newsbf02.news.aol.com> <3vd6t2$lq0@sgi.iunet.it> <950803$003535$3280spenkov@ozemail.com.au> <505089247wnr@hyperfax.demon.co.uk>
Date: Thu, 17 Aug 1995 14:54:15 GMT
Lines: 53

"C:WINAPPSWINSOCKKA9QSPOOLMAIL" <RobDarwin-dml@hyperfax.demon.co.uk> writes:

>Forgive me if I am out of date, but I remember looking at PDC prolog
>some time ago and was concerned about the strong type checking.

Does anyone know if the latest PDC Prolog's type system is any better
than the pretty inflexible type system that Turbo Prolog had?

>I always thought that lack of type checking was a benefit for a lot of
>prolog applications, but I would be interested in other views
>(preferably not emotive/quasi-religious).

I don't think that lack of type checking is a benefit.  Type checking
has a very significant benefit: it catches a very large number of bugs
early in the software life-cycle.  A secondary benefit is efficiency.
*Some* strong type systems (e.g. Pascal's and Turbo Prolog's)
are overly restrictive, but it doesn't have to be that way.
Haskell's type system, for example, seems very flexible.

In Turbo Prolog, lists were the only polymorphic type allowed.
Goedel's type system is a fair bit better than Turbo Prolog, because
you have parametric polymorphism everywhere but still a bit
restrictive, because the polymorphism in Goedel must be purely
parametric: you can't do anything with values of polymorphic types
except shuffle them around.  In combination with a lack of higher-order
predicates, this is a pretty strong restriction: for example, you can't
write a generic sorting predicate in Goedel.

Mercury's type system is pretty similar to Goedel's, but there are
a few small but significant extensions which make it much more useable.
One extension is a universal type `univ'.  A value of any type can
be converted to type `univ' and then back again.  It's a bit like
`void *' in C, except that in Mercury the conversion from `univ' back
to another type is checked at runtime and will fail if the type
you're trying to convert it to is not the same as the original type.
Another extension is the ability to define "equivalence types", which
are similar to C's confusingly-named `typedef' except that they can be
polymorphic.  (Even C++, which has templates, does not have template
typedefs.)  Mercury also allows you to declare a type in the interface
section of a module and define it as an equivalence type in the
implementation section.  This is frequently useful, but many strongly
typed languages don't provide that facility.

Mercury doesn't have Haskell-style type classes, but you can get a
similar effect using higher-order predicates.  (Unfortunately, the
current Mercury release doesn't yet support higher-order predicates
properly.)

-- 
Fergus Henderson              | Designing grand concepts is fun;
fjh@cs.mu.oz.au               | finding nitty little bugs is just work.
http://www.cs.mu.oz.au/~fjh   | -- Brooks, in "The Mythical Man-Month".
PGP key fingerprint: 00 D7 A2 27 65 09 B6 AC  8B 3E 0F 01 E7 5D C4 3F
