[Haskell-cafe] Time consumption nub
scook0 at gmail.com
Wed Jul 18 08:40:24 EDT 2007
On 7/18/07, Arie Groeneveld <bradypus at xs4all.nl> wrote:
> Ok, so when do I use nub instead of 'map head.group.sort' ?
> Using nub gave me a lot of trouble in terms of time consumption
> while handling long lists.
Well, nub is non-strict, so you can use it on infinite or partial
lists, provided you don't consume too much of the result.
Prelude Data.List> take 10 $ nub [1..]
Prelude Data.List> take 10 $ map head . group . sort $ [1..]
(Yes, taking nub of [1..] is silly; it's just an example.)
More information about the Haskell-Cafe