[Haskell-cafe] x -> String

Daniel Peebles pumpkingod at gmail.com
Fri Oct 16 15:26:33 EDT 2009


Whoops, sorry about that then!

On Fri, Oct 16, 2009 at 2:59 PM, Ross Mellgren <rmm-haskell at z.odi.ac> wrote:
> Andrew has mentioned the debugger several times, NOT the interactive REPL.
> That is, using :-commands to inspect values.
>
> -Ross
>
> On Oct 16, 2009, at 2:46 PM, Daniel Peebles wrote:
>
>> My GHCi can't do that :o
>>
>> I just wrote data A = B | C and loaded the file into GHCi. Typing B gives
>> me:
>>
>> <interactive>:1:0:
>>   No instance for (Show A)
>>     arising from a use of `print' at <interactive>:1:0
>>   Possible fix: add an instance declaration for (Show A)
>>   In a stmt of a 'do' expression: print it
>>
>> The error also gives an idea of what GHCi is doing behind the scenes:
>> it's just calling print, which has a Show constraint.
>>
>> On Fri, Oct 16, 2009 at 2:40 PM, Andrew Coppin
>> <andrewcoppin at btinternet.com> wrote:
>>>
>>> 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 at haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


More information about the Haskell-Cafe mailing list