[Haskell-beginners] how to split a list

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Mon Mar 26 18:26:19 UTC 2018


> To be more explicit:

>    λ> :m +Data.List (groupBy)
>    λ> :m +Data.Function (on)
>    λ> l = [1,2, 3, 4, 6, 7, 9, 10]
>    λ> map (map snd) $ groupBy ((==) `on` snd) $ zip l (zipWith (-) l [1..])
>    [[0,0,0,0],[1,1],[2,2]]

I imagine that you mean fst instead of snd in order to produce the right output :)

How can I check if this code produce list copies and is efficient with big lists ?


thanks


Frederic


More information about the Beginners mailing list