Re: [Haskell-cafe] Why is $ right associative instead of left associative?

2006-02-06 Thread Henning Thielemann

On Sun, 5 Feb 2006, Lennart Augustsson wrote:

 I don't use lists very much.  They are not the right data structure
 for many things.

Certainly, but lists are useful as interim data structure or for
initialising complex data structures.

 So : is not as common as :: in my code. I checked a small sample of
 code, about 2 lines of Haskell. It has about 1000 uses of ':' and
 2000 of '::'.

 In my opinion all the special syntactic sugar for lists should go
 away.  I don't think lists are special enough to motivate it.

Fine, someone shares my attitude towards the list sugar. Nevertheless, do
you mean with 'no sugar for lists' also no infix operator for list
construction? I would still like an operator of low precedence for list
construction for writing e.g. (1,'a):(2,'b'):[].

 But this is not what Haskell' is about.  It's supposed to be some
 modest extensions to Haskell.  Not designing a new perfect language.

Yes, this discussion is definitely beyond Haskell'.

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


Re[2]: [Haskell-cafe] Why is $ right associative instead of left associative?

2006-02-06 Thread Bulat Ziganshin
Hello Henning,

Monday, February 06, 2006, 4:12:44 PM, you wrote:

 In my opinion all the special syntactic sugar for lists should go
 away.  I don't think lists are special enough to motivate it.

HT Fine, someone shares my attitude towards the list sugar. Nevertheless, do
HT you mean with 'no sugar for lists' also no infix operator for list
HT construction? I would still like an operator of low precedence for list
HT construction for writing e.g. (1,'a):(2,'b'):[].

i prefer to have : and [] as general collection constructors:

class Collection c a where
  []  :: c a  -- creates empty collection
  (:) :: a - c a - c a  -- adds value to the head of collection

and having default rules that instatiates this collection type to
list if there is no type signatures and other information what allows
to find proper type of collection constructed this way - just like the
default Int language construct defaults all untyped numeric
constants to Int


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]



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


Re: [Haskell-cafe] Why is $ right associative instead of left associative?

2006-02-05 Thread Tomasz Zielonka
On Sat, Feb 04, 2006 at 07:02:52PM -0500, [EMAIL PROTECTED] wrote:
 G'day all.

Hello!

 Quoting Tomasz Zielonka [EMAIL PROTECTED]:
 
  Probably it was anticipated that right associative version will
  be more useful. You can use it to create a chain of transformations,
  similar to a chain of composed functions:
 
  (f . g . h) x   =   f $ g $ h $ x
 
 Of course, if $ were left-associative, it would be no less useful here,
 because you could express this chain thusly:
 
 f . g . h $ x

OK, I can be persuaded to use this style. I like function composition
much more than $ :-)

 This is the way that I normally express it.  Partly because I find
 function application FAR more natural than right-associative application,
 and partly because I'm hedging my bets for Haskell 2 just in case the
 standards committee wakes up and notices that the associativity of $ is
 just plain wrong and decides to fix it. :-)

Is there any chance that Haskell' will change the definition of $ ?

Well, if there is any moment where we can afford introducing backward
incompatible changes to Haskell', I think it's now or never!

 In fact, I'll go out on a limb and claim that ALL such uses of $ are
 better expressed with composition.  Anyone care to come up with a
 counter-example?

The only problem I see right now is related to change locality. If I
have a chain like this:

f x y .
g x $
z

and I want to add some transformation between g and z I have to
change one line and insert another

f x y .
g x .
h x y $
z

With right-associative $ it would be only one line-add. Probably not a
very strong argument.

  But of course, left associative version can also be useful. Some
  time ago I used a left associative version of the strict application
  operator, which I named (!$).
 
 In fact, I think it's much MORE useful, and for precisely the reason
 that you state: it makes strict application much more natural.

Agreed.

Best regards
Tomasz

-- 
I am searching for programmers who are good at least in
(Haskell || ML)  (Linux || FreeBSD || math)
for work in Warsaw, Poland
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is $ right associative instead of left associative?

2006-02-05 Thread Bill Wood
On Sun, 2006-02-05 at 13:49 +0100, Tomasz Zielonka wrote:
   . . .
 and I want to add some transformation between g and z I have to
 change one line and insert another
 
 f x y .
 g x .
 h x y $
 z

 With right-associative $ it would be only one line-add. Probably not a
 very strong argument.

Maybe stronger than you think.  I know that one of the arguments for
making ; a C-style delimiter rather than a Pascal-style separator is
that adding a new statement at the end of a series is error-prone -- one
tends to forget to add the ; in front of the new statement (and one
reason Pascal syntax included the null statement was so that s1;
would parse as s1; null, making ; a de facto delimiter).

Editing ease matters more than a little.

 -- Bill Wood


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


[Haskell-cafe] Why is $ right associative instead of left associative?

2006-02-04 Thread Brian Hulley

Hi -
In the Haskell98 report section 4.4.2 $ is specified as being right 
associative. This means that f $ a0 a1 $ b0 b1 would parse as f (a0 a1 (b0 
b1)) which seems rather strange to me. Surely it would be much more useful 
if $ were defined as left associative so that it could be used to separate 
the args to f?


Does anyone know why this strange associativity was chosen?

Thanks, Brian.

(The reason I'm asking is that I'm working on the syntax of a language 
similar to Haskell but which uses layout to allow expressions like:


f #$ -- can be followed by an explicit 
block or layout block

   a0 a1
   b0 b1

which is sugar for (f $ a0 a1) $ b0 b1 ie f (a0 a1) (b0 b1) ) and I was 
surprised to discover that the parentheses are needed for the most obvious 
reading) 


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


Re: [Haskell-cafe] Why is $ right associative instead of left associative?

2006-02-04 Thread Tomasz Zielonka
On Sat, Feb 04, 2006 at 02:52:20PM -, Brian Hulley wrote:
 Hi -
 In the Haskell98 report section 4.4.2 $ is specified as being right 
 associative. This means that f $ a0 a1 $ b0 b1 would parse as f (a0 a1 (b0 
 b1)) which seems rather strange to me. Surely it would be much more useful 
 if $ were defined as left associative so that it could be used to separate 
 the args to f?
 
 Does anyone know why this strange associativity was chosen?

Probably it was anticipated that right associative version will
be more useful. You can use it to create a chain of transformations,
similar to a chain of composed functions:

(f . g . h) x   =   f $ g $ h $ x

Example:

map f $ group $ sort $ filter g $ l

But of course, left associative version can also be useful. Some
time ago I used a left associative version of the strict application
operator, which I named (!$).

Anyway, you can't always remove all parentheses. And why would you want
to? Everybody is used to them.

Best regards
Tomasz

-- 
I am searching for programmers who are good at least in
(Haskell || ML)  (Linux || FreeBSD || math)
for work in Warsaw, Poland
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is $ right associative instead of left associative?

2006-02-04 Thread Brian Hulley

Tomasz Zielonka wrote:

On Sat, Feb 04, 2006 at 02:52:20PM -, Brian Hulley wrote:

Hi -
In the Haskell98 report section 4.4.2 $ is specified as being right
associative. This means that f $ a0 a1 $ b0 b1 would parse as f (a0
a1 (b0 b1)) which seems rather strange to me. Surely it would be
much more useful if $ were defined as left associative so that it
could be used to separate the args to f?

Does anyone know why this strange associativity was chosen?


Probably it was anticipated that right associative version will
be more useful. You can use it to create a chain of transformations,
similar to a chain of composed functions:

   (f . g . h) x   =   f $ g $ h $ x

Example:

   map f $ group $ sort $ filter g $ l

But of course, left associative version can also be useful. Some
time ago I used a left associative version of the strict application
operator, which I named (!$).


I wonder if anyone has done empirical studies to determine scientifically 
which associativity would be more useful in practice eg by analysis of 
source code involving $ and comparing the number of parentheses that would 
be needed in each case, and perhaps also some studies involving the number 
of confused readers in each case...


Even though both versions are useful, it seems to me that faced with the 
choice of choosing an associativity for an operator that does function 
application, and given that prefix application is left associative, there is 
one clear winner, but unfortunately the Haskell committee didn't see it this 
way, and perhaps it is too late to ever change this (just like :: and : 
which were mixed up for reasons unknown). Especially since chains can 
already be composed using . .




Anyway, you can't always remove all parentheses. And why would you
want to? Everybody is used to them.


$'s advertised purpose is to remove parentheses, but I agree that 
parenthesized code is often more readable (especially when operators have 
unexpected fixities... :-))


Regards, Brian. 


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


Re: [Haskell-cafe] Why is $ right associative instead of left associative?

2006-02-04 Thread Taral
On 2/4/06, Brian Hulley [EMAIL PROTECTED] wrote:
 Does anyone know why this strange associativity was chosen?

I think it's very natural. Everything after the $, including other $
expressions, is applied to the stuff before the $. This saves me from
a lot of nested parentheses.

It seems to be that the left-associative version of $ does not
decrease nesting level so effectively.

--
Taral [EMAIL PROTECTED]
Computer science is no more about computers than astronomy is about
telescopes.
-- Edsger Dijkstra
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is $ right associative instead of left associative?

2006-02-04 Thread Stefan Holdermans

Taral wrote:


I think it's very natural. Everything after the $, including other $
expressions, is applied to the stuff before the $. This saves me from
a lot of nested parentheses.


To me, ($) helping me to avoid writing lots of parentheses, makes it  
extremely useful. Actually: except for passing function application  
to higher-order functions, this is the only way I use it. So, I  
always thought parentheses were *the* reason for the right- 
associativity of ($). Not sure if it really was originally, but, ever  
so, I think it is the best reason.


Regards,

  Stefan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is $ right associative instead of left associative?

2006-02-04 Thread Tomasz Zielonka
On Sat, Feb 04, 2006 at 08:37:51PM +0100, Stefan Holdermans wrote:
 Taral wrote:
 
 I think it's very natural. Everything after the $, including other $
 expressions, is applied to the stuff before the $. This saves me from
 a lot of nested parentheses.
 
 To me, ($) helping me to avoid writing lots of parentheses, makes it  
 extremely useful. Actually: except for passing function application  
 to higher-order functions, this is the only way I use it. So, I  
 always thought parentheses were *the* reason for the right- 
 associativity of ($). Not sure if it really was originally, but, ever  
 so, I think it is the best reason.

A left-associative low-precedence application operator can also help
avoid writing parentheses, only in different cases, eg.

f $$ x + 1 $$ x * x + 2 * x + 1

equals

f (x + 1) (x * x + 2 * x + 1)

But in this case the parentheses don't nest, which may be a reason
why a right-associative version was chosen. ($) helps to avoid
the case of nesting parentheses. Such nesting is unbounded, for
example you can have chains like this with arbitrary length:

a (b (c (d (e (f x)

even if you only have unary functions.

Also, adding or removing a function in such a chain can require
non-local changes, that is you are forced to add or remove a closing
parenthesis on the end of expression.

If you use ($):

a $ b $ c $ d $ e $ f x

you can easily add or remove a function in the chain.

On the other hand, adding new parameters to calls like this

f (x + 1) (y - 1) ...

is very localised.

Best regards
Tomasz

-- 
I am searching for programmers who are good at least in
(Haskell || ML)  (Linux || FreeBSD || math)
for work in Warsaw, Poland
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is $ right associative instead of left associative?

2006-02-04 Thread ajb
G'day all.

Quoting Tomasz Zielonka [EMAIL PROTECTED]:

 Probably it was anticipated that right associative version will
 be more useful. You can use it to create a chain of transformations,
 similar to a chain of composed functions:

 (f . g . h) x   =   f $ g $ h $ x

Of course, if $ were left-associative, it would be no less useful here,
because you could express this chain thusly:

f . g . h $ x

This is the way that I normally express it.  Partly because I find
function application FAR more natural than right-associative application,
and partly because I'm hedging my bets for Haskell 2 just in case the
standards committee wakes up and notices that the associativity of $ is
just plain wrong and decides to fix it. :-)

In fact, I'll go out on a limb and claim that ALL such uses of $ are
better expressed with composition.  Anyone care to come up with a
counter-example?

 But of course, left associative version can also be useful. Some
 time ago I used a left associative version of the strict application
 operator, which I named (!$).

In fact, I think it's much MORE useful, and for precisely the reason
that you state: it makes strict application much more natural.

Strict application also has the wrong associativity.  As it is, $! is
only useful if the _last_ argument of a function needs to be strict.  I
find that ordering my arguments in a de Bruijn-like order (which many
experienced functional programmers do unconsciously) results in this
being the least common case.

The last argument of a function is usually the induction argument: it's
almost invariably the subject of a top-level test.  The strictness
analyser invariably picks up that the argument is strict.  It's the OTHER
arguments you may need to evaluate early.

Suppose you have a function with three arguments, the second of which
needs to be strict.  I want to write something like this:

f (g x) $! (h y) $ (j z)

What I have to write is this:

(f (g x) $! (h y)) (j z)

or this:

let y' = h y in y' `seq` f (g x) y' (j z)

 Anyway, you can't always remove all parentheses. And why would you want
 to? Everybody is used to them.

I agree.  However, sometimes parentheses make things more confusing.
Almost always the best solution is to give the offending subexpression
a name, using let or where.  However, the specific case above is the
only one that I've found where this, too, makes things worse.

In summary: There is no good reason to make $ right-associative and at
least one good reason to make it left-associative.

Cheers,
Andrew Bromage
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is $ right associative instead of left associative?

2006-02-04 Thread ajb
G'day all.

Quoting [EMAIL PROTECTED]:

 This is the way that I normally express it.  Partly because I find
 function application FAR more natural than right-associative application,

I meant to say that I find function COMPOSITION more natural than
right-associative application.  It certainly fits better with my
personal biases about good functional programming style.

Cheers,
Andrew Bromage
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe