
On Thu, Jul 23, 2009 at 10:18 PM, Chaddaï
Fouché
Your instance would look like that :
instance IPAddr IPv4Addr IPv4Host IPv4Mask where type Host IPv4Addr = IPv4Host type Mask IPv4Addr = IPv4Mask host (IPv4Addr h _) = h mask (IPv4Addr _ m) = m
Oops... I forgot to trim the extra parameters !
instance IPAddr IPv4Addr where type Host IPv4Addr = IPv4Host type Mask IPv4Addr = IPv4Mask host (IPv4Addr h _) = h mask (IPv4Addr _ m) = m
One advantage compared to the multiparameter + functional dependencies solution is that you can write : (IPAddr a) => ... In your context rather than introducing h and m when they're not needed. If you need to write "Host a" several time in a function, you can put the following in your context : (IPAdrr a, Host a ~ h) => ... and use h for Host a thereafter. -- Jedaï