[Haskell-beginners] Manage the type of a variable in the show implementation

Christian Sperandio christian.sperandio at gmail.com
Wed Jul 23 13:04:29 UTC 2014


I chose the newtype solution.

Thanks :)



2014-07-23 14:40 GMT+02:00 Chaddaï Fouché <chaddai.fouche at gmail.com>:

> On Wed, Jul 23, 2014 at 2:20 PM, Christian Sperandio <
> christian.sperandio at gmail.com> wrote:
>
>> I know the quote problem comes from the show function on String value.
>> How could I do a show for no-string values and return directly the value
>> for strings?
>>
>
> You can't ! (ok you can but you'll need to use OverlappingInstances)
>
> Anyway, using Show for this is wrong, Show is supposed to translate
> datatypes in a form you could copy in your code to get the value back, it
> isn't supposed to be for presentation. You have libraries that do pretty
> formatting better.
>
> If you absolutely want this, I would suggest writing another class for it
> and use OverlappingInstances to allow for one "DataLog String" instance and
> one "(Show a) => YourClass (DataLog a)" instance.
>
> Another possibility is to do a newtype for strings that have a Show
> instance that doesn't put quotes around. That might even be a better idea,
> maybe your Strings really represent variables or something in this case
> anyway ?
> --
> Jedaï
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140723/ee19c14d/attachment.html>


More information about the Beginners mailing list