[Haskell-beginners] How to show a record

Francesco Ariis fa-ml at ariis.it
Sun Aug 17 12:57:18 UTC 2014


On Sun, Aug 17, 2014 at 12:08:57PM +0100, Karolis Velicka wrote:
> In that case, can you elaborate please? I don't see how this is different
> to making the record itself an instance if Show.

If by "no difference" you mean "equivalent output", I guess we can ditch
Haskell and write programs in Basic.

What Martin is asking for is how you could implement such a feature if
something like |deriving (Show)| weren't there.

On 17 Aug 2014 10:44, "martin" <martin.drautzburg at web.de> wrote:
> Right, but this is merely a coincidence.
>
> What I wanted is a way to show a value of a record, where all fields are
> instances of Show.
>
> Haskell itself is able to do this (and it even figures out the accessors,
> which I am not even asking for).

Martin, as far as I know this is not possible in standard ^Haskell 2010^ [1].
To perform this kind of magic people use ^Template Haskell^ [2], which is,
in so many words, a meta programming extension for GHC; with it you can
handle and go-back-and-forth between Concrete Syntax and the Abstract Syntax
Tree.
Template Haskell isn't type safe and that goes "against the grain" of
Haskell-the-language itself, I suppose (for sure it goes against mine);
it is used in some popular libraries (e.g. lens, yesod).


[1] http://www.haskell.org/onlinereport/haskell2010/
[2] http://www.haskell.org/haskellwiki/Template_Haskell
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140817/b5bbac06/attachment.sig>


More information about the Beginners mailing list