+1 for the inclusion of chop. 

The unfoldr relationship is a good thing, because it gives an insight into when you can do 'chop fusion' by leaning on the unfoldr/destroy rules. ;) 

If we actually used unfoldr/destroy fusion, I'd probably advocate for defining chop in terms of unfoldr as a consequence, to facilitate rewriting, but noting the relationship at least provides a nice way to handle it for the stream fusion folks.

-Edward

On Tue, Dec 14, 2010 at 10:38 AM, Lennart Augustsson <lennart@augustsson.net> wrote:
Yes, chop can be easily written in terms of unfoldr.  But the chop function fits better with other existing list functions, like I tried to illustrate with my examples.

  -- Lennart


On Tue, Dec 14, 2010 at 10:40 AM, Stefan Holdermans <stefan@vectorfabrics.com> wrote:
Henning,

>> I would like to propose the following function for inclusion in Data.List
>> chop :: (a -> (b, [a]) -> [a] -> [b]
>> chop _ [] = []
>> chop f as = b : chop f as'
>>   where (b, as') = f as


> Is the difference between 'unfoldr' and 'chop' just the Maybe result type of f?


Yes.

 chop f = unfoldr g
   where
     g [] = Nothing
     g as = Just (f as)

Cheers,

 Stefan


_______________________________________________
Libraries mailing list
Libraries@haskell.org
http://www.haskell.org/mailman/listinfo/libraries