GHC: Ticket #3671: Add partitioning functions to Data.List
http://ghc.haskell.org/trac/ghc/ticket/3671
<p>
The functions <tt>take</tt> and <tt>span</tt> have recursive equivalents <tt>takeRec</tt> and <tt>spanRec</tt> that apply the same function to the remainder, i.e.
</p>
<pre class="wiki">takeRec i xs = let (hs,ts) = splitAt i xs in hs : takeRec i xs
spanRec p xs = let (hs,ts) = span p xs in hs : spanRec p xs
</pre><p>
and the more generic version of <tt>take</tt>:
</p>
<pre class="wiki">genericTakeRec i xs = let (hs,ts) = genericSplitAt i xs in hs : genericTakeRec i xs
</pre><p>
These functions, to me, are in the same league as <tt>partition</tt> and <tt>group</tt>, can be added with little chance of nameclashes on functions with a different meaning and are not named compositions.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/3671
Trac 1.0.1holzenspTue, 17 Nov 2009 13:49:44 GMT
http://ghc.haskell.org/trac/ghc/ticket/3671#comment:1
http://ghc.haskell.org/trac/ghc/ticket/3671#comment:1
<p>
Correction, obviously:
</p>
<pre class="wiki">takeRec i xs = let (hs,ts) = splitAt i xs in hs : takeRec i ts
spanRec p xs = let (hs,ts) = span p xs in hs : spanRec p ts
genericTakeRec i xs = let (hs,ts) = genericSplitAt i xs in hs : genericTakeRec i ts
</pre>
TicketholzenspTue, 17 Nov 2009 14:06:28 GMT
http://ghc.haskell.org/trac/ghc/ticket/3671#comment:2
http://ghc.haskell.org/trac/ghc/ticket/3671#comment:2
<p>
Oh my, so sloppy; forgot base cases. Last try.
</p>
<pre class="wiki">takeRec :: Int -> [a] -> [[a]]
takeRec = genericTakeRec
genericTakeRec :: (Integral a) => a -> [b] -> [[b]]
genericTakeRec n _ | n <= 0 = []
genericTakeRec _ [] = []
genericTakeRec i xs = let (hs,ts) = genericSplitAt i xs in hs : genericTakeRec i ts
spanRec :: (a -> Bool) -> [a] -> [[a]]
spanRec _ [] = []
spanRec p xs = let (hs,ts) = span p xs in hs : spanRec p ts
</pre>
Ticketmalcolm.wallace@…Wed, 18 Nov 2009 02:59:00 GMT
http://ghc.haskell.org/trac/ghc/ticket/3671#comment:3
http://ghc.haskell.org/trac/ghc/ticket/3671#comment:3
<p>
Although your recursive 'takeRec' makes some sense, the recursive 'spanRec' is more dubious.
</p>
<pre class="wiki">spanRec p xs = let (hs,ts) = span p xs in hs : spanRec p ts
</pre><p>
By the definition of 'span', the first element of 'ts' satisfies the predicate p. Thus, in the first recursive call, 'span' will split the remaining list into [] and ts, the second recursive call likewise, and so on ad infinitum.
</p>
<pre class="wiki">spanRec (==0) [1,2,3,0,4,5,6] = [1,2,3]:[]:[]:[]:[]...
</pre>
TicketholzenspWed, 18 Nov 2009 09:05:12 GMT
http://ghc.haskell.org/trac/ghc/ticket/3671#comment:4
http://ghc.haskell.org/trac/ghc/ticket/3671#comment:4
<p>
Ian remarked the same oversight:
</p>
<p>
<a class="ext-link" href="http://old.nabble.com/Proposal-(Trac-ticket--3671):-Add-takeRec,-genericTakeRec-and-spanRec-to-Data.List-td26390220.html"><span class="icon"></span>http://old.nabble.com/Proposal-(Trac-ticket--3671):-Add-takeRec,-genericTakeRec-and-spanRec-to-Data.List-td26390220.html</a>
</p>
<p>
New suggestion (with other names as suggested in the same mail thread):
</p>
<pre class="wiki">splitAts :: Int -> [a] -> [[a]]
splitAts = genericSplitAts
genericSplitAts :: (Integral a) => a -> [b] -> [[b]]
genericSplitAts n _ | n <= 0 = []
genericSplitAts _ [] = []
genericSplitAts i xs = let (hs,ts) = genericSplitAt i xs in hs : genericSplitAts i ts
spans :: (a -> Bool) -> [a] -> [[a]]
spans _ [] = []
spans p xs = let (hs,ts) = span p xs in hs : breaks p ts
breaks :: (a -> Bool) -> [a] -> [[a]]
breaks _ [] = []
breaks p xs = let (hs,ts) = break p xs in hs : spans p ts
</pre>
TicketiglooFri, 20 Nov 2009 20:58:31 GMTmilestone set
http://ghc.haskell.org/trac/ghc/ticket/3671#comment:5
http://ghc.haskell.org/trac/ghc/ticket/3671#comment:5
<ul>
<li><strong>milestone</strong>
set to <em>Not GHC</em>
</li>
</ul>
TicketiglooSun, 28 Nov 2010 15:54:54 GMTstatus changed; resolution set
http://ghc.haskell.org/trac/ghc/ticket/3671#comment:6
http://ghc.haskell.org/trac/ghc/ticket/3671#comment:6
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>wontfix</em>
</li>
</ul>
<p>
This looks like an abandoned proposal. If that's not the case, please
re-open and give a discussion summary and consensus decision, as
described on the
<a class="ext-link" href="http://www.haskell.org/haskellwiki/Library_submissions"><span class="icon"></span>process page</a>.
</p>
Ticket