synonym type not allowed

Dr Simon Jones s.b.jones@cs.stir.ac.uk
Thu, 18 Dec 1997 10:14:42 +0100


Erik Zuurbier wrote:

>You may regard instances of type synonyms as an instance of the basic
>type, then you don't have the problem that the compiler cannot determine
>whether the expression (3, 4.0) is of type (Int, Real) or of your
>MyType. You always use the instances of type (Int, Real).
>
>That is simple. That brings down the word synonym to what the word
>actually means:
>a different word for exactly the same thing. I cannot immagine that
>language developers
>have never thought of this. A synonym type would be reduced to a syntactic
>issue. What
>do we lose that way?
>
>

I have not seen the following amongst the replies to Erik posted so far:

I have always assumed that the principle of type checking via type name
equality rather than by equality following reduction to a canonical 'base
representation' is desirable because it allows a programmer (software
engineer) to distinguish types that are non-equivalent in the problem
semantic domain (eg number of oranges and size of a file in bytes) but have
identical representations in the implementation (eg int). The compiler can
then help to ensure that one kind of data is not mistakenly used in place
of the other.

[Although I quite enjoy 'dangerous', 'low-level' programming (eg
dynamically typed, or untyped code), I also firmly believe that one of the
great potentials of computer tools that help us to use computers, eg
compilers, is to prevent us making silly mistakes wherever it is possible
to do so (strong static type checking being a prime example).]


Regards   Simon

Dr Simon B Jones
Dept of Computing Science
             and Mathematics    | Email: sbj@cs.stir.ac.uk
University of Stirling          | URL: http://www.cs.stir.ac.uk/~sbj
Stirling                        | Tel: (UK) 01786 467434 (Int) +44 1786 467434
SCOTLAND  FK9 4LA               | Fax: (UK) 01786 464551 (Int) +44 1786 464551