No subject


Thu Jan 10 18:17:16 CET 2013


<br>
&gt; One compelling use of such type functions is to make type<br>
&gt; coercions implicit, especially in arithmetic. Suppose we want to be ab=
le to<br>
&gt; write add a b to add two numeric values a and b even if one is an Inte=
ger<br>
&gt; and the other is a Double (without writing fromIntegral explicitly).<b=
r>
<br>
And then an Add class is defined which can dispatch at the type-level<br>
to appropriate functions which resolve two types into one, with a<br>
catch-all case for Num.<br>
<br>
Has anyone put this into a package, for all common arithmetic<br>
operations? I would use it. Doing arithmetic stuff in Haskell always<br>
feels labored because of having constantly convert between number<br>
types.<br></blockquote><div><br></div><div>I prefer the current way (which =
is interestingly what Go chose as well). With implicit casts it&#39;s easy =
to shoot yourself in the foot e.g. when doing bit-twiddling. These two are =
different</div>


<div><br></div><div>f :: Word8 -&gt; Int -&gt; Word32</div><div>f w8 n =3D =
fromIntegral (w8 `shiftL` n)</div><div><br></div><div><div>f&#39; :: Word8 =
-&gt; Int -&gt; Word32</div><div>f&#39; w8 n =3D (fromIntegral w8) `shiftL`=
 n</div>


</div><div><br></div></div>

--485b397dd69791415b04d84f24f8--



More information about the Haskell-Cafe mailing list