Re: argument ordering (was: Re: Priority Queues, or lack thereof)

In response to questions about why the convention of putting the data structure as the last argument... This style supports multiple operations nicely, especially with combined with the $ operator. For example, to insert 3 elements into a set, you can say insert 1 $ insert 2 $ insert 3 $ someSet (the last $ is optional). With the other argument ordering, you would say insert (insert (insert someSet 3) 2) 1 -- Chris

This style supports multiple operations nicely, especially with combined with the $ operator.
But note that the version with $ is actually longer than the one with nested parens! And where the operands are not statically known, the different orderings do simply come down to foldl/foldr preference:
insert 1 $ insert 2 $ insert 3 $ someSet
== foldr insert someSet [1,2,3]
insert (insert (insert someSet 3) 2) 1
== foldl insert someSet [3,2,1] In some sense the foldl variant is more 'obvious' about the order in which elements are actually inserted. Regards, Malcolm

On Fri, Aug 19, 2005 at 09:39:38AM -0400, Okasaki, C. DR EECS wrote:
In response to questions about why the convention of putting the data structure as the last argument...
This style supports multiple operations nicely, especially with combined with the $ operator. For example, to insert 3 elements into a set, you can say insert 1 $ insert 2 $ insert 3 $ someSet (the last $ is optional). With the other argument ordering, you would say insert (insert (insert someSet 3) 2) 1
With this ordering, couldn't one simply write someSet `insert` 3 `insert` 2 `insert` 1 ? -- David Roundy http://www.darcs.net
participants (3)
-
David Roundy
-
Malcolm Wallace
-
Okasaki, C. DR EECS