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