On 15-May-2000, S.D.Mechveliani <[EMAIL PROTECTED]> wrote:
> I am again stuck. Who could help, please?
>
> module T
> where
> import Prelude ( tail, (.) ) -- List(..) ?
At first glance, I didn't see what the problem was.
But having tried it myself, I see why you're having difficulty.
There's simply no valid syntax in Haskell 98 for naming
the list type constructor (`[]') in a module import or
export list!
Following the grammar in the Haskell 98 Report,
: exports -> ( export1 , ... , exportn [ , ] ) (n>=0)
: export -> qvar
: | qtycon [(..) | ( qcname1 , ... , qcnamen )] (n>=0)
: | qtycls [(..) | ( qvar1 , ... , qvarn )] (n>=0)
: | module modid
: qcname -> qvar | qcon
:
: qtycon -> [modid .] tycon
: tycon -> conid
: conid -> large {small | large | digit | ' }
we see that the name of a (possibly qualified) type constructor
in an export list is a `qtycon', which is an optionally module
qualified `tycon', which is just a `conid', and a `conid'
is just an identifier starting with a capital letter.
The same is true for module imports.
The problem is that although the grammar for types includes a
nonterminal `gtycon' which includes syntax for various special type
constructors,
: gtycon -> qtycon
: | () (unit type)
: | [] (list constructor)
: | (->) (function constructor)
: | (,{,}) (tupling constructors)
the grammar for import and export lists use `tycon'
and `qtycon' (respectively) rather than `gtycon'.
Is there any particular reason for this, or is this
just a defect in the Haskell 98 report?
Would changing `qtycon' to `gtycon' in the
grammar production for `export' cause any problems?
Likewise, how about changing `tycon' in the grammar
production for `import' to say `gutycon', defined by
gutycon -> tycon
| () (unit type)
| [] (list constructor)
| (->) (function constructor)
| (,{,}) (tupling constructors)
?
For Haskell implementations that follow the report,
I don't see any easy work-around for this problem.
The only thing you can do is to use `import qualified Prelude'
rather than `import Prelude(...)'.
The good news is that ghc (4.04) does not follow the Haskell 98
report -- it accepts the following code, apparently as an
extension to Haskell 98 (even without `-fglasgow-exts'):
module Example(Prelude.[](..)) where
import Prelude([](..))
Similarly, it also accepts
module Example(Prelude.[]((:), [])) where
import 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.