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
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 ::
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
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
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.