<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>A quick thought that came to me after hoogling [a] -&gt; [[a]].</div><div><br></div><div>The first four functions in the search result are named after what they return (noun in plural) rather than what they do (verb). I am talking about <font class="Apple-style-span" face="'Courier New'">inits</font>, <font class="Apple-style-span" face="'Courier New'">permutations</font>, <font class="Apple-style-span" face="'Courier New'">subsequence</font> and <font class="Apple-style-span" face="'Courier New'">tails</font>.</div><div><br></div><div>So I thought the following syntax might work as well if (as it is already common) grouping functions are named after &nbsp;what they return.</div><div><br></div><div><div><font class="Apple-style-span" face="'Courier New'">then &nbsp; &nbsp; &nbsp; f<br>then &nbsp; &nbsp; &nbsp; f by e<br>then group f<br>then group f by e</font></div></div><div><br></div><div>For example the following code fragments read well:</div><div><br></div><div><font class="Apple-style-span" face="'Courier New'">then group inits</font></div><div><font class="Apple-style-span" face="'Courier New'">then group permutations</font></div><div><font class="Apple-style-span" face="'Courier New'">then group subsequences</font></div><div><font class="Apple-style-span" face="'Courier New'">then group tails</font></div><div><br></div><div>Here we use the special identifier group as a verb.</div><div><br></div><div>I have not told you about the fifth result of the hoogling, the <font class="Apple-style-span" face="'Courier New'">groupWith</font> function. The following really looks ugly:</div><div><br></div><div><font class="Apple-style-span" face="'Courier New'">then group groupWith by e</font></div><div><br></div><div>But following the aforementioned naming convention the <font class="Apple-style-span" face="'Courier New'">groupWith</font> function could as well be named as&nbsp;<font class="Apple-style-span" face="'Courier New'">equals</font>. Now this reads well:</div><div><br></div><div><font class="Apple-style-span" face="'Courier New'">then group equals by e</font></div><div><br></div><div>Cheers, George</div><div><br></div><br><div><div>On 2011-Oct-5, at 09:14 , Simon Peyton-Jones wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>[adding ghc-users]<br><br>It's not easy, Phil. &nbsp;Do you have any ideas?<br><br>For the 'then' case the name of the function serves as the verb. &nbsp;One might say<br><br><span class="Apple-tab-span" style="white-space:pre">        </span>then take 4<br>or<br><span class="Apple-tab-span" style="white-space:pre">        </span>then takeWhile by salary &gt; 40<br><br>For grouping one might like to say the same &nbsp;thing, such as<br><span class="Apple-tab-span" style="white-space:pre">        </span>then groupBy by salary<br>but the typing rule is quite different, so we really need a different keyword. &nbsp;We chose the compound keyword "then group" to avoid needing a whole new keyword ("group" is treated specially only in tthis context). So you write<br><span class="Apple-tab-span" style="white-space:pre">        </span>then group by salary using groupBy<br><br>Using this order of the pieces for the sorting case is harder. What would one say? &nbsp;"then process"? &nbsp;Like this?<br><span class="Apple-tab-span" style="white-space:pre">        </span>then process by salary &gt; 40 using takeWhile<br>Not very nice.<br><br>One could use a new keyword for grouping "theng" say, thus:<br><span class="Apple-tab-span" style="white-space:pre">        </span>theng groupBy by salary<br>But that is hardly beautiful either.<br><br>So the current story is not great, but it's the best I could think of. Improvements welcome.<br><br>Simon<br><br>| &nbsp;-----Original Message-----<br>| &nbsp;From: Philip Wadler [mailto:wadler@inf.ed.ac.uk]<br>| &nbsp;Sent: 04 October 2011 18:15<br>| &nbsp;To: Simon Peyton-Jones; George Giorgidze<br>| &nbsp;Subject: Re: FW: Two Proposals<br>| &nbsp;<br>| &nbsp;George,<br>| &nbsp;<br>| &nbsp;Nice proposal. &nbsp;I like the idea of symmetry, but don't at all like the<br>| &nbsp;idea that f comes before e for 'then' but f comes after e for 'then<br>| &nbsp;group'. &nbsp;Can you rethink it and come up with something even more<br>| &nbsp;symmetric?<br>| &nbsp;<br>| &nbsp;Yours, &nbsp;-- P<br>| &nbsp;<br>| &nbsp;<br>| &nbsp;On Tue, Oct 4, 2011 at 9:23 AM, Simon Peyton-Jones<br>| &nbsp;&lt;<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>&gt; wrote:<br>| &nbsp;&gt; FYI<br>| &nbsp;&gt;<br>| &nbsp;&gt; -----Original Message-----<br>| &nbsp;&gt; From: <a href="mailto:glasgow-haskell-users-bounces@haskell.org">glasgow-haskell-users-bounces@haskell.org</a> [mailto:glasgow-haskell-<br>| &nbsp;users-bounces@haskell.org] On Behalf Of George Giorgidze<br>| &nbsp;&gt; Sent: 30 September 2011 18:28<br>| &nbsp;&gt; To: <a href="mailto:glasgow-haskell-users@haskell.org">glasgow-haskell-users@haskell.org</a><br>| &nbsp;&gt; Subject: Two Proposals<br>| &nbsp;&gt;<br>| &nbsp;&gt; GHC Users,<br>| &nbsp;&gt;<br>| &nbsp;&gt; I would like to make to the following two proposals:<br>| &nbsp;&gt; &nbsp;* Eliminate the default grouping close from SQL-like comprehensions<br>| &nbsp;&gt; &nbsp;* Introduce a GHC extension for list literal overloading<br>| &nbsp;&gt;<br>| &nbsp;&gt; OK, let me start with the first proposal.<br>| &nbsp;&gt;<br>| &nbsp;&gt; Currently, the SQL-like comprehension notation (both in its list comprehension<br>| &nbsp;and monad comprehension variants) features the following five clauses:<br>| &nbsp;&gt;<br>| &nbsp;&gt; then f<br>| &nbsp;&gt; then f by e<br>| &nbsp;&gt; then group by e<br>| &nbsp;&gt; then group using f<br>| &nbsp;&gt; then group by e using f<br>| &nbsp;&gt;<br>| &nbsp;&gt; The first two clauses are used for specifying transformations of type [a] -&gt; [a]<br>| &nbsp;(or Monad m =&gt; m a-&gt; m a for monad comprehensions). The following three<br>| &nbsp;clauses are used for specifying transformations of type [a] -&gt; [[a]] (or Monad m,<br>| &nbsp;Functor f =&gt; m a -&gt; m (f a) for monad comprehensions). See [1] for further<br>| &nbsp;details.<br>| &nbsp;&gt;<br>| &nbsp;&gt; Note that the third clause does not mention which function is used for grouping.<br>| &nbsp;In this case GHC.Exts.groupWith function is used as a default for list<br>| &nbsp;comprehensions and the mgroupWith function from the MonadGroup class is used<br>| &nbsp;as a default for monad comprehensions.<br>| &nbsp;&gt;<br>| &nbsp;&gt; I would like to suggest to remove the third clause for the following reasons:<br>| &nbsp;&gt; * Currently the syntax is asymmetrical. Note that there is the default case for<br>| &nbsp;the 'then group' clause and not for the 'then' clause.<br>| &nbsp;&gt; * In the current notation it is not clear which grouping function is used in the<br>| &nbsp;default case<br>| &nbsp;&gt; * For many monads including lists it is not clear which function should be<br>| &nbsp;selected as a default (e.g., the groupWith function also does sorting and it is not<br>| &nbsp;clear to me why this should be the default)<br>| &nbsp;&gt; * Gets rid of the MonadGroup class. Currently the sole purpose of this class is to<br>| &nbsp;introduce a default grouping function for monad comprehensions.<br>| &nbsp;&gt; * Explicit mention of the grouping function would make &nbsp;monad/list<br>| &nbsp;comprehensions much easier to read by making it immediately apparent which<br>| &nbsp;function is used for grouping.<br>| &nbsp;&gt;<br>| &nbsp;&gt; My second proposal is to introduce the OverloadedLists extension that overloads<br>| &nbsp;list literals. See Section 5.2 in [1] for details.<br>| &nbsp;&gt;<br>| &nbsp;&gt; Basically the idea is to treat list literals like:<br>| &nbsp;&gt;<br>| &nbsp;&gt; [1,2,3]<br>| &nbsp;&gt;<br>| &nbsp;&gt; as<br>| &nbsp;&gt;<br>| &nbsp;&gt; fromList [1,2,3]<br>| &nbsp;&gt;<br>| &nbsp;&gt; where<br>| &nbsp;&gt;<br>| &nbsp;&gt; class IsList l where<br>| &nbsp;&gt; &nbsp;type Item l<br>| &nbsp;&gt; &nbsp;fromList :: [Item l] -&gt; l<br>| &nbsp;&gt;<br>| &nbsp;&gt; In the following I give useful instances of the IsList class.<br>| &nbsp;&gt;<br>| &nbsp;&gt; instance IsList [a] where<br>| &nbsp;&gt; &nbsp;type Item [a] = a<br>| &nbsp;&gt; &nbsp;fromList = id<br>| &nbsp;&gt;<br>| &nbsp;&gt; instance (Ord a) =&gt; IsList (Set a) where<br>| &nbsp;&gt; &nbsp;type Item (Set a) = a<br>| &nbsp;&gt; &nbsp;fromList = Set.fromList<br>| &nbsp;&gt;<br>| &nbsp;&gt; instance (Ord k) =&gt; IsList (Map k v) where<br>| &nbsp;&gt; &nbsp;type Item (Map k v) = (k,v)<br>| &nbsp;&gt; &nbsp;fromList = Map.fromList<br>| &nbsp;&gt;<br>| &nbsp;&gt; instance IsList (IntMap v) where<br>| &nbsp;&gt; &nbsp;type Item (IntMap v) = (Int,v)<br>| &nbsp;&gt; &nbsp;fromList = IntMap.fromList<br>| &nbsp;&gt;<br>| &nbsp;&gt; instance IsList Text where<br>| &nbsp;&gt; &nbsp;type Item Text = Char<br>| &nbsp;&gt; &nbsp;fromList = Text.pack<br>| &nbsp;&gt;<br>| &nbsp;&gt; As you can see the extension would allow list literals to be used for sets, maps<br>| &nbsp;and integer maps. In addition the suggested OverloadedLists extension would<br>| &nbsp;subsume OverloadedStrings extension (see the instance for Text, for example).<br>| &nbsp;Having said that, for now, I am not suggesting to remove the OverloadedStrings<br>| &nbsp;extension as it appears to be widely used.<br>| &nbsp;&gt;<br>| &nbsp;&gt; This extension could also be used for giving data-parallel array literals instead of<br>| &nbsp;the special syntax used currently.<br>| &nbsp;&gt;<br>| &nbsp;&gt; Unless there is a vocal opposition to the aforementioned two proposals, I would<br>| &nbsp;like to implement them in GHC. Both changes appear to be straightforward to<br>| &nbsp;implement.<br>| &nbsp;&gt;<br>| &nbsp;&gt; Thanks in advance for your feedback.<br>| &nbsp;&gt;<br>| &nbsp;&gt; Cheers, George<br>| &nbsp;&gt;<br>| &nbsp;&gt; [1] <a href="http://www-db.informatik.uni-tuebingen.de/files/giorgidze/haskell2011.pdf">http://www-db.informatik.uni-tuebingen.de/files/giorgidze/haskell2011.pdf</a><br>| &nbsp;&gt; _______________________________________________<br>| &nbsp;&gt; Glasgow-haskell-users mailing list<br>| &nbsp;&gt; <a href="mailto:Glasgow-haskell-users@haskell.org">Glasgow-haskell-users@haskell.org</a><br>| &nbsp;&gt; <a href="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users">http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</a><br>| &nbsp;&gt;<br>| &nbsp;&gt;<br>| &nbsp;&gt;<br>| &nbsp;<br>| &nbsp;<br>| &nbsp;<br>| &nbsp;--<br>| &nbsp;.\ Philip Wadler, Professor of Theoretical Computer Science<br>| &nbsp;./\ School of Informatics, University of Edinburgh<br>| &nbsp;/&nbsp; \ <a href="http://homepages.inf.ed.ac.uk/wadler/">http://homepages.inf.ed.ac.uk/wadler/</a><br>| &nbsp;<br>| &nbsp;The University of Edinburgh is a charitable body, registered in<br>| &nbsp;Scotland, with registration number SC005336.<br>| &nbsp;<br><br></div></blockquote></div><br></body></html>