X-Comment1: #############################################################
X-Comment2: #     uk.ac.glasgow.cs has changed to uk.ac.glasgow.dcs     #
X-Comment3: #     If this address does not work please ask your mail    #
X-Comment4: #     administrator to update your NRS & mailer tables.     #
X-Comment5: #############################################################


There have been several messages on this list concerning type
synonyms.  To repeat an example, is module B legal?

        module A
          type T = Int
          x :: T
          x = 4

        module B
          import A(x)

The point is that if x::T, then does T need to be in scope in B?

Well, the Haskell report doesn't say!  It only tells you how
to decide if
        a module together with the interfaces it imports
is legal.

If the interface for A reads

        interface A
          x :: Int

then module B is legal.  If the interface reads

        interface A
          x :: T

then module B isn't legal, because it can't figure out what
T is.

====================

What should be said about A's interface?  (The report is rather
ambiguous at present; 5.3.1 (3).)

        - Synonyms should be *allowed* in interfaces, so that
                people can write readable interfaces.

        - Synonyms shouldn't be *compulsory* in interfaces, because
                one cannot infer them unambigously.  What signature
                should y have here, [S] or [T]?

                        type S = Int
                        type T = Int
                        y = [ 1::S, 2::T ]

So I think all the report can say is that synomyms may (but need not)
appear in interface type signatures; but if they do then the closure
rule means that the synonym must be in scope.

I propose to reword 5.3.1 (3) as follows:

        A type signature appears in the interface for every value that the
        implementation exports.  The type expressed by this signature
        must be the same as the most general type inferred from the
        declaration of the value in implementation, after any 
        constraints expressed by explicit type signatures in the 
        implementation have been applied.  

        The type signature in the interface may (but need not) 
        use type synonyms; if any such synonyms are used, then 
        the closure rule (Section 5.1.3) implies that these 
        synonyms must be in scope wherever this value is imported.

This leaves it unspecified how an automatic compilation system
should construct an interface; it can be stupid (expand all synonyms)
or clever (be as synonymic as possible), but the spirit of the Report
is that that is up to the compilation system.

===============

I'm aware that there are still some Prelude-ish questions
remaining concerning synonyms, but is everyone happy with the above?

Simon

Reply via email to