A question concerning functional dependencies
Jerzy Karczmarczuk
karczma@info.unicaen.fr
Mon, 02 Sep 2002 11:46:13 +0200
I wanted to write a small package implementing vector spaces,
etc. A part of it is
class Module v s
where
(*>) :: s->v->v
defining the multiplication of a vector by a scalar: w = a*>v
Now, as in many other circumstances, concrete vectors are based
on concrete scalars, and I defined really: class Module v s | v->s .
One typical instance of vectors is the orthodox functional
construction
instance Num s => Module (v->s) s
where
(s*>f) x = s * (f x)
and such tests: u = 2.5 *> sin; res = u 3.14
pass without tears.
But I wanted also that operators of the type (b->s) -> (b->s),
for example: inver f = recip . f . recip
be vectors. So:
instance ...=> Module ((v->s)->(v->s)) s
where
(s*>op) f = s*>(op f)
But GHCi yells that two instances in view of the functional
dependency declared are in conflict. Since I believe that
I do not really understand fundeps in Haskell, and this is not
a GHC 'feature' only, I send this query to the haskell list.
I don't see this conflict. I could remove the fundep, but then
I have other (smaller, but a bit annoying) problems, so I want
to keep it, if only for my own instruction. Good people, help,
please.
Why v [->s] cannot "coexist" in this context with
((v->s)->v) [->s]
Of course all extensions, including overlapping instances are on.
Jerzy Karczmarczuk
Caen, France