Mon, 21 Feb 2000 19:31:33 +0300 (MSK), S.D.Mechveliani <[EMAIL PROTECTED]> pisze:
> factorOverFinField_2:: --instance overlaps in ghc-4.06 **
> (Field fF, FactorizationRing (UPol fF))
> =>
> UPol (UPol fF) -> Factorization (UPol (UPol fF))
>
> factorOverFinField_2 f@(UPol _ a v dA) =
> if
> isZero f then error $ msg "f = 0\n"
> else ...
> pairs++(factorPrimitive $ canAssoc g)
> where
> ...
> factorPrimitive :: (Field fF, FactorizationRing (UPol fF))
> =>
> UPol (UPol fF)-> Factorization (UPol (UPol fF))
> factorPrimitive f = ...
Type variables in type signatures scope only over the signatures
themselves. fF in the signature of factorOverFinField_2 is independent
of fF in factorPrimitive. factorPrimitive would have to have the type
you specified (polymorphic wrt. fF), but your implementation, as the
wonderful error message said, provides only a function which shares
the type of field with factorOverFinField_2, not an independently
polymorphic one.
The only place where a type variable is not universally quantified at
the beginning of the type signature it occures in, is a type signature
of a method in a class definition. It is not possible to express the
type signature of your factorPrimitive in Haskell 98 nor in earlier
versions of Haskell.
GHC and Hugs have an extension of pattern type signatures. Read about
them in The GHC User's guide. Write:
factorOverFinField_2 (f@(UPol _ a v dA) :: UPol (UPol fF)) =
or specify the type (mentioning fF) of a component of f, to give a
name for the fF type which is accessible in type signatures local
to this function. Remove the context from the type signature of
factorPrimitive. The fF type variable is already constrained (even
when you omit the type signature of factorOverFinField_2 - well,
the constraint partially results from its usage in factorPrimitive).
The type signature of factorPrimitive merely mentions fF, it does
not introduce it.
--
__("< Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
\__/ GCS/M d- s+:-- a22 C+++$ UL++>++++$ P+++ L++>++++$ E-
^^ W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t
QRCZAK 5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-