Hi, <br><br><div class="gmail_quote">On Thu, Jul 23, 2009 at 4:26 PM, Chaddaï Fouché <span dir="ltr"><<a href="mailto:chaddai.fouche@gmail.com">chaddai.fouche@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Thu, Jul 23, 2009 at 10:18 PM, Chaddaï<br>
Fouché<<a href="mailto:chaddai.fouche@gmail.com">chaddai.fouche@gmail.com</a>> wrote:<br>
> Your instance would look like that :<br>
<br>
</div>Oops... I forgot to trim the extra parameters !<br>
<br>
> instance IPAddr IPv4Addr where<br>
<div class="im">> type Host IPv4Addr = IPv4Host<br>
> type Mask IPv4Addr = IPv4Mask<br>
> host (IPv4Addr h _) = h<br>
> mask (IPv4Addr _ m) = m</div></blockquote><div><br>This is great stuff and exactly what I wanted. Thank you very much guys!<br><br>I kept on hacking at it and so far I have this code: <a href="http://hpaste.org/fastcgi/hpaste.fcgi/view?id=7428">http://hpaste.org/fastcgi/hpaste.fcgi/view?id=7428</a> <br>
which unfortunately doesn't compile:<br><br>Net/IP.hs:44:39:<br> Couldn't match expected type `Word (Host a)'<br> against inferred type `Word (Mask a)'<br> In the second argument of `($)', namely `(bits h) .&. (bits m)'<br>
In the first argument of `makeIPAddr', namely<br> `(fromBits $ (bits h) .&. (bits m))'<br> In the first argument of `($)', namely<br> `makeIPAddr (fromBits $ (bits h) .&. (bits m))'<br>
<br>In the declaration of the class IPAddr, is there any way to force that the IPHost and IPMask types are made up from the same IPBits type? Basically I would like the compiler to enforce that Word (Host a) and Word (Mask a) be the same type for a specific instance of IPAddr.<br>
<br>Note: I'm not sure how practical all this is going to be in the end (perhaps a bit to convoluted), but it's an excellent learning exercise for me.<br><br><br>Thanks a lot,<br><br>Patrick<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br>
<br>
</div>One advantage compared to the multiparameter + functional dependencies<br>
solution is that you can write :<br>
(IPAddr a) => ...<br>
In your context rather than introducing h and m when they're not needed.<br>
<br>
If you need to write "Host a" several time in a function, you can put<br>
the following in your context :<br>
(IPAdrr a, Host a ~ h) => ...<br>
and use h for Host a thereafter.<br>
<font color="#888888"><br>
--<br>
Jedaï<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>=====================<br>Patrick LeBoutillier<br>Rosemère, Québec, Canada<br>