Question about sets

Hal Daume III hdaume@ISI.EDU
Tue, 20 Aug 2002 10:57:36 -0700 (PDT)


Sets of arbitrary elements are not possible, because, for instance, you
need to be able to compare elements to ensure no duplicates in the set and
you can't do this for any arbitrary pair of types.  Lists with arbitrary
elements are possible, but not very useful.  After all, what could you do
with them?  You don't know what type they are so you couldn't apply any
function to them, except for a function which doesn't depend in any way on
the type of its argument and hence doesn't depend on its argument at all.

Any example of such lists would be:

  data AnyList = AnyNil | forall a . AnyCons a AnyList

But I don't think this is what you really want.  If you need to be able to
store any two types in a list/set, use a union datatype, like:

  data Either a b = Left a | Right b

then you can have a set of, for example, Either Int String.  You can
generalize this on your own.




On Tue, 20 Aug 2002, Scott J. wrote:

> As far a I know sets can implemented by implementing a list of anything(a
> list of all types) The sets Haskell does have are AFAIK sets of elements of
> the same type: these are not general sets.
> 
> Scott
> 
> ----- Original Message -----
> From: "Ketil Z. Malde" <ketil@ii.uib.no>
> To: <haskell-cafe@haskell.org>
> Sent: Tuesday, August 20, 2002 8:56 AM
> Subject: Re: Question about sets
> 
> 
> > "Scott J." <jscott@planetinternet.be> writes:
> >
> > > I have a question. Why are sets not implemented in Haskell?
> >
> > What do you mean?  Isn't
> >
> >         http://www.haskell.org/ghc/docs/latest/html/hslibs/set.html
> >
> > sufficient?  (Remember to tell GHC '-package data')
> >
> > -kzm
> > --
> > If I haven't seen further, it is by standing in the footprints of giants
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe@haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>