[Haskell] How to substract a list?

Mads Lindstrøm mads_lindstroem at yahoo.dk
Mon Mar 28 07:57:07 EST 2005


Hi

Bright Sun wrote:
> Hi, 
> 
> Tks, this is not what I wanted.
> 
> I want remove pairs list, 
> 
> [(5,1),(4,1),(3,1),(2,1),(1,1)] remove [(2,1),(1,1)]
> [(5,1),(4,1),(3,1)]

[(5,1),(4,1),(3,1),(2,1),(1,1)] \\ [(2,1),(1,1)]

should give the right result. Befere using the '\\' operator you may
need to load the List module (in Hugs :load List).

Hope it helps,

Mads Lindstrøm

> 
> so pairs [(2,1),(1,1)] removed.
> 
> Tks.
> 
> --- Pierre Barbier de Reuille
> <pierre.barbier at cirad.fr> wrote:
> > 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
> > 
> 
> 
> 		
> __________________________________ 
> Do you Yahoo!? 
> Yahoo! Small Business - Try our new resources site!
> http://smallbusiness.yahoo.com/resources/
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
> 



More information about the Haskell mailing list