[Haskell-cafe] ATs vs FDs

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Sat Aug 14 06:38:04 EDT 2010

Andrew Coppin <andrewcoppin at btinternet.com> writes:

> 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.

I assume you mean something like this?

| class NextOneUpFD this previous | this -> previous where ...
| instance NextOneUpFD Vector3 Vector4 where ...

If so, how does this not solve the issue?

| class NextOneUpAT v where
|   type Next v
|   ...
| instance NextOneUpAT Vector3 where
|   type Next Vector3 = Vector4
|   ...

Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com

More information about the Haskell-Cafe mailing list