Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Nested Iterations with Takusen (Pepe Barbe)
2. [email protected] is inviting you to freecharge.in
([email protected])
----------------------------------------------------------------------
Message: 1
Date: Mon, 18 Apr 2011 09:46:04 -0500
From: Pepe Barbe <[email protected]>
Subject: [Haskell-beginners] Nested Iterations with Takusen
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
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
------------------------------
Message: 2
Date: Mon, 18 Apr 2011 23:26:46 +0530 (IST)
From: [email protected]
Subject: [Haskell-beginners] [email protected] is inviting you to
freecharge.in
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110418/1060331e/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 34, Issue 31
*****************************************