Reply: Z_n in Haskell

2002-03-31 Thread Serge D. Mechveliani
Hello, Hal Daume III <[EMAIL PROTECTED]> writes about Z_n in Haskell: > Suppose I want to define integers modulo n, I could do this something > like: > data Zn = Zn Integer Integer -- modulus, number > > instance Num Zn where >(Zn m1 n1) + (Zn m2 n2) >

Re: Z_n in Haskell

2002-03-28 Thread oleg
The Z_n problem doesn't seem to be different from the problem of arrays or bitvectors of a statically-checkable size. If you prefer a decimal specification of the modulus, you may find the following articles relevant. Implementation of fixed-precision decimal types: Main> BV D1 0

Re: Z_n in Haskell

2002-03-28 Thread Ken Shan
On 2002-03-28T13:27:42-0800, Hal Daume III wrote: > Suppose I want to define integers modulo n, I could do this something Check out the message "Modular arithmetic" earlier on haskell-cafe (http://www.haskell.org/pipermail/haskell-cafe/2001-August/002132.html) and its followup... -- Edit this s

Z_n in Haskell

2002-03-28 Thread Hal Daume III
Suppose I want to define integers modulo n, I could do this something like: data Zn = Zn Integer Integer -- modulus, number instance Num Zn where (Zn m1 n1) + (Zn m2 n2) | m1 == m2 = Zn m1 (n1 + n2 `mod` m1) | otherwise= error "differing moduli" ...etc... However, I'd really like