[Haskell-cafe] Re: language proposal: ad-hoc overloading

John Smith voldermort at icmail.net
Sat Sep 6 19:09:23 EDT 2008

Ryan Ingram wrote:
> module Prob where
> import qualified Data.Map as M
> ....
> newtype Prob p a = Prob { runProb :: [(a,p)] }
> combine :: (Num p, Ord a) => Prob p a -> Prob p a
> combine m = Prob $
>     M.assocs $
>     foldl' (flip $ uncurry $ M.insertWith (+)) M.empty $
>     runProb m
> Do you see it?  All those "M." just seem dirty to me, especially
> because the compiler should be able to deduce them from the types of
> the arguments.

May I humbly suggest a much simpler solution to your problem: if an identifier is ambiguous, the compiler will use the 
last import. So, in your example, the compiler will assume that any instance of empty is Data.Map.empty

Some means of using an imported module as the default namespace, and requiring the Prelude to be qualified, may also help.

More information about the Haskell-Cafe mailing list