Re: A question concerning functional dependencies
At 2002-09-02 02:46, Jerzy Karczmarczuk wrote:
class Module v s | v->s . ... instance Num s => Module (v->s) s ... instance ...=> Module ((v->s)->(v->s)) s ... But GHCi yells that two instances in view of the functional dependency declared are in conflict.
GHCi is correct. Bear in mind GHC ignores contexts in instance declarations when calculating conflicts. This is unfortunate, but apparently fixing it would be hard. ((v->s)->(v->s)) is a substitution instance of (v->s). So from the first instance, instance ...=> Module (v->s) s GHC can derive instance ...=> Module ((v->s)->(v->s)) (v->s) ...which conflicts with your second instance per the fundep: instance ...=> Module ((v->s)->(v->s)) s The solution of course is to declare new datatypes: newtype Vector v s = MkVector (v->s) newtype Operator v s = MkOperator ((v->s)->(v->s)) etc. -- Ashley Yakeley, Seattle WA
On Mon, Sep 02, 2002 at 03:11:58AM -0700, Ashley Yakeley wrote:
At 2002-09-02 02:46, Jerzy Karczmarczuk wrote:
class Module v s | v->s . ... instance Num s => Module (v->s) s ... instance ...=> Module ((v->s)->(v->s)) s ... But GHCi yells that two instances in view of the functional dependency declared are in conflict.
GHCi is correct. Bear in mind GHC ignores contexts in instance declarations when calculating conflicts. This is unfortunate, but apparently fixing it would be hard.
Even taking contexts into account, these two might still conflict: if you had instance Num ((v->s)->v) for some values of v and s, you would get a conflict. GHC (and Hugs) check for potential conflicts like this unless you explicitly allow overlapping instances. --Dylan
participants (2)
-
Ashley Yakeley -
Dylan Thurston