[Haskell-cafe] Not in scope: type constructor or class `Map'
michael rice
nowgate at yahoo.com
Thu Dec 30 17:01:01 CET 2010
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-Reader.html
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20101230/ba359ca1/attachment.htm>
More information about the Haskell-Cafe
mailing list