type fine until you try to use it

Abraham Egnor aegnor@antioch-college.edu
Mon, 13 Jan 2003 20:40:12 -0500 (EST)


In a project I'm working on, one data type I've defined is this:

data FilterIS = FilterIS { source :: (InputStream s) => s, filter ::
Filter }

which, to me, just means it holds any instance of the InputStream class
and a Filter value.  Sure, says ghci, fine by me.  However, if I try to do
anything with that datatype, even something as simple as

newFilterIS = FilterIS

I get the following error, or something very like it:

Stream.hs:96:
    Inferred type is less polymorphic than expected
        Quantified type variable `s' escapes
        Expected type: s -> t
        Inferred type: (forall s1. (InputStream s1) => s1)
                       -> (forall fs. (InputStream fs) => fs -> IO Word8)
-> FilterIS
    In the definition of `newFilterIS': FilterIS

I've gotten used to having to spend a while figuring out what error
messages mean, but it bugs me that there seems to be some problem with the
type that's "brought out" by just making a synonym for the constructor.  I
know there's nothing wrong with the line where I define a synonym; there's
practically nothing there to *be* wrong, so the problem has to be in the
type... and yet the compiler didn't catch it until I added that synonym
line.  What's up?

Abe