[Haskell-cafe] ATs vs FDs

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


Andrew Coppin <andrewcoppin at btinternet.com> writes:

> Ivan Lazar Miljenovic wrote:
>> I assume you mean something like this?
>>
>> ,---- 
>> | class NextOneUpFD this previous | this -> previous where ...
>> | | instance NextOneUpFD Vector3 Vector4 where ...
>> `----
>>   
>
> More like
>
>  class NextPrevFD next prev | next -> prev, prev -> next where...
>
> but yeah, that's the general idea.

Oh, I wasn't sure you could do that.

>> If so, how does this not solve the issue?
>>
>> ,----
>> | class NextOneUpAT v where
>> |   type Next v
>> |   ...
>> | | instance NextOneUpAT Vector3 where
>> |   type Next Vector3 = Vector4
>> |   ...
>> `----
>>   
>
> Can I use that to go both up and down? Would the types be unambiguous?
> I guess I'll have to go try it out...

Depends on how you use it; it might need to have a "type Previous v" in
there as well, but I'm not sure how well that will cope when you get to
the "end of the line".

One thing to note: GHC does not currently support superclass
constraints, so it isn't possible to have something like: 

  class (NextOneUpAT v1, NextOneUpAT v2, Next v1 ~ Next v2) => ...

But you _can_ do so in a type signature for a function.

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list