[Haskell-beginners] splitAt implementation (using foldr) and infinite lists
Ozgur Akgun
ozgurakgun at gmail.com
Mon Apr 16 16:55:20 CEST 2012
You can also use lazy pattern matching.
http://en.wikibooks.org/wiki/Haskell/Laziness#Lazy_pattern_matching
On 16 April 2012 15:21, Lorenzo Bolla <lbolla at gmail.com> wrote:
> > splitAt' :: Int -> [a] -> ([a], [a])
> > splitAt' n = foldr (\x ~(z1, z2) -> if fst x <= n then (snd x : z1,
> z2)
> > else ([], snd x : z2))
> > ([], [])
> > . zip [1..]
>
Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120416/528b7ede/attachment.htm>
More information about the Beginners
mailing list