Re: PROPOSAL: Include record puns in Haskell 2011

2010-02-26 Thread Iavor Diatchki
Hello,

In order to keep the discussion structured I have created two tickets
in the haskell-prime trac system
(http://hackage.haskell.org/trac/haskell-prime):
  * Proposal 1: Add pre-Haskell'98 style punning and record
disambiguation (ticket #136)
  * Proposal 2: Add record-wildcards (ticket #137)

I decided to split the two into separate tickets because, at least in
my mind, there are different things that we might discuss about the
two, and also they make sense independent of each other (although
record wildcards without punning might be a bit weird :-).

I think that both proposals are worth considering for Haskell 2011
because there are situations where they can significantly improve the
readability of code involving record manipulation.  I disagree with
the stylistic issues that were brought up in the discussion because I
do not believe that variable "shadowing" should be avoided at all
costs:  at least for me, avoiding shadowing is a means to an end
rather then an end in itself.  In the case of record puns, I think
that the clarity of the notation far surpasses any confusion that
might be introduced by the shadowing.  Furthermore, as other
participants in the discussion pointed out, the proposed features are
orthogonal to the rest of the language, so their use is entirely
optional.

-Iavor




On Fri, Feb 26, 2010 at 2:59 AM, Heinrich Apfelmus
 wrote:
> Simon Marlow wrote:
>> While I agree with these points, I was converted to record punning
>> (actually record wildcards) when I rewrote the GHC IO library.  Handle
>> is a record with 12 or so fields, and there are literally dozens of
>> functions that start like this:
>>
>>   flushWriteBuffer :: Handle -> IO ()
>>   flushWriteBuffer Handle{..} = do
>>
>> if I had to write out the field names I use each time, and even worse,
>> think up names to bind to each of them, it would be hideous.
>
> What about using field names as functions?
>
>    flushWriteBuffer h@(Handle {}) = do
>        ... buffer h ...
>
> Of course, you always have to drag  h  around.
>
>
> Regards,
> Heinrich Apfelmus
>
> --
> http://apfelmus.nfshost.com
>
> ___
> Haskell-prime mailing list
> Haskell-prime@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-prime
>
___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: PROPOSAL: Include record puns in Haskell 2011

2010-02-26 Thread Heinrich Apfelmus
Simon Marlow wrote:
> While I agree with these points, I was converted to record punning
> (actually record wildcards) when I rewrote the GHC IO library.  Handle
> is a record with 12 or so fields, and there are literally dozens of
> functions that start like this:
> 
>   flushWriteBuffer :: Handle -> IO ()
>   flushWriteBuffer Handle{..} = do
> 
> if I had to write out the field names I use each time, and even worse,
> think up names to bind to each of them, it would be hideous.

What about using field names as functions?

flushWriteBuffer h@(Handle {}) = do
... buffer h ...

Of course, you always have to drag  h  around.


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com

___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


RE: PROPOSAL: Include record puns in Haskell 2011

2010-02-25 Thread Simon Peyton-Jones
| >> we implicitly get
| >> f :: T -> Int
| >> which punning shadows with
| >> f :: Int   
| >> whereas I generally avoid shadowing completely.
| >
| > I agree with Ian.
| 
| I tend to agree.

I originally had field puns in GHC, and then took them out when Haskell 98 
removed them, after a discussion very like this one.  I put them back in 
because some people really wanted them.  

Actually GHC has three separate extensions to do with named fields:

field disambiguation (Section 7.3.14)
field puns (Section 7.3.15)
field wildcards (Section 7.3.16)

Look here 
http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#disambiguate-fields


Opinions differ.  I'm rather with John: let the programmer choose, rather than 
enforcing a style in the language. For punning, the programmer can certainly 
choose on a case by case basis.  If you use Haskell 98's existing syntax, there 
is no change to the semantics if you switch on field puns:

data T = C { f :: Int }

foo (C {f = x}) = ...   -- No punning
bar (C {f}) = ...   -- Punning

It would help this discussion if someone created a ticket to explain the actual 
proposal, so that we are all discussing the same thing.

Simon

___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: PROPOSAL: Include record puns in Haskell 2011

2010-02-24 Thread John Meacham
On Wed, Feb 24, 2010 at 08:50:42PM +, Simon Marlow wrote:
> On 24/02/10 18:23, Ian Lynagh wrote:
> While I agree with these points, I was converted to record punning  
> (actually record wildcards) when I rewrote the GHC IO library.  Handle  
> is a record with 12 or so fields, and there are literally dozens of  
> functions that start like this:
>
>   flushWriteBuffer :: Handle -> IO ()
>   flushWriteBuffer Handle{..} = do
>
> if I had to write out the field names I use each time, and even worse,  
> think up names to bind to each of them, it would be hideous.
>
> There are reasons to find this distasteful, yes, but I think the  
> alternative is much worse.
>
> I'm not proposing record wildcards (yet) *cough* labelled-field  
> wildcards, but punning is a step in the right direction.

Yes. I too have had this issue with jhc and am a big fan of GHC's field
wildcards. It is motivation enough for me to require a newer version of
ghc for compiling jhc. I'd support field wildcards in 2011, but would
understand if people thought it was too soon.

John

-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/
___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: PROPOSAL: Include record puns in Haskell 2011

2010-02-24 Thread Simon Marlow

On 24/02/10 18:23, Ian Lynagh wrote:

On Tue, Feb 23, 2010 at 07:07:30PM -0800, Iavor Diatchki wrote:


I'd like to propose that we add record punning to Haskell 2011.

Thoughts, objections, suggestions?


I have a feeling I'm in the minority, but I find record punning an ugly
feature.

Given
 data T = C { f :: Int }
we implicitly get
 f :: T ->  Int
which punning shadows with
 f :: Int
whereas I generally avoid shadowing completely.


While I agree with these points, I was converted to record punning 
(actually record wildcards) when I rewrote the GHC IO library.  Handle 
is a record with 12 or so fields, and there are literally dozens of 
functions that start like this:


  flushWriteBuffer :: Handle -> IO ()
  flushWriteBuffer Handle{..} = do

if I had to write out the field names I use each time, and even worse, 
think up names to bind to each of them, it would be hideous.


There are reasons to find this distasteful, yes, but I think the 
alternative is much worse.


I'm not proposing record wildcards (yet) *cough* labelled-field 
wildcards, but punning is a step in the right direction.


Cheers,
Simon
___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: PROPOSAL: Include record puns in Haskell 2011

2010-02-24 Thread Isaac Dupree

On 02/24/10 13:40, Martijn van Steenbergen wrote:

Ian Lynagh wrote:

I have a feeling I'm in the minority, but I find record punning an ugly
feature.

Given
data T = C { f :: Int }
we implicitly get
f :: T -> Int
which punning shadows with
f :: Int
whereas I generally avoid shadowing completely.


I agree with Ian.


I tend to agree.

I don't mind if a few files that use a ton of label-operations are 
marked with NamedFieldPuns and use that feature a lot.  But, funnily, if 
it were put in the standard then it would be enabled in un-marked source 
files, and then I personally wouldn't like it as much. (Any decision is 
acceptable to me though.)


-Isaac
___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: PROPOSAL: Include record puns in Haskell 2011

2010-02-24 Thread John Meacham
On Wed, Feb 24, 2010 at 06:54:44PM +, Thomas Davie wrote:
> The problem though, unless I'm misunderstanding, is that you *must*
> enforce one or other convention here.  Either you force everyone who's
> style is to never shadow things to do so because of this language
> feature, or you remove the language feature and trample on the other
> crowd.

Hmm? I don't see how this language feature forces shadowing any more
than allowing shadowing anywhere else in the language. It is not
proposed that field punning replace the previous mechanism for assigning
or pulling values from fields, just that it be added as an option. Just
as it has always been an option to shadow variables in do notation.

John

-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/
___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: PROPOSAL: Include record puns in Haskell 2011

2010-02-24 Thread Thomas Davie

On 24 Feb 2010, at 18:52, John Meacham wrote:

> On Wed, Feb 24, 2010 at 06:23:39PM +, Ian Lynagh wrote:
>> On Tue, Feb 23, 2010 at 07:07:30PM -0800, Iavor Diatchki wrote:
>> I have a feeling I'm in the minority, but I find record punning an ugly
>> feature.
>> 
>> Given
>>data T = C { f :: Int }
>> we implicitly get
>>f :: T -> Int
>> which punning shadows with
>>f :: Int
>> whereas I generally avoid shadowing completely.
> 
> I can see the thinking here, but I don't like for the language to try to
> enforce 'style' or make decisions based on it. I think it is more in the
> spirit of haskell to provide multiple mechanisms when it makes sense and
> let the users figure out what works for them stylistically. 

The problem though, unless I'm misunderstanding, is that you *must* enforce one 
or other convention here.  Either you force everyone who's style is to never 
shadow things to do so because of this language feature, or you remove the 
language feature and trample on the other crowd.

For what it's worth, I'd side with Ian on this one.

Bob___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: PROPOSAL: Include record puns in Haskell 2011

2010-02-24 Thread John Meacham
On Wed, Feb 24, 2010 at 06:23:39PM +, Ian Lynagh wrote:
> On Tue, Feb 23, 2010 at 07:07:30PM -0800, Iavor Diatchki wrote:
> I have a feeling I'm in the minority, but I find record punning an ugly
> feature.
> 
> Given
> data T = C { f :: Int }
> we implicitly get
> f :: T -> Int
> which punning shadows with
> f :: Int
> whereas I generally avoid shadowing completely.

I can see the thinking here, but I don't like for the language to try to
enforce 'style' or make decisions based on it. I think it is more in the
spirit of haskell to provide multiple mechanisms when it makes sense and
let the users figure out what works for them stylistically. 

John

-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/
___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: PROPOSAL: Include record puns in Haskell 2011

2010-02-24 Thread Martijn van Steenbergen

Ian Lynagh wrote:

I have a feeling I'm in the minority, but I find record punning an ugly
feature.

Given
data T = C { f :: Int }
we implicitly get
f :: T -> Int
which punning shadows with
f :: Int
whereas I generally avoid shadowing completely.


I agree with Ian.

Groetjes,

Martijn.

___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: PROPOSAL: Include record puns in Haskell 2011

2010-02-24 Thread Ian Lynagh
On Tue, Feb 23, 2010 at 07:07:30PM -0800, Iavor Diatchki wrote:
>
> I'd like to propose that we add record punning to Haskell 2011.
> 
> Thoughts, objections, suggestions?

I have a feeling I'm in the minority, but I find record punning an ugly
feature.

Given
data T = C { f :: Int }
we implicitly get
f :: T -> Int
which punning shadows with
f :: Int
whereas I generally avoid shadowing completely.


Thanks
Ian

___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


PROPOSAL: Include record puns in Haskell 2011

2010-02-24 Thread Iavor Diatchki
Hello,
(Malcolm, sorry for the double post, I forgot to CC the list)
I was thinking mostly about the "old-time"-y punning, where I can
write a label, say "theField", and it automatically gets expanded to
"theField = theField", in record patterns and record constructing
expressions.

The only corner case that I can remember about this is the interaction
with qualified names, the issue being what happens if a label in a pun
is qualified?  I think that in such cases we should just used the
unqualified form for the variable associated with the label.  In
patterns, I can't think of any other sensible alternative.  In
expressions, I could imaging expanding "A.theField" to "A.theField =
A.theField" but it seems that this would almost never be what we want,
while in all the uses I've had "A.theField = theField" is what was
needed.

I think that this is exactly what GHC implements, at least based on
the following example:

module A where data T = C { f :: Int }

{-# LANGUAGE NamedFieldPuns #-}
module B where
import qualified A

testPattern (A.C { A.f }) = f
testExpr f                = A.C { A.f }

I imagine that this is fairly close to what was in Haskell 1.3?   As
far as wild-cards are concerned, I don't feel particularly strongly
about them either way (I can see some benefits and some drawbacks) so
I'd be happy to leave them for a separate proposal or add them to this
one, depending on how the rest of the community feels.

-Iavor





On Wed, Feb 24, 2010 at 1:35 AM, Malcolm Wallace
 wrote:
>> I'd like to propose that we add record punning to Haskell 2011.
>
> Can you be more specific?  Do you propose to re-instate punning exactly as
> it was specified in Haskell 1.3?  Or do you propose in addition some of the
> newer extensions that have been recently implemented in ghc (but not other
> compilers), such as record wildcards?
>
> Regards,
>    Malcolm
>
> ___
> Haskell-prime mailing list
> Haskell-prime@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-prime
>
___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


Re: PROPOSAL: Include record puns in Haskell 2011

2010-02-24 Thread Malcolm Wallace

I'd like to propose that we add record punning to Haskell 2011.


Can you be more specific?  Do you propose to re-instate punning  
exactly as it was specified in Haskell 1.3?  Or do you propose in  
addition some of the newer extensions that have been recently  
implemented in ghc (but not other compilers), such as record wildcards?


Regards,
Malcolm

___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime


PROPOSAL: Include record puns in Haskell 2011

2010-02-23 Thread Iavor Diatchki
Hello,
I'd like to propose that we add record punning to Haskell 2011.  I
think that this is a useful feature which makes working with record
fields easier, and reduces clutter in definitions, both in patterns
and expressions.  Furthermore, this features has been implemented in
GHC for a long time (it used to be in Hugs too, once) and we've had
plenty of time to iron out dark corners in the design.

Thoughts, objections, suggestions?

-Iavor
___
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime