<p dir="ltr">Hi Jake</p>
<p dir="ltr"><a href="https://hackage.haskell.org/package/applicative-numbers">https://hackage.haskell.org/package/applicative-numbers</a> can generate those instances.</p>
<p dir="ltr">Regards<br>
Adam</p>
<div class="gmail_quote">On Apr 22, 2016 10:23 AM, "Jake" <<a href="mailto:jake.waksbaum@gmail.com">jake.waksbaum@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Is it possible to automatically derive instances of Numeric type classes like Num, Fractional, Real, Floating, etc?<div><br></div><div>I currently have two datatypes, Pair and Triple, that are defined like this:</div><div><br></div><div>data Pair a = Pair a a</div><div>data Triple a = Triple a a a</div><div><br></div><div>I wrote these pretty trivial instances for Num and Floating:</div><div><br></div><div><div>instance Num a => Num (Pair a) where</div><div> (+) = liftA2 (+)</div><div> (*) = liftA2 (*)</div><div> abs = liftA abs</div><div> negate = liftA negate</div><div> signum = liftA signum</div><div> fromInteger = pure . fromInteger</div><div><br></div><div>instance Fractional a => Fractional (Pair a) where</div><div> (/) = liftA2 (/)</div><div> recip = liftA recip</div><div> fromRational = pure . fromRational</div></div><div><br></div><div>and practically identical instances for Triple as well.</div><div><br></div><div>Is there anyway to have GHC derive these instances and the other numeric type classes?</div><div><br></div><div>Thanks,</div><div>Jake</div></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div>