> I just reread Dima's answer to my query about the database access in
> particular and am confused. Dima says that he can't allow queries
> outside the IOMonad because he has to worry about freeing memory (query
> output).
>
> However, Haskell/Com (built on top of Greencard?) seems to be able to
> propagate garbage collection information from Haskell to C so that
> when a Haskell/COM Object is no longer in use, there is some functionality
> decrements its reference counter automatically.
>
> How does this work? and can dima use this mechamism to free queries
> when they are no longer needed? ..allowing database queries outside
> the IOMonad?
I think all you need is something like this:
query :: String -- The query
-> [Result] -- The result
query q = unsafePerformIO (do {
server <- connect "foo.bax.com";
result <- sendQuery server q;
disconnect server;
return result
})
A use of unsafePerformIO :: IO a -> a is a promise that the
enclosed action is indeed a function. I.e. the proof obligation
is yours. That's what you say you want here.
And, yes, the garbage collection should be OK.
Simon