Proposal: Add chop function to Data.List

Edward Kmett ekmett at gmail.com
Wed Feb 9 02:32:33 CET 2011


+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 at 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 at 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20110208/77fbf853/attachment.htm>


More information about the Libraries mailing list