Original-Via: uk.ac.nsf; Tue, 26 Nov 91 02:54:29 GMT


If I have understood you correctly, there is not a problem.

If there is an instance declaration for class C and type T, it must occur
either in the module that declares C or the module that declares T, and is
exported whenever C or T is exported. So whenever C and T are in scope, so
is the C-T instance, and your problem cannot arise. (report 5.3.1)

--brian
        

        Suppose I define

                f x y z = if y==z then x*x else x

        the typing will be 

                f :: Num a, Eq b => a -> b -> b -> a

        with a and b quantified.  As far as I understand, the instantiations of Eq
        Num in scope at this point are irrelevant in the meaning of f.
        The rationale (presumably) is that since f is a closure, we might as
        well wait until it is applied to circumscribe its applicability.
        Now suppose I define

                g = f 3::Int

        the type for g will be

                Num Int, Eq b => b -> b -> Int

                My understanding is that, if Int is not an instance of Num at this
        point, an error will be declared (although g is also a function, and
        there is no particular reason not to wait until it is applied before
        checking that Int is an instance of Num).  This of course ignores
        the fact that Int is declared an instance of Num in the prelude.

        I guess I have two questions:

        1.  Am I right in my interpretation of the meaning of contexts?
        Is there some place in the report where this is explained?

        2.  If I am, what is the rationale for this decision?  It seems to me
            that if such checking is delayed at all, it ought to be delayed until
           it is time to print something!

        Satish


Reply via email to