I'm trying to get the Chinese Remainder Theorem algorithm to work, so I've been trawling online looking for help. I'm trying to just get this example of the CRT in haskell to compile, but I'm getting these errors. I've implemented my own extGCD
function.
extGCD :: Integer -> Integer -> (Integer, Integer, Integer)
extGCD a 0 = (a, 1, 0)
extGCD a b = let (q, r) = divMod a b
(d, m, n) = extGCD b r
in (d, n, m - n*q)
crt :: [Integer] -> [Integer] -> Integer
crt as ms = let {p = product ms
;ls = [extGCD x (div p x) !! 1 |x<- ms]
}in sum [ div (x*y*p) z | (x,y,z)<- zip3 as ls ms ]
Here's the error:
Couldn't match expected type `[t0]'
with actual type `(Integer, Integer, Integer)'
In the return type of a call of `extGCD'
In the first argument of `(!!)', namely `extGCD x (div p x)'
In the expression: extGCD x (div p x) !! 1
Failed, modules loaded: none.