[Haskell-beginners] Implementing instance of '^' operator

Chaddaï Fouché chaddai.fouche at gmail.com
Sat Jan 16 21:05:06 UTC 2016


(^) 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.

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).

-- 
Jedaï

Le dim. 3 janv. 2016 à 14:07, Harald Hanche-Olsen <hanche at math.ntnu.no> a
écrit :

> -----Original Message-----
> From: pmcilroy at gmail.com <pmcilroy at gmail.com>
> Date: 3 January 2016 at 07:55:53
>
> > As a ‘hello world’ example for type definitions, I like to define a
> numeric type that can
> > handle the mod p multiplicative group, where p is prime. This requires:
> > • Implementing interface functions
>
> […]
>
> I can’t help with the question you’re asking, but I have a minor nitpick:
> You want to have
> negate (Modp p 0) = Modp p 0,
> and not Modp p p as in your current implementation.
>
> – Harald
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160116/b6c14373/attachment.html>


More information about the Beginners mailing list