[Haskell-beginners] A first try

Manfred Lotz manfred.lotz at arcor.de
Mon Jun 27 04:57:06 CEST 2011

On Sun, 26 Jun 2011 17:32:02 -0400
David Place <d at vidplace.com> wrote:

> On Jun 26, 2011, at 4:59 PM, Manfred Lotz wrote:
> > Is there any problem in the code snippet I pasted? If so I would
> > like to get a hint of course.
> There really isn't enough code in your snippet to be able to say.
> The rule is that if you return a lazy data structure from withFile
> you may find the file has been closed before you have read the data.
> If your parseXMLDoc is strict then you will get away with it.   I
> feel that isn't very nice.

What I had learned (and it seems to work fine) is to force the result
which gets done here in return $!

insertXml (stat, m) xf =
  U.withBinaryFile xf ReadMode
     (\handle -> do ct <- getXmlContent xf handle
          ... some code...   
         return $! (stat',m'))

So I hope that is the one and important recipe to add when using


More information about the Beginners mailing list