[Haskell-beginners] lazy database queries

Michael Hendricks michael at ndrix.org
Thu Jul 29 18:24:57 EDT 2010


Thanks Gabríel.  That's exactly what I was looking for.  I had avoided
the docs for System.IO.Unsafe since "unsafe" scared me away :-)

I've cc'd the list so that others can find your excellent answer in
the archives later.

-- 
Michael

On Thu, Jul 29, 2010 at 03:32:25PM +0000, "Gabríel A. Pétursson" wrote:
>  You might be interested in unsafeInterleaveIO in the module
> System.IO.Unsafe
> <http://users.skynet.be/jyp/html/base/System-IO-Unsafe.html>.
> 
> On 29.07.2010 14:04, Michael Hendricks wrote:
> >I have a data structure roughly like
> >
> >     data Prices = Prices {
> >         today    :: [Price],
> >         thisYear :: [Price]
> >     }
> >
> >Both today and thisYear are initially populated by database queries
> >using HDBC.  I then have functions which call today and possibly call
> >thisYear.  thisYear is not called often and the query to retrieve that
> >data is very expensive.
> >
> >I thought I could use HDBC's laziness to postpone actually running the
> >slow query until thisYear was required.  Attempts with quickQuery
> >suggest that the query is executed immediately and the only laziness
> >is with fetching the results.
> >
> >Is it possible to make thisYear a lazy list which only executes the
> >query if thisYear's values are required?
> >
> >Thank you.


More information about the Beginners mailing list