Original-Via: uk.ac.nsf; Sat, 23 Nov 91 08:53:36 GMT

I am confused about the meaning of constraints imposed by a context.
I will try to illustrate my understanding with an example.  I am hoping that
the Gurus will either confirm or give another explanation.

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