Closed Bodigrim closed 4 years ago
I believe there was some performance reason this was originally introduced instead of GND because of some subtle inliner optimisation not firing. I'll double check and see if the benchmarks seem fine, then I'll merge this. Would definitely prefer less unsafeCoerce
whenever possible.
Cool merging now. Thanks 😊
1.0.2 is on Hackage now. https://hackage.haskell.org/package/galois-field-1.0.2
Instead of defining
newtype Prime (p :: Nat) = P Natural
and unsafe-coercing between it andMod p
, one can definePrime
to be a newtype wrapper overMod
and avoidunsafeCoerce
. It also allows to inherit many instances fromMod
by means of GND.I removed
instance Bits (Prime p)
, since bit fiddling with modular values is obviously highly unsafe. This instance is not used anywhere in the library and other types of fields do not define it, so I hope this is fine.I also removed
toP'
, which is nothing else but a legitimizedunsafeCoerce
. It does not really look appropriate for this library to depend on the internal representation ofData.Mod
. If an end user is so brave and so desperate, that safetoP
is not enough, he can probably reach out forunsafeCoerce
directly.