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

Chaddaï Fouché chaddai.fouche at gmail.com
Wed Jul 23 12:40:02 UTC 2014


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ï
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140723/a9425507/attachment-0001.html>


More information about the Beginners mailing list