Jochem Berndsen wrote:

I rephrase: There *is* a way to turn arbitrary values into strings. I
know there is, because the GHCi debugger *does* it. The question is,
does anybody know of an /easy/ way to do this?

No. GHCi does not always do this:

Prelude Data.Ratio> let plus1 = (+1)
Prelude Data.Ratio> plus1

<interactive>:1:0:
    No instance for (Show (a -> a))
      arising from a use of `print' at <interactive>:1:0-4
    Possible fix: add an instance declaration for (Show (a -> a))
    In a stmt of a 'do' expression: print it
Prelude Data.Ratio>

The GHCi *debugger* can print out even values for which no Show instance exists. (But yes, it fails to print anything interesting for function types... It works for ADTs that don't have Show though.)

Anybody know of a way to do this? (As it happens, the values I'm testing
with are all Showable anyway, but the type checker doesn't know that...)

What is the problem with adding a function
showMyContainer :: (Show a) => Container a -> String
?
In this case you can show your container (for debugging purposes), but
only if you have Showable elements in your container.

This could plausibly work...

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to