[Haskell] How to substract a list?

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Sun Mar 27 18:53:39 EST 2005


One answer is the infix operator (\\) defined in the List module (or in 
Data.List ...)

But it's in ont of the "set" operations. For example try :

[1..10] \\ [3..6]
[1,2,7,8,9,10]

But also :

([1..10]++[1..10]) \\ [3..6]
[1,2,7,8,9,10,1,2,7,8,9,10]

So _all_ the elements with values in [3..6] where removed !!
If that's what you want ! Perfect ... if not : what do you want exactly 
? List substraction is not uniq.

Pierre

Bright Sun a écrit :
> In Haskell, ++ can spends second list argument onto
> the end of first list argument.  How to substract the
> second list from the first list?
> 
> For example, 
> [(5,1),(4,1),(3,1),(2,1),(1,1)]
> substract
> [(2,1),(1,1)]
> I want to get result list:
> [(5,1),(4,1),(3,1)]
> 
> Tks.  
> 
> 
> 		
> __________________________________ 
> Do you Yahoo!? 
> Make Yahoo! your home page 
> http://www.yahoo.com/r/hs
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
> 

-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68


More information about the Haskell mailing list