[Haskell-cafe] type classes
Cotton Seed
cotton at alum.mit.edu
Wed Jul 2 21:42:58 EDT 2008
Hi everyone,
I'm working on a computational algebra program and I've run into a problem.
In my program, I have types for instances of algebraic objects, e.g. ZModN
for modular integers, and types for the objects themselves, e.g. ZModNTy for
the ring of modular integers.
Now, I want to subclass ZModNTy from something like
class RingTy a b where
order :: a -> Integer
units :: a -> [b]
where `a' represents algebraic object, and `b' the type of instances of that
object. I want an instance
instance RingTy ZModNTy ZModN where ...
but then code that only uses order fails with errors like
No instance for (RingTy ZModNTy b)
arising from a use of `order' at Test2.hs:16:8-15
since there is no constraint on the second type variable.
I think what I really want is
class RingTy a where
order :: a b -> Integer
units :: a b -> [b]
but this doesn't work either since ZModNTy is not parametric in its type
like, say, `Polynomial a' is.
Is this a common problem? Is there a standard way to handle it?
Thank you for your attention,
Cotton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080702/cb7a03e3/attachment.htm
More information about the Haskell-Cafe
mailing list