Krzysztof Gogolewski | 25 Sep 15:17 2013
Picon

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
_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Joachim Breitner | 25 Sep 22:36 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

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 <at> joachim-breitner.de • http://www.joachim-breitner.de/
  Jabber: nomeata <at> joachim-breitner.de  • GPG-Key: 0x4743206C
  Debian Developer: nomeata <at> debian.org
_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Edward A Kmett | 26 Sep 06:50 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

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 <mail <at> joachim-breitner.de> 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 <at> joachim-breitner.de • http://www.joachim-breitner.de/
>  Jabber: nomeata <at> joachim-breitner.de  • GPG-Key: 0x4743206C
>  Debian Developer: nomeata <at> debian.org
> _______________________________________________
> Libraries mailing list
> Libraries <at> haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
David Luposchainsky | 26 Sep 10:03 2013

Re: Proposal: Show and Read for Data.Ord.Down

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
Ivan Lazar Miljenovic | 26 Sep 10:16 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

On 26 September 2013 18:03, David Luposchainsky
<dluposchainsky <at> googlemail.com> 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?

--

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic <at> gmail.com
http://IvanMiljenovic.wordpress.com
Ben Millwood | 27 Sep 01:23 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

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.
Erik Hesselink | 27 Sep 07:51 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

On Fri, Sep 27, 2013 at 1:23 AM, Ben Millwood <haskell <at> benmachine.co.uk> wrote:
> 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
Edward Kmett | 27 Sep 15:40 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

+1 for getDown


On Thu, Sep 26, 2013 at 7:23 PM, Ben Millwood <haskell <at> benmachine.co.uk> wrote:
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 <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Bardur Arantsson | 27 Sep 23:41 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

On 2013-09-27 15:40, Edward Kmett wrote:
> +1 for getDown
> 

This kind of makes me wish there was an Up newtype.

Regards,
David Luposchainsky | 27 Sep 23:55 2013

Re: Proposal: Show and Read for Data.Ord.Down

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?

David
Bardur Arantsson | 28 Sep 00:03 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

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.
Krzysztof Gogolewski | 14 Oct 22:03 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

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 <spam <at> scientician.net>:
> 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 <at> haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
Ross Paterson | 27 Sep 11:06 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

On Thu, Sep 26, 2013 at 06:16:57PM +1000, Ivan Lazar Miljenovic wrote:
> On 26 September 2013 18:03, David Luposchainsky
> <dluposchainsky <at> googlemail.com> 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.
Edward Kmett | 27 Sep 15:47 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

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 <R.Paterson <at> city.ac.uk> wrote:
On Thu, Sep 26, 2013 at 06:16:57PM +1000, Ivan Lazar Miljenovic wrote:
> On 26 September 2013 18:03, David Luposchainsky
> <dluposchainsky <at> googlemail.com> 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 <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Herbert Valerio Riedel | 26 Sep 12:59 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

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?
Ivan Lazar Miljenovic | 26 Sep 13:14 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

On 26 September 2013 20:59, Herbert Valerio Riedel <hvr <at> gnu.org> wrote:
> 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 <at> haskell.org
> http://www.haskell.org/mailman/listinfo/libraries

--

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic <at> gmail.com
http://IvanMiljenovic.wordpress.com
Erik Hesselink | 26 Sep 13:15 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

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 <hvr <at> gnu.org> wrote:
> 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 <at> haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
Herbert Valerio Riedel | 26 Sep 14:12 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

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')
Ivan Lazar Miljenovic | 26 Sep 14:56 2013
Picon

Re: Proposal: Show and Read for Data.Ord.Down

On 26 September 2013 22:12, Herbert Valerio Riedel <hvr <at> gnu.org> wrote:
> 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 <at> gmail.com
http://IvanMiljenovic.wordpress.com

Gmane