[Haskell-cafe] Playing with ATs again

Andrew Coppin andrewcoppin at btinternet.com
Tue Aug 3 13:25:07 EDT 2010

OK, so if you do something like

  class Container c where
    type Element c :: *

then we now have a clean and concise way to discover what type of 
element any given container holds. (Regardless of whether it's element 
type is parametric, hard-coded, class-constrained or anything else.) I 
really like this!

Now suppose that instead of a container type with an associated element 
type, what we want is several pairs of types having a one-to-one 
relationship, and we want to be able to traverse that relationship in 
either direction. What's the best way to do that?

(I tried just having two mirror image classes like the one above. But 
that doesn't work; there's no guarantee that going one way and then 
going back the other way will definitely take you back to where you 
started. I tried to make that a constraint, and got an error message 
that basically says "this feature is not implemented". Great. Still, 
there's probably a better way to do this.)

More information about the Haskell-Cafe mailing list