On 15-May-2000, Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> wrote:
> On Mon, 15 May 2000, S.D.Mechveliani wrote:
> 
> >    import Prelude ( tail, (.) )   -- List(..) ?
> 
> [](..) or []([],(:))
> And also: ()(..) or ()(())
> 
> AFAIR the report says that : is a special syntax that always refers to the
> Prelude thing, for consistency with the rest of the list syntax. But in
> GHC (:) must be imported like other constructors, where other list
> constructions are indeed magical - hmm, I guess GHC is not right here and
> should always understand (:).

The report is actually a bit unclear: it says that `:' is a special
syntax, and it gives a definition of `:' in the Prelude, but it
doesn't actually say that `:' always refers to the Prelude version.

It's not clear from the report what is supposed to happen if you write

        import Prelude ()
        nil :: [a]
        nil = []

or

        import Prelude ()
        cons :: a -> [a]
        cons h t = h : t

The report says "every name explicitly mentioned by the source code
must be either defined locally or imported from another module" (5.3.3),
but it seems that the special syntax `[]' and `:' are not "names" (2.4),
so I guess this rule does not apply to them.  However, it would
help a lot if the report was clearer about this point.
The existing implementations I tried behave differently.

Hugs allows the first example, but rejects the second, which seems
quite inconsistent.

ghc rejects them both, which is at least consistent, but goes against
my interpretation of 5.3.3.  Also, that approach is not a complete
solution unless you also extend the syntax of imports and exports to
allow (:) and [] to be explicitly imported and exported, as ghc seems
to have done.  If you take this approach but omit the extension, then
`import Prelude (...)' becomes unusable, and instead you have to just
use `import qualified Prelude'.

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.

Reply via email to