[Haskell-cafe] nub vs. find + (:) Is this abysmal code?
Felipe Lessa
felipe.lessa at gmail.com
Sun Feb 10 10:20:59 EST 2008
On Feb 10, 2008 1:14 PM, Chaddaï Fouché <chaddai.fouche at gmail.com> 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 :: [Product] -> Product -> [Product]
addProduct inventory p = p : delete p inventory
> and probably even better with a Set instead of a List...
import qualified Data.Set as S
addProduct :: S.Set Product -> Product -> S.Set Product
addProduct = flip S.insert
--
Felipe.
More information about the Haskell-Cafe
mailing list