Hi, <br><br><div class="gmail_quote">On Thu, Jul 23, 2009 at 4:26 PM, Chaddaï Fouché <span dir="ltr">&lt;<a href="mailto:chaddai.fouche@gmail.com">chaddai.fouche@gmail.com</a>&gt;</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é&lt;<a href="mailto:chaddai.fouche@gmail.com">chaddai.fouche@gmail.com</a>&gt; wrote:<br>
&gt; Your instance would look like that :<br>
<br>
</div>Oops... I forgot to trim the extra parameters !<br>
<br>
&gt; instance IPAddr IPv4Addr where<br>
<div class="im">&gt;   type Host IPv4Addr = IPv4Host<br>
&gt;   type Mask IPv4Addr = IPv4Mask<br>
&gt;   host (IPv4Addr h _) = h<br>
&gt;   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&#39;t  compile:<br><br>Net/IP.hs:44:39:<br>    Couldn&#39;t match expected type `Word (Host a)&#39;<br>           against inferred type `Word (Mask a)&#39;<br>    In the second argument of `($)&#39;, namely `(bits h) .&amp;. (bits m)&#39;<br>
    In the first argument of `makeIPAddr&#39;, namely<br>        `(fromBits $ (bits h) .&amp;. (bits m))&#39;<br>    In the first argument of `($)&#39;, namely<br>        `makeIPAddr (fromBits $ (bits h) .&amp;. (bits m))&#39;<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&#39;m not sure how practical all this is going to be in the end (perhaps a bit to convoluted), but it&#39;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) =&gt; ...<br>
In your context rather than introducing h and m when they&#39;re not needed.<br>
<br>
If you need to write &quot;Host a&quot; several time in a function, you can put<br>
the following in your context :<br>
(IPAdrr a, Host a ~ h) =&gt; ...<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>