[Haskell-cafe] Am I using type families well?

Ryan Ingram ryani.spam at gmail.com
Tue Nov 2 17:58:59 EDT 2010


On Tue, Nov 2, 2010 at 12:32 AM, Yves Parès <limestrael at gmail.com> wrote:
> I understand your point Ryan, but in that case, why didn't the error occur
> when Resource and ResourceId were separated classes?

Because there was only one "retrieveLoc" for a particular IdOf, even
if resources shared an IdOf.

i.e.

instance ResourceId Int where
   type CfgOf Int = ()
   type LocOf Int = String
   retreiveLoc () n = "IntId " ++ show n

instance Resource () where
   type IdOf () = Int
instance Resource Int where
   type IdOf Int = Int

In this case
   retrieveLoc () (5 :: Int) = "IntId 5" without any ambiguity,
whereas when it was all one class there could be a different method to
retrieve the location for () and Int even if IdOf was both Int.

> BTW, I assume for your Int instance of Resource, you meant:
>> instance Resource Int where
>>   type IdOf Int = Int
>>   type LocOf Int = String
>>   type CfgOf Int = ()

Yes, that's correct.  Oops.

  -- ryan


More information about the Haskell-Cafe mailing list