defining (-> Bool) as a set
Simon Peyton-Jones
simonpj@microsoft.com
Mon, 22 Apr 2002 23:16:41 -0700
Hal,=20
[I think this sort of question would be better on the haskell-cafe
list.]
I don't think what you want can be done directly. It's the old
thing about not having lambdas at the type level. You want:
instance Eq a =3D> Coll (\x. x -> Bool) a where ...
and you just can't do that. You *can* abstract the second argument
of (->):
instance Eq a =3D> Coll ((->) Bool) a where ...
but not the first. It's a well known shortcoming in Haskell, that you
can
partially apply type constructors, but you can't do argument
permutation.
I know of no good solution. Adding type lambdas in their full glory
makes type inference pretty much impossible. What we'd like is
a compromise. Maybe someone can invent one. But take care.
The ground is littered with corpses.
Simon
| -----Original Message-----
| From: Hal Daume III [mailto:hdaume@ISI.EDU]=20
| Sent: 23 April 2002 01:30
| To: Jorge Adriano
| Cc: Haskell Mailing List
| Subject: Re: defining (-> Bool) as a set
|=20
|=20
| Yeah, both options suggested are valid, of course. But I=20
| really don't want to have a constructor and I'm using Edison=20
| where Coll is defined something like:
|=20
| class Coll c e where
| empty :: c e
| insert :: c e -> e -> c e
|=20
| etc., which precludes the fun dep solution.
|=20
| - Hal
|=20
| --
| Hal Daume III
|=20
| "Computer science is no more about computers | hdaume@isi.edu
| than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
|=20
| On Tue, 23 Apr 2002, Jorge Adriano wrote:
|=20
| >=20
| > > class Collection e ce | ce -> e where
| > > empty :: ce
| > > insert :: e -> ce -> ce
| > > member :: e -> ce -> Bool
| > >
| > > instance Eq a =3D> Collection a (a -> Bool) where
| > > empty =3D (\x -> False)
| > > insert e f =3D (\x -> if x =3D=3D e then True else f x)
| > > member e f =3D f e
| >=20
| > This is way better than my solution...
| >=20
| > I had never used multi-parameter classes before, so I forgot the=20
| > functional
| > dependency (right name? the "|ce->e"), and there was=20
| obviously no need for my=20
| > extra constructor.
| >=20
| > J.A.
| >=20
|=20
| _______________________________________________
| Haskell mailing list
| Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
|=20