I have these functions in Haskell:
type World = [String]
look :: World -> IO World
look w = do
putStrLn $ "You are here " ++ show w
return w
test w = do
words <- fmap words getLine
case words of
("quit":_) -> return ()
("look":_) -> do w' <- area w'; describe w'
("remove":item:_) -> do w' <- removeItem item w; loop w'
_ -> do putStrLn "Wrong input"; test w
area::String->String
area place =
return place
describe:: String ->String
describe place =
case place of
"usa" -> putStrLn "It is usa"
"uk" -> putStrLn "It is uk"
"aur" -> putStrLn "It is aus"
main = do
let world0 = ["ht", "alt"]
let place = ["usa"]
area place
print place
test world0
In the line
("look":_) -> do w' <- area w'; describe w'
I want to call the "area" function that returns a place entered in main and the describe function to return the description for that place. How can I do that?
areaanddescribehave the typesString -> IO StringandString -> IO ()respectively? You're usingreturnandputStrLnin these functions, so they have to return a monadic value