[Haskell-cafe] Re: Proposal: TypeDirectedNameResolution

Heinrich Apfelmus apfelmus at quantentunnel.de
Tue Jul 28 04:41:28 EDT 2009

Cale Gibbard wrote:
> There was a great related idea on #haskell the other day: Make
> explicit qualification unnecessary whenever there is a *unique* choice
> of module qualifications from those imported which would make the
> expression typecheck. Ambiguities would still need to be qualified,
> but I feel that this would eliminate 99% of all ugly qualified names
> from code. It would be especially good in the case of infix operators,
> which as far as I know, nobody actually enjoys qualifying explicitly.
> [...]
> What do people think of this idea? Personally, it really annoys me
> whenever I'm forced to give explicit module qualifications, and I
> think this would really help. It would also subsume the
> DisambiguateRecordFields extension rather handily.

While I do agree that qualified names are annoying at times, I think
that type directed name disambiguation is a Pandora's box.

Furthermore, we already have a mechanism for type based disambiguation,
namely good old type classes. For instance, the qualifications required
when importing  Data.Map  are actually a sign that we are lacking proper
container type classes à la Edison.

There are other possible language extension that may make qualification
easier, Pascal's  with  statement comes to mind.


In Haskell, this would work something like this:

  histogram xs =
      with Data.Map
          foldl' f empty xs
              f m x = case lookup m x where
                         Just k  -> insertWith x (+1) m
                         Nothing -> insert x 1 m

In the scope of  with , ambiguous qualifications default to  Data.Map .



More information about the Haskell-Cafe mailing list