Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Ambiguous occurrence" error even after a qualified import

Tags:

haskell

Here is a snippet of my code:

import Control.Monad.State as S
get x = x + 1

Now if I try to use get, I get the following error:

Ambiguous occurrence `get'
It could refer to either `Main.get', defined at twitter.hs:59:1
                      or `S.get',
                         imported from Control.Monad.State at twitter.hs:15:1-31

Since I imported Control.Monad.State as a qualified module, shouldn't it automatically pick the get function in Main? Why is it running into this conflict? How can I fix it?

like image 958
Vlad the Impala Avatar asked Dec 22 '22 07:12

Vlad the Impala


1 Answers

You need to use import qualified Control.Monad.State as S. Skipping qualified keyword brings into scope both S.get and get, etc.

If the import declaration used the qualified keyword, only the qualified name of the entity is brought into scope. If the qualified keyword is omitted, then both the qualified and unqualified name of the entity is brought into scope.

See 5.3.2 and 5.3.4 of Haskell 2010 report.

like image 136
Cat Plus Plus Avatar answered Jan 21 '23 14:01

Cat Plus Plus