[Haskell-beginners] database question
gaius at gaius.org.uk
Sat Sep 18 16:30:46 EDT 2010
On 18 Sep 2010, at 21:03, Daniel Fischer wrote:
>> Why does it think that that is the final expression of the function?
> It doesn't, but you said the do-expression had type
> ReaderT Connection (WriterT [String] m) ()
> quickQuery :: IConnection conn =>
> conn -> String -> [SqlValue] -> IO [[SqlValue]]
> The types don't match, hence the error. But you have a MonadIO
> rs <- liftIO $ quickQuery ...
> should fix it.
Aha! It does indeed, thanks :-)
I had assumed that with the rs <- quickQuery I was getting the
[[SqlValue]] "out" of the IO Monad - but I have to lift it into the IO
Monad first, since I am in a monadic context? This would be the non-
module Main where
main:: IO ()
main = do lda <- connectSqlite3 "test.db"
rs <- quickQuery lda "select datetime ('now')" 
mapM_ putStrLn (map convRow rs)
where convRow [x] = (fromSql x)::String
Oh, but I am already in the IO monad there aren't I.... And doQuery
*isn't* but I have declared that it *should be* (e.g. an instance of
typeclass MonadIO). Is that accurate?
>> Any advice greatly appreciated. I have been struggling with this
> Hopefully it didn't stop you from eating.
Nothing could do that :-)
More information about the Beginners