Name: noko-tan 2008-12-16 15:34
Hi guise
wai this code work not as planned
i expect "boo" but it prints Nothing
import System.IO
import Control.Monad
import Data.IORef
import qualified Data.HashTable as HT
type MyTable = HT.HashTable String String
newMyTable :: IO MyTable
newMyTable = HT.new (==) HT.hashString
data App = App {
table :: IO MyTable,
msg :: IO (IORef String)
}
mkApp = App newMyTable (newIORef "")
put app k v = liftM (\t-> HT.insert t k v) (table app)
look app k = join (liftM (\t -> HT.lookup t k) (table app))
main = do
let app = mkApp
put app "foo" "boo"
boo <- look app "foo"
print boo
wai this code work not as planned
i expect "boo" but it prints Nothing
import System.IO
import Control.Monad
import Data.IORef
import qualified Data.HashTable as HT
type MyTable = HT.HashTable String String
newMyTable :: IO MyTable
newMyTable = HT.new (==) HT.hashString
data App = App {
table :: IO MyTable,
msg :: IO (IORef String)
}
mkApp = App newMyTable (newIORef "")
put app k v = liftM (\t-> HT.insert t k v) (table app)
look app k = join (liftM (\t -> HT.lookup t k) (table app))
main = do
let app = mkApp
put app "foo" "boo"
boo <- look app "foo"
print boo