Re: [Haskell-cafe] nub vs. find + (:) Is this abysmal code?

2008-02-10 Thread Chaddaï Fouché
2008/2/10, Michael Feathers [EMAIL PROTECTED]: How bad is this: addProduct :: [Product] - Product - [Product] addProduct inventory product = nub (product : inventory) This is pretty terrible, if the list is consumed afterward (which we assume it will be) we should have something like a

Re: [Haskell-cafe] nub vs. find + (:) Is this abysmal code?

2008-02-10 Thread Felipe Lessa
On Feb 10, 2008 1:14 PM, Chaddaï Fouché [EMAIL PROTECTED] wrote: This is much better, though probably better writed : addProduct :: [Product] - Product - [Product] addProduct inventory p | elem p inventory = p : inventory | otherwise = inventory Maybe addProduct ::

Re: [Haskell-cafe] nub vs. find + (:) Is this abysmal code?

2008-02-10 Thread Felipe Lessa
On Feb 10, 2008 1:07 PM, Michael Feathers [EMAIL PROTECTED] wrote: How bad is this: addProduct :: [Product] - Product - [Product] addProduct inventory product = nub (product : inventory) O(n²) as is nub. compared to this: addProduct :: [Product] - Product - [Product] addProduct

[Haskell-cafe] nub vs. find + (:) Is this abysmal code?

2008-02-10 Thread Michael Feathers
How bad is this: addProduct :: [Product] - Product - [Product] addProduct inventory product = nub (product : inventory) compared to this: addProduct :: [Product] - Product - [Product] addProduct inventory p | isNothing (find (==p) inventory)= p : inventory | otherwise

Re: [Haskell-cafe] nub vs. find + (:) Is this abysmal code?

2008-02-10 Thread Felipe Lessa
On Feb 10, 2008 1:20 PM, Felipe Lessa [EMAIL PROTECTED] wrote: Maybe addProduct :: [Product] - Product - [Product] addProduct inventory p = p : delete p inventory Oh, forget this, it will keep rewriting the tail of the list, which is a Bad Thing (TM). -- Felipe.