[Takusen] Nested Iterations with Takusen

Pepe Barbe elventear at gmail.com
Tue Apr 19 14:52:56 BST 2011


On Apr 18, 2011, at 11:08 PM, Jason Dagit wrote:

> I think what GHC is trying to say is that you've declared something to work
> for all Monads m, but you're also requiring it to work for IO.  In
> particular, using withSession inside secondLevelQuery forces
> secondLevelQuery to use the IO monad.
> 
> So then in firstLevelQuery, this line:
> count' <- secondLevelQuery
> 
> Forces iter to only work for the IO monad.  GHC is complaining because iter
> was declared to work for all monads but the way it's implemented forces it
> to only work for the IO monad.
> 
> If you change it to:
> iter :: Integer -> IterAct IO (Integer, Integer)
> 
> Does your type error go away?

It doesn't work, I get the following error:

sample.hs:27:27:
    No instance for (Database.Enumerator.QueryIteratee
                       (DBM mark Session)
                       Database.PostgreSQL.Enumerator.Query
                       (IO (IterResult (Integer, Integer)))
                       (Integer, Integer)
                       Database.PostgreSQL.Enumerator.ColumnBuffer)
      arising from a use of `doQuery'
    Possible fix:
      add an instance declaration for
      (Database.Enumerator.QueryIteratee
         (DBM mark Session)
         Database.PostgreSQL.Enumerator.Query
         (IO (IterResult (Integer, Integer)))
         (Integer, Integer)
         Database.PostgreSQL.Enumerator.ColumnBuffer)
    In the second argument of `withSession', namely
      `(doQuery query iter (0, 0))'
    In the expression:
      withSession connection (doQuery query iter (0, 0))
    In the expression:
      do { let query = sql "SELECT count(*) from alarms"
               iter :: Integer -> IterAct IO (Integer, Integer)
               ....;
           withSession connection (doQuery query iter (0, 0)) }

I am already using an alternative using mapM and two functions similar to the firstLevel and secondLevel that are not nested. This question is more about the fundamentals and because am new to Haskell and Takusen.

I thought doing these nested queries would be an ok idea, but it doesn't seem to be so easy. So another question I have is if what I was proposing initially, doing nested queries, was a good idea or maybe there is a better way of doing what I intended.

Thanks,
Pepe


More information about the Takusen mailing list