
Not sure what's going on here. Doesn't like line 5, the type statement. And what's with the semicolons in that line and in function main? Michael ========= From: http://www.haskell.org/ghc/docs/6.10.3/html/libraries/mtl/Control-Monad-Read... import Control.Monad.Reader import qualified Data.Map as Map import Data.Maybe type Bindings = Map String Int; -- Returns True if the "count" variable contains correct bindings size. isCountCorrect :: Bindings -> Bool isCountCorrect bindings = runReader calc_isCountCorrect bindings -- The Reader monad, which implements this complicated check. calc_isCountCorrect :: Reader Bindings Bool calc_isCountCorrect = do count <- asks (lookupVar "count") bindings <- ask return (count == (Map.size bindings)) -- The selector function to use with 'asks'. -- Returns value of the variable with specified name. lookupVar :: String -> Bindings -> Int lookupVar name bindings = fromJust (Map.lookup name bindings) sampleBindings = Map.fromList [("count",3), ("1",1), ("b",2)] main = do putStr $ "Count is correct for bindings " ++ (show sampleBindings) ++ ": "; putStrLn $ show (isCountCorrect sampleBindings); ========== Prelude> :l monad5 [1 of 1] Compiling Main ( monad5.hs, interpreted ) monad5.hs:5:16: Not in scope: type constructor or class `Map' Failed, modules loaded: none.

Because Data.Map is imported qualified, any symbols in it (including Map) needs to be qualified: type Bindings = Map.Map String Int A standard idiom is to do import like so: import qualified Data.Map as Map import Map (Map) so that the Map symbol itself does not need qualification. Eric

On Thu, 30 Dec 2010 08:01:01 -0800 (PST)
michael rice
Not sure what's going on here. Doesn't like line 5, the type statement. And what's with the semicolons in that line and in function main?
import Control.Monad.Reader import qualified Data.Map as Map import Data.Maybe
type Bindings = Map String Int;
. The right hand side should be "Map.Map String Int"; alternatively add an unqualified import above for just the Map type:
import Data.Map(Map)
The semicolon is optional---the layout rule will insert it if you leave it out. Pedro

Thanks, all.
Just tried
type Bindings = Map.Map String Int
and it also seems to work.
Michael
--- On Thu, 12/30/10, Pedro Vasconcelos
Not sure what's going on here. Doesn't like line 5, the type statement. And what's with the semicolons in that line and in function main?
import Control.Monad.Reader import qualified Data.Map as Map import Data.Maybe
type Bindings = Map String Int;
. The right hand side should be "Map.Map String Int"; alternatively add an unqualified import above for just the Map type:
import Data.Map(Map)
The semicolon is optional---the layout rule will insert it if you leave it out. Pedro _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Eric Stansifer
-
michael rice
-
Pedro Vasconcelos