[bitc-dev] Internal and External function types

Jonathan S. Shapiro shap at eros-os.org
Tue Jul 25 02:14:46 EDT 2006


On Tue, 2006-07-25 at 02:11 -0400, Jonathan S. Shapiro wrote:
> Because of the "strip outermost mutability" rule, there is an
> interesting conundrum: what type should be assigned to the following
> procedure:
> 
>   (define (mut-c c)
>     (set! c #\a)
>     c)
> 
> Obviously, "c" must be mutable, and since this is correctly recognized
> by the symbol resolver, the type of MUT-C must surely be:
> 
>   [a] (fn ((mutable char)) (mutable char))
> 
> However, note that values are copied at procedure return, so it would be
> perfectly reasonable to assign the type:
> 
>   [b] (fn ((mutable char)) char)
> 
> But note that the argument "c" is copied at procedure call, so from the
> caller perspective it is also reasonable to assign the type:
> 
>   [c] (fn (char) char)
> 
> on the theory that it is none of the caller's business what MUT-C does
> with its private copy of the argument!


There is a corollary to this that involves type classes. In general, you
can't define multiple instances for the same type. For functions, the
relevant type is the *external* type. Therefore, the compiler currently
imposes the restriction that you cannot define two instances A, B in
such a way that the resulting methods would have colliding external
types.

shap



More information about the bitc-dev mailing list