[Haskell-beginners] How to show a record

Karolis Velicka karolis.velicka at gmail.com
Sat Aug 16 09:45:35 UTC 2014


You can make it derive Show as well as Eq, then you'll have the default
haskell's string representation of your record. You'd only need an
additional function if you wanted to pretty print your records in some
specific, non standard way.

Best wishes,
Karolis Velicka
On 16 Aug 2014 09:49, "martin" <martin.drautzburg at web.de> wrote:

> Hello all,
>
> I have a record type like this
>
>         data Payload = Pl {
>                     pType    :: Char,
>                     accepts  :: String,
>                     produces :: String,
>                     workarea :: String} deriving (Eq)
>
> an I want to write my own show function. I ended up with somethink like
> this
>
>         show pl = concatMap ( $ pl) [show . pType, show . accepts, show .
> produces, show . workarea]
>
> That repetition of "show ." annoys me, but of course without it the
> elements of that list would have different types. Is
> there a way around it and how does haskell itself manage to show records?
> _______________________________________________
> 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/20140816/fd540e34/attachment.html>


More information about the Beginners mailing list