wiki:QualifiedIdentifiers

Version 5 (modified by simonmar@…, 7 years ago) (diff)

fix various inaccuracies

Fix the lexical syntax for qualified identifiers

Ticket: #59

The lexical rules for qualified identifiers lead to some unexpected consequences, and are tricky to implement, such that several existing compilers don't implement them properly.

eg.

  • M.where should be 2 lexemes, M.wher and e. (Hugs treats it as 1, GHC treats it as 3 (see http://hackage.haskell.org/trac/ghc/ticket/1215)).
  • M... should be 2 lexemes, M.. and . (.. is a reserved symbol and can't be qualified, neigther GHC nor Hugs implements this)
  • M.\ should be 2 lexemes, M and .\

The trickiness in implementation is due to the lookahead required.

Fixing the lexical syntax is easy, we define

id -> small {small|large|digit|'}
varid -> id<reservedid>

qvarid -> [ modid . ] id

and similarly for qualified symbols.

See also CompositionAsDot, which supercedes this proposal if adopted.

Cons

  • treating M.where as a qualified variable isn't very useful, since you can't define a variable called where. Perhaps it should be possible to use qualified identifiers in a definition, to make this consistent again?

Pros

  • the consequences of the current lexical syntax are ugly (M.wher e ?) and unintentional.
  • most compilers don't get it right anyway, this is just a small change that makes it easier to implement Haskell.