With hammar help, I created a Haskell template that compiles
$(zModP 5)
to
newtype Z5 = Z5 Int instance Additive.C Z5 where (Z5 x) + (Z5 y) = Z5 $ (x + y) `mod` 5 ...
Now I have a problem, I donβt think I can solve this way.
The remarkable fact about polynomials is that they are irreducible in rational ones if they are irreducible modulo some prime p . I already have a method that brute force tries to lay polynomials over a given (final) field.
I want to try running this function for several fields. Here is what I want:
isIrreducible :: (FiniteField.C a) => Poly.T a -> Bool isIrreducible p = ... intPolyIrreducible :: Poly.T Int -> Bool intPolyIrreducible p = isIrreducible (p :: Poly.T Z2) || isIrreducible (p :: Poly.T Z3) || isIrreducible (p :: Poly.T Z5) || ...
Basically, I want to try running a factoring algorithm for a large number of "division" definitions.
I think it's possible to do this with TH, but it looks like it's forever. I am wondering if it is easy to pass my arithmetic operations as an isIrreducible parameter?
Alternatively, it seems like it could be something like a Newtype module, but I can't figure out how it will work without using TH in a way that would be difficult ...
Anyone have any thoughts on how best to do this?
haskell template-haskell abstract-algebra
Xodarap
source share