[Haskell-beginners] lazy database queries

Michael Hendricks michael at ndrix.org
Thu Jul 29 10:04:35 EDT 2010

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