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                                        = inventory


My guess is that the latter is more efficient, but then when I think about laziness, I wonder whether the first is a fair trade.

Michael
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to