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?
You need to use
import qualified Control.Monad.State as S. Skippingqualifiedkeyword brings into scope bothS.getandget, etc.See 5.3.2 and 5.3.4 of Haskell 2010 report.