Proposal: Show and Read for Data.Ord.Down

Hello, I propose to add derived Show and Read instances to Data.Ord.Down. This should be uncontroversial. Any thoughts? For reference, Data.Ord.Down is currently defined as newtype Down a = Down a deriving (Eq) instance Ord a => Ord (Down a) where compare (Down x) (Down y) = y `compare` x Krzysztof Gogolewski

Hi, Am Mittwoch, den 25.09.2013, 15:17 +0200 schrieb Krzysztof Gogolewski:
I propose to add derived Show and Read instances to Data.Ord.Down. This should be uncontroversial. Any thoughts?
I could imagine that such instances were intentionally not put there because the author of Down has intended it to be used only “temporarily”, e.g. map (\(Down x) -> x) . sort . map Down so the absence of the instances encourage that usage pattern. Not sure though if base should be encouraging certain usage patterns. Also, Show is useful for debugging. A mildly positive *shrug* from me. Greetings Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • http://www.joachim-breitner.de/ Jabber: nomeata@joachim-breitner.de • GPG-Key: 0x4743206C Debian Developer: nomeata@debian.org

I strongly favor creating instances like this. Not having them just makes the world more painful to debug code to make a normative point and leads to greater code fragmentation when someone else has another stance. -Edward
On Sep 25, 2013, at 4:36 PM, Joachim Breitner
wrote: Hi,
Am Mittwoch, den 25.09.2013, 15:17 +0200 schrieb Krzysztof Gogolewski:
I propose to add derived Show and Read instances to Data.Ord.Down. This should be uncontroversial. Any thoughts?
I could imagine that such instances were intentionally not put there because the author of Down has intended it to be used only “temporarily”, e.g. map (\(Down x) -> x) . sort . map Down so the absence of the instances encourage that usage pattern.
Not sure though if base should be encouraging certain usage patterns. Also, Show is useful for debugging.
A mildly positive *shrug* from me.
Greetings Joachim
-- Joachim “nomeata” Breitner mail@joachim-breitner.de • http://www.joachim-breitner.de/ Jabber: nomeata@joachim-breitner.de • GPG-Key: 0x4743206C Debian Developer: nomeata@debian.org _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On 2013-09-26 06:50, Edward A Kmett wrote:
I strongly favor creating instances like this.
Not having them just makes the world more painful to debug code to make a normative point and leads to greater code fragmentation when someone else has another stance.
I agree. Being able to look at some value "the dirty way" is an important use case of Show (be it as a return value or via trace), and I see no reason for any datatype to not support Show when it could. On Read I don't have an opinion because I usually try to avoid it :-) +1 David/quchen

On 26 September 2013 18:03, David Luposchainsky
On 2013-09-26 06:50, Edward A Kmett wrote:
I strongly favor creating instances like this.
Not having them just makes the world more painful to debug code to make a normative point and leads to greater code fragmentation when someone else has another stance.
I agree. Being able to look at some value "the dirty way" is an important use case of Show (be it as a return value or via trace), and I see no reason for any datatype to not support Show when it could.
On Read I don't have an opinion because I usually try to avoid it :-)
+1
+1 from me as well; furthermore, how about an "unDown :: Down a -> a" record function or some such just to avoid the "\(Down x) -> x" usage like how Krzysztof described? -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com

On Thu, Sep 26, 2013 at 06:16:57PM +1000, Ivan Lazar Miljenovic wrote:
+1 from me as well; furthermore, how about an "unDown :: Down a -> a" record function or some such just to avoid the "\(Down x) -> x" usage like how Krzysztof described?
I vote for `getDown` as it's just not often enough I feel like my Haskell code is instructing me to party.

On Fri, Sep 27, 2013 at 1:23 AM, Ben Millwood
On Thu, Sep 26, 2013 at 06:16:57PM +1000, Ivan Lazar Miljenovic wrote:
+1 from me as well; furthermore, how about an "unDown :: Down a -> a" record function or some such just to avoid the "\(Down x) -> x" usage like how Krzysztof described?
I vote for `getDown` as it's just not often enough I feel like my Haskell code is instructing me to party.
Calling it 'getDown' would also be consistent with the newtypes in Data.Monoid. Erik

+1 for getDown
On Thu, Sep 26, 2013 at 7:23 PM, Ben Millwood
On Thu, Sep 26, 2013 at 06:16:57PM +1000, Ivan Lazar Miljenovic wrote:
+1 from me as well; furthermore, how about an "unDown :: Down a -> a" record function or some such just to avoid the "\(Down x) -> x" usage like how Krzysztof described?
I vote for `getDown` as it's just not often enough I feel like my Haskell code is instructing me to party.
______________________________**_________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/**mailman/listinfo/librarieshttp://www.haskell.org/mailman/listinfo/libraries

On 2013-09-27 23:55, David Luposchainsky wrote:
On 2013-09-27 23:41, Bardur Arantsson wrote:
This kind of makes me wish there was an Up newtype.
Before somebody suggests renaming Identity, let's stop the bikeshedding and push this trivial change?
I don't really think humour (or attempts at such) count as bikeshedding, but whatevs... :) +1 to the OP.

Over 2 weeks passed; by my count there are five +1 votes to the
original proposal (adding Show and Read instances), and one mildly
positive shrug. I committed the change in
base/ebc85262ccfbb65db71d7fdff7a35c8178b99f18.
2013/9/28 Bardur Arantsson
On 2013-09-27 23:55, David Luposchainsky wrote:
On 2013-09-27 23:41, Bardur Arantsson wrote:
This kind of makes me wish there was an Up newtype.
Before somebody suggests renaming Identity, let's stop the bikeshedding and push this trivial change?
I don't really think humour (or attempts at such) count as bikeshedding, but whatevs... :)
+1 to the OP.
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On Thu, Sep 26, 2013 at 06:16:57PM +1000, Ivan Lazar Miljenovic wrote:
On 26 September 2013 18:03, David Luposchainsky
wrote: On 2013-09-26 06:50, Edward A Kmett wrote:
I strongly favor creating instances like this.
Not having them just makes the world more painful to debug code to make a normative point and leads to greater code fragmentation when someone else has another stance.
I agree. Being able to look at some value "the dirty way" is an important use case of Show (be it as a return value or via trace), and I see no reason for any datatype to not support Show when it could.
On Read I don't have an opinion because I usually try to avoid it :-)
+1
+1 from me as well; furthermore, how about an "unDown :: Down a -> a" record function or some such just to avoid the "\(Down x) -> x" usage like how Krzysztof described?
Making it a field will complicate the derived Read and Show instances. That can be avoided by adding it as a separate function.

I agree. I really do wish that derived Read/Show for single-parameter
constructors didn't try to show the record syntax.
There is another approach:
I often just wind up writing the 4 lines of Read/Show for simple data types
/ newtypes.
This avoids cluttering my debugging output, while keeping it as a field
accessor so end users can still just
import Foo (Down(..))
and be sure getDown comes along for the ride.
-Edward
On Fri, Sep 27, 2013 at 5:06 AM, Ross Paterson
On Thu, Sep 26, 2013 at 06:16:57PM +1000, Ivan Lazar Miljenovic wrote:
On 26 September 2013 18:03, David Luposchainsky
wrote: On 2013-09-26 06:50, Edward A Kmett wrote:
I strongly favor creating instances like this.
Not having them just makes the world more painful to debug code to make a normative point and leads to greater code fragmentation when someone else has another stance.
I agree. Being able to look at some value "the dirty way" is an important use case of Show (be it as a return value or via trace), and I see no reason for any datatype to not support Show when it could.
On Read I don't have an opinion because I usually try to avoid it :-)
+1
+1 from me as well; furthermore, how about an "unDown :: Down a -> a" record function or some such just to avoid the "\(Down x) -> x" usage like how Krzysztof described?
Making it a field will complicate the derived Read and Show instances. That can be avoided by adding it as a separate function. _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On 26 September 2013 20:59, Herbert Valerio Riedel
On 2013-09-25 at 15:17:30 +0200, Krzysztof Gogolewski wrote:
Hello,
I propose to add derived Show and Read instances to Data.Ord.Down. This should be uncontroversial. Any thoughts?
...wouldn't that require the wrapped type to provide 'Show' as well?
Yes, same as for Maybe, etc. ...
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com

That's exactly the derived instance that would be generated:
instance Show a => Show (Down a) where
...
Erik
On Thu, Sep 26, 2013 at 12:59 PM, Herbert Valerio Riedel
On 2013-09-25 at 15:17:30 +0200, Krzysztof Gogolewski wrote:
Hello,
I propose to add derived Show and Read instances to Data.Ord.Down. This should be uncontroversial. Any thoughts?
...wouldn't that require the wrapped type to provide 'Show' as well? _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On 26 September 2013 22:12, Herbert Valerio Riedel
On 2013-09-26 at 13:15:00 +0200, Erik Hesselink wrote:
That's exactly the derived instance that would be generated:
instance Show a => Show (Down a) where ...
...in that case, +1 from me :-)
(I assumed wrongly this was about adding "derived (Show,Read)" to 'Down')
It is.... that's just what the derived instance would be. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com
participants (11)
-
Bardur Arantsson
-
Ben Millwood
-
David Luposchainsky
-
Edward A Kmett
-
Edward Kmett
-
Erik Hesselink
-
Herbert Valerio Riedel
-
Ivan Lazar Miljenovic
-
Joachim Breitner
-
Krzysztof Gogolewski
-
Ross Paterson