Hi Marcin,
| module M where
|
| class Seq s a | s -> a where
| m :: Seq s b => (a -> b) -> s a -> s b
This combination of constructor classes and functional dependencies
looks very odd! The dependency says that, if you pick a particular
implementation s of sequences, then there will be at most one choice
for the element type a. I can have lists of Char or lists of Int,
but not both together!
Perhaps you wanted something more like the following:
class Seq s a | s -> a where
m :: Seq t b => (a -> b) -> s -> t
Note that the kinds have changed here; s and t are both of kind *,
not * -> * as before. The trouble with this version is that it
doesn't require/ensure that you've used the same form of sequence
for both s and t. The parametric type classes folks had an answer
for this in the form of a constraint s ~ t requiring that the two
types had "the same outermost constructor", but I don't think it
was really a good solution either.
| instance Seq PS Char where
| m f (PS s) = PS (map f s)
|
| This is not accepted by Hugs:
Rightly so. With this definition, you've promised that the element
type corresponding to PS will be Char, which means that you can't
have a different element type in the returned collection!
Hope this helps!
All the best,
Mark