[Haskell-cafe] How to build an "Indicator Type" for a type class?
byorgey at seas.upenn.edu
Tue Jun 1 21:59:30 EDT 2010
Perhaps something here may be of use?
On Mon, May 31, 2010 at 01:32:18PM +0200, Steffen Schuldenzucker wrote:
> Dear Cafe,
> > data True
> > data False
> > class C a
> (arbitrary instances for C may follow)
> Now, how to obtain an "Indicator Type" for C, i.e. a type IndC that is defined
> via a type family / fundep / ... , so that
> IndC a = True forall a which are instances of C
> IndC a = False for all other a.
> I've collected some failed approaches here. My key problem is that if I
> define (in the 3rd try):
> > instance (C a) => IndC3 a True
> , it does *not* mean "Define this instance for all a which are an instance of
> C", but "Define the instance IndC3 a True for all types a, but it's not gonna
> work if a is not an instance of C".
> Does anyone have another idea?
> After having implemented type-level lists and a quicksort on them, I'd
> like to have type-level sets. In their most simple implementation, sets are
> just (unsorted) lists like this:
> > data Nil
> > data Cons a b
> > class Elem x l
> (instances for Elem so that Elem x l iff x is an element of the list l)
> Now I want:
> > type family Insert x s :: *
> Insert x s = s forall (x, s) with (Elem x s)
> Insert x s = Cons x s for all other (x, s).
> Thanks a lot!
>  http://hpaste.org/fastcgi/hpaste.fcgi/view?id=25832#a25832
>  Kiselyov, Peyton-Jones, Shan: "Fun with type functions"
>  I rewrote this algorithm using type families instead of fundeps:
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe