[Haskell-cafe] fundeps => type family

Tad Doxsee tad.doxsee at gmail.com
Sun Apr 3 22:35:54 CEST 2011


Ryan,

That did it!  Thanks a lot for your help.

Tad


On Sun, Apr 3, 2011 at 1:14 PM, Ryan Ingram <ryani.spam at gmail.com> wrote:
>
>
> On Sun, Apr 3, 2011 at 1:00 PM, Tad Doxsee <tad.doxsee at gmail.com> wrote:
>>
>>   "Equality constraints ... enable a simple translation of programs
>>    using functional dependencies into programs using family
>>    synonyms instead.
>>
>> So I tried:
>>
>> class (T s ~ a) => ShapeC a s where
>>  type T s :: *
>>  draw :: s -> String
>>  copyTo :: s -> T s -> T s -> s
>>
>> but got a compile error:
>>
>>  Alas, GHC 7.0 still cannot handle equality superclasses: T s ~ a
>>
>> So my question is, how does one convert the above code to use type
>> families instead of functional dependencies?  Is one technique
>> preferable over another?
>
> Sadly the documentation assumes the feature that you show is missing.  That
> said, you don't need that feature for the simple FD you have.
>
> Just do
>
> class ShapeC s where
>    type T s :: *
>    draw :: s -> String
>    copyTo :: s -> T s -> T s -> s
>
>
> This code should work:
>
> data ShapeD a = forall s. (ShapeC s, a ~ T s) => MkShapeD s
>
> instance ShapeC (ShapeD a) where
>     type T (ShapeD a) = a
>     draw (MkShapeD s) = draw s
>     copyTo (MkShapeD s) x y = MkShapeD (copyTo s x y)
>
>
>



More information about the Haskell-Cafe mailing list