[Haskell-beginners] Issue with lazy eval + trace

Hugo Ferreira hmf at inescporto.pt
Mon Nov 7 09:41:24 CET 2011


Hello,

I am using "import Debug.Trace" to debug some code but it is
not working as expected. I believe this is due to lazy evaluation.
But I cannot see how I can circumvent it. To exemplify I have
the following function:

tagFun :: (POSTags -> Tag) -> POSTags -> POSTags
tagFun f corpus = Z.foldlz' tag Z.empty corpus
   where
       tag acc z = Z.insert newTag acc
        where
          (token, correctTag, _proposdTag) = trace "cursor " Z.cursor z
          proposed = trace "proposed tag" (f z)
          newTag = ( token, correctTag, proposed )


If I place tracing at:

       tag acc z = trace ("tag "++token++" = "++ show newTag) Z.insert 
newTag acc

then it works ok. However the lines

          (token, correctTag, _proposdTag) = trace "cursor " Z.cursor z
          proposed = trace "proposed tag" (f z)

don't work. They only appear once. I assume they should appear with
every element in the zipper. Can anyone explain why?

TIA,
Hugo F.






More information about the Beginners mailing list