[web-devel] Database connection laziness (yesod)

Jeremy Hughes jedahu at gmail.com
Wed May 18 00:32:06 CEST 2011

Another lazy question:

> fun :: Int -> Int
> foo a = runReader ask (fun a)
> bar a = runReader (return 3) (fun a)

foo causes (fun a) to be evaluated but bar doesn't. Is the same true
for database connections? Are they created lazily?

I ask because it would be neat to be able to write:

> runDB $ getFromCache cache key

where getFromCache queries the DB only on a cache miss, and have a
connection created only in the case of a cache miss.

I have tried test this myself, but I can't get ghci to cooperate and
load yesod from source.



More information about the web-devel mailing list