[Haskell-cafe] retrospective on 'seq' -> 'unsafeSeq' ?

Ketil Malde ketil at malde.org
Tue Apr 15 02:48:32 EDT 2008

Bernie Pope <bjpop at csse.unimelb.edu.au> writes:

> Of course, [unsafeShow] won't be able to print functions in any helpful way,
> unless we attach source code information to
> functions as well (which may be worth doing anyway?).

It might not be able to print the function's definition, but perhaps
its type?

> One thing to watch out for is cycles in data structures. You may not
> want to try to detect them, but at least you should
> be lazy in generating the printable representation of values.

For debugging output, I find I often limit output to avoid this.
For instance, I defined this helper function for XML parser debugging:

  showSome :: [Tag] -> String
  showSome a@(_:_:_:_:_:_:_) = (init . show . take 5 $ a)++" ... ]"
  showSome a                 = show a

with a typical error call:

  then error ("Couldn't find tag '"++show tag++"' in\n"++showSome list)

Come to think of it, ghci's print-bind-result functionality could benefit
from something like that...

I also think it would be nice if unsafeShow could be available also
in compiled code, not just ghci - e.g. sometimes you might want a mere
user to run your application with debugging turned on. 

If I haven't seen further, it is by standing in the footprints of giants

More information about the Haskell-Cafe mailing list