<div dir="ltr"><div><div>(^) is _not_ a method of Num, it is simply a function with a Num constraint. It will work on your new numbers as well as it would on any other that implements (*) correctly, you don't need to rewrite it.<br><br></div>By the way, your functions are dangerously partial, it would seem useful to put the prime into the type so that you can't add or multiply different Mod p. Of course this demands a bit more knowledge of Haskell type system than is likely in a beginner, but if you're motivated, I encourage you to look at numbers in type (see GHC.TypeLits maybe).<br><br>-- <br></div>Jedaï<br></div><br><div class="gmail_quote"><div dir="ltr">Le dim. 3 janv. 2016 à 14:07, Harald Hanche-Olsen <<a href="mailto:hanche@math.ntnu.no">hanche@math.ntnu.no</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">-----Original Message-----<br>
From: <a href="mailto:pmcilroy@gmail.com" target="_blank">pmcilroy@gmail.com</a> <<a href="mailto:pmcilroy@gmail.com" target="_blank">pmcilroy@gmail.com</a>><br>
Date: 3 January 2016 at 07:55:53<br>
<br>
> As a ‘hello world’ example for type definitions, I like to define a numeric type that can<br>
> handle the mod p multiplicative group, where p is prime. This requires:<br>
> • Implementing interface functions<br>
<br>
[…]<br>
<br>
I can’t help with the question you’re asking, but I have a minor nitpick: You want to have<br>
negate (Modp p 0) = Modp p 0,<br>
and not Modp p p as in your current implementation.<br>
<br>
– Harald<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>