
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?

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"
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@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Your particular types do not require your annoying repetition beyond
[ show . pType, accepts, produces, workarea] with 1st show = (:[])
On Sat, Aug 16, 2014 at 10:45 AM, martin
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@haskell.org http://www.haskell.org/mailman/listinfo/beginners

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). Am 08/16/2014 12:39 PM, schrieb Roman Czyborra:
Your particular types do not require your annoying repetition beyond [ show . pType, accepts, produces, workarea] with 1st show = (:[])
On Sat, Aug 16, 2014 at 10:45 AM, martin
mailto:martin.drautzburg@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@haskell.org mailto:Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

In that case, can you elaborate please? I don't see how this is different
to making the record itself an instance if Show.
Best wishes,
Karolis Velicka
On 17 Aug 2014 10:44, "martin"
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).
Your particular types do not require your annoying repetition beyond [ show . pType, accepts, produces, workarea] with 1st show = (:[])
On Sat, Aug 16, 2014 at 10:45 AM, martin
mailto:martin.drautzburg@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
Am 08/16/2014 12:39 PM, schrieb Roman Czyborra: 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@haskell.org mailto:Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

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"
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

I think what Martin is aiming at is heterogeneous collections.
http://www.haskell.org/haskellwiki/Heterogenous_collections
As you can see from the article, you can do "the same thing" to a bunch of
objects of different types, but you've still got to "pack" them explicitly
first. So in this particular case the answer is that it's not worth the
effort. This may seem ridiculous, but it turns out that Haskell's approach
gives you a lot of power in other areas.
Julian
On 17 August 2014 13:57, Francesco Ariis
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"
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
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Am 08/17/2014 06:46 PM, schrieb Julian Birch:
I think what Martin is aiming at is heterogeneous collections. http://www.haskell.org/haskellwiki/Heterogenous_collections
As you can see from the article, you can do "the same thing" to a bunch of objects of different types, but you've still got to "pack" them explicitly first. So in this particular case the answer is that it's not worth the effort. This may seem ridiculous, but it turns out that Haskell's approach gives you a lot of power in other areas.
Julian
On 17 August 2014 13:57, Francesco Ariis
mailto:fa-ml@ariis.it> wrote: 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.
Thanks for pointing out Heterogenous_collections to me.
participants (5)
-
Francesco Ariis
-
Julian Birch
-
Karolis Velicka
-
martin
-
Roman Czyborra