Haskell Ambiguous Occurrences — how to avoid?

The types are clearly different but Haskell doesn’t allow ad-hoc overloading of names, so you can only choose one lookup to be used without a prefix.

The typical solution is to import Data.Map qualified:

> import qualified Data.Map as Map

Then you can say

> lookup 1 [(1,2), (3,4)]
Just 2
> Map.lookup 1 Map.empty
Nothing

Usually, Haskell libraries either avoid re-using names from the Prelude, or else re-use a whole bunch of them. Data.Map is one of the second, and the authors expect you to import it qualified.

[Edit to include ephemient’s comment]

If you want to use Data.Map.lookup without the prefix, you have to hide Prelude.lookup since it’s implicitly imported otherwise:

import Prelude hiding (lookup) 
import Data.Map (lookup)

This is a bit weird but might be useful if you use Data.Map.lookup a whole bunch and your data structures are all maps, never alists.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)