[Haskell-beginners] Getting the Takusen example code to compile -failed import problem

Bayley, Alistair Alistair.Bayley at invesco.com
Fri Aug 7 03:47:48 EDT 2009


> -----Original Message-----
> From: Daniel Everett [mailto:djeinbrum at yahoo.co.uk] 
> 
> OK, this now compiles thanks to (a) hacking Setup.hs to refer 
> to odbc_config rather than odbcconf and (b) unregistering the 
> user packages with ghc-pkg --user unregister Takusen.

Please create a darcs patch for Setup.hs and send it to me. IIRC, you
were on Linux? I'm not sure if Takusen has been tested under Linux.
We've receieved patches for OSX, Oleg uses BSD, and I have Windows, so
it would be useful to get patches for Linux installs too.


> create table dummy (id int primary key);

> query1Iteratee :: (Monad m) => Int -> String -> Double -> 
> IterAct m [(Int, String, Double)]
> query1Iteratee a b c accum = result' ((a, b, c):accum)

>    r <- doQuery (sql "select id from dummy") query1Iteratee []
>    liftIO(putStrLn(show r))
>  )

> fromUTF8Ptr: zero byte found in string as position 8
> 
> Is there any thing wrong with the above code?

Yes. The iteratee function expects three columns in the result-set (with
types Int, String, and Double, in that order), but your query only
provides one column (dummy, of type Int).

There is the beginnings of some code in a couple of the backends to
validate the iteratee against the actual result-set, but it's nowhere
near complete. So if you have a mismatch between iteratee and query,
then you are likely to get marshaling erros and/or garbage. Note that
it's OK to have a result-set return more columns than the iteratee
consumes, but obviously to converse cannnot work.


> Also, what does liftIO actually do?

The monad that your database session is in is a ReaderT wrapper over IO.
In order to perform actions that run in the IO monad, you need to "lift"
them.
  http://www.haskell.org/haskellwiki/Monad_Transformers_Explained


Alistair
*****************************************************************
Confidentiality Note: The information contained in this message,
and any attachments, may contain confidential and/or privileged
material. It is intended solely for the person(s) or entity to
which it is addressed. Any review, retransmission, dissemination,
or taking of any action in reliance upon this information by
persons or entities other than the intended recipient(s) is
prohibited. If you received this in error, please contact the
sender and delete the material from any computer.
*****************************************************************



More information about the Beginners mailing list