
Hello everyone, I am new to Haskell and I am trying to use the Takusen library to query an SQL database. My desire is two perform a two level query query where the first query will iterate through some values that will be used in the second level to get the data of interest. I am having issues with the types and I haven't been able to figure out what am I doing wrong. Below is some sample code that shows the problem I am dealing with: -- sample.hs import Database.PostgreSQL.Enumerator import Database.Enumerator db_host = CAhost "host" db_user = CAuser "user" db_password = CApassword "pass" db_name = CAdbname "name" db_auth_tokens = [db_user, db_password, db_host, db_name] connection = connect db_auth_tokens secondLevelQuery :: IO Integer secondLevelQuery = do let query = sql "SELECT count(*) from alarms" iter :: Monad m => Integer -> IterAct m Integer iter count _ = result' count withSession connection (doQuery query iter 0) firstLevelQuery :: IO (Integer, Integer) firstLevelQuery = do let query = sql "SELECT count(*) from alarms" iter :: Monad m => Integer -> IterAct m (Integer, Integer) iter count _ = do count' <- secondLevelQuery result' (count', count) withSession connection (doQuery query iter (0,0)) main = firstLevelQuery -- end sample.hs And the output from ghc is: sample.hs:23:31: Could not deduce (m ~ IO) from the context (Monad m) bound by the type signature for iter :: Monad m => Integer -> IterAct m (Integer, Integer) at sample.hs:(22,7)-(24,43) `m' is a rigid type variable bound by the type signature for iter :: Monad m => Integer -> IterAct m (Integer, Integer) at sample.hs:22:7 Expected type: m Integer Actual type: IO Integer In a stmt of a 'do' expression: count' <- secondLevelQuery In the expression: do { count' <- secondLevelQuery; result' (count', count) } In an equation for `iter': iter count _ = do { count' <- secondLevelQuery; result' (count', count) } I would appreciate any help in figuring out what am I doing wrong. Thanks, Pepe