[nhc-bugs] two problems exportation/importation of field labels.

Feliks Kluzniak feliks@crt.se
Fri, 8 Mar 2002 18:12:30 +0100


Hello!

I think NHC does not properly handle exports and imports of field labels.  


Problem 1
--------

The following two modules seem to be legal according to the Haskell 98 report
(Sec.5.2, p. 66):
    
    ==================================================================
    
    module See1 ( D( Undef, Def, value ) )  where
    
    data  D  =  Undef | Def{ value :: Int }
    
    ------------------------------------------------------------------
    
    module See2 ( foo ) where
    
    import See1 ( D( Undef, Def, value ) )
    
    
    foo ::  D -> Int
    
    foo d  =  case  d
              of
                 Undef  ->  error "no value"
                 Def{}  ->  value d
    
    ==================================================================

Both GHC and Hugs accept this, but NHC reports an error:

    hmake -d../nhc See2.hs
    nhc98    -c -d ../nhc See1.hs
    
    ====================================
    	In file: ./See1.hs:
    1:16 Found ( but expected one of ) ,


If one changes the heading of See1 to

     module See1 ( D( Undef, Def ), value )  where

then one gets

    hmake -d../nhc See2.hs
    nhc98    -c -d ../nhc See2.hs

    ====================================
	    In file: ./See2.hs:
    3:13 Found ( but expected a {-end-of-definition-or-EOF-}



Problem 2
---------

There are no syntactic problems when one uses another, equally legal form: 

    ==================================================================
    
    module See1 ( D( Undef, Def ), value )  where
    
    data  D  =  Undef | Def{ value :: Int }
    
    ------------------------------------------------------------------
    
    module See2 ( foo ) where
    
    import See1 ( D( Undef, Def ), value )
    
    
    foo ::  D -> Int
    
    foo d  =  case  d
              of
                 Undef  ->  error "no value"
                 Def{}  ->  value d
    
    ==================================================================


Again, this is accepted both by GHC and Hugs.  But now NHC has another bone to
pick: 
    
    hmake -d../nhc See2.hs
    nhc98    -c -d ../nhc See2.hs
    
    ====================================
    	Error when renaming::
    Identifier value defined 2 times.

To make this go away, one has to change the importation clause to

    import See1 ( D( Undef, Def ) )

Now everything is OK, and NHC does not complain about the occurrence of "value"
in "foo"!

Regards,
-- Feliks