[Haskell-cafe] x -> String
Andrew Coppin
andrewcoppin at btinternet.com
Fri Oct 16 14:40:16 EDT 2009
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...
More information about the Haskell-Cafe
mailing list