Re: More on lists and sets
Date: 28 Mar 2006 03:46:45 -0800
Message-ID: <1143546405.035888.3990_at_u72g2000cwu.googlegroups.com>
Marshall Spight wrote:
> vc wrote:
> > Marshall Spight wrote:
> > > vc wrote:
> > > > paul c wrote:
> > > >
> > > > The usual list intersection opeartion (L = L1 intersect L2) is defined
> > > > as
> > > >
> > > > L = [x | x <- L1, x in L2]
> > >
> > > You speak as if "list intersection" is a well-defined, well-understood
> > > term with no significant disagreement.
> >
> > It's been so defined and understood starting at least with Lisp as well
> > as in languages like Scheme, Haskell and ML.
>
> I asked a Lisp programmer, and he said, no, that's not what
> means, and provided supporting common lisp documentation
> to show it having another meaning.
What other meaning did he have in mind ?
> I asked an SML programmer
> and he said it wasn't a term he was familiar with, but he would
> assume it meant the operation you described. I would have
> liked to have asked a Haskell programmer, but there are no
> working Haskell programmers in the USA (kidding) so I had
> to look it up in "Haskell: The Craft of Functional Programming"
> instead. No entries under "list intersection" and "intersection, list".
A Haskell standard library excerpt:
"17.2 "Set" operations
There are a number of "set" operations defined over the List type. nub
(meaning "essence") removes duplicates elements from a list. delete,
(\\), union and intersect (and their By variants) preserve the
invariant that their result does not contain duplicates, provided that
their first argument contains no duplicates.
nub removes duplicate elements from a list. For example:
nub [1,3,1,4,3,3] = [1,3,4]
delete x removes the first occurrence of x from its list argument, e.g.,
delete 'a' "banana" == "bnana"
(\\) is list difference (non-associative). In the result of xs \\ ys, the first occurrence of each element of ys in turn (if any) has been removed from xs. Thus, (xs ++ ys) \\ xs == ys.
union is list union, e.g.,
"dog" `union` "cow" == "dogcw"
intersect is list intersection, e.g.,
[1,2,3,4] `intersect` [2,4,6,8] == [2,4]
" Received on Tue Mar 28 2006 - 13:46:45 CEST