Fwd: [Haskell-cafe] ATs vs FDs

Gábor Lehel illissius at gmail.com
Sat Aug 14 06:32:24 EDT 2010

---------- Forwarded message ----------
From: Gábor Lehel <illissius at gmail.com>
Date: 2010/8/14
Subject: Re: [Haskell-cafe] ATs vs FDs
To: Andrew Coppin <andrewcoppin at btinternet.com>

You're missing equality constraints for classes.

In other words:

class (a ~ Smaller (Bigger a), a ~ Bigger (Smaller a)) => Vector a
where type Bigger a; type Smaller a

FDs and TFs are equivalent in theory, however their implementation in
GHC has shortcomings on (I believe) both sides. In this case, GHC
unfortunately doesn't yet support equality constraints in class
contexts, which you would need to do some of the things FDs can do.

I believe there are workarounds for this in some cases, including one
which uses plain type classes to encode not-quite-equality, and one
where you just add the constraints to every method of the class
instead, but I don't know the details.

On Sat, Aug 14, 2010 at 12:19 PM, Andrew Coppin
<andrewcoppin at btinternet.com> wrote:
> As I understand it, ATs were invented because FDs are "evil" and must never
> be used ever for any purpose. However, it doesn't seem to be possible to use
> ATs to do the same things that FDs can do.
> You can use ATs to write type functions, which take one type and return
> another type. This allows you to express type relationships in a very
> elegant way. However, what it does /not/ seem to allow you to do is express
> one-to-one relationships.
> For example, I'd like to be able to say that the next vector up from a
> Vector3 is a Vector4, and the next vector down is a Vector2. And I can say
> that. What I can't say is that the *only* next vector up is a Vector4. And
> thus, all my code is littered with ambiguous type warnings because although
> /currently/ there's only one class instance, somebody could come along some
> day and write another one.
> What am I missing?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

Work is punishment for failing to procrastinate effectively.

Work is punishment for failing to procrastinate effectively.

More information about the Haskell-Cafe mailing list