[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: More on dispatching by function return type



On Tuesday, December 16, 2003 7:29 PM, Dan Sugalski 
[SMTP:dan@sidhe.org] wrote:
>
> I'm not sure CPS really has anything to do with it. CPS deals
> entirely with dispatching to and returning from (not that there's
> much difference) a function. Using the return type as part of the
> signature to determine which function to dispatch to seems orthogonal
> to how the dispatching actually happens.

I think that the idea is that we're presumably familiar with static 
dispatch on argument types (both Java and C++ do this to resolve method 
overloading).  CPSing the program shifts the return type into argument 
position.

The type of read is

forall a. (Read a) => String -> a

where the dispatch occurs on the return type.  The type of CPSed read 
is

forall a r. (Read a) => String -> (a -> r) -> r

and the dispatch occurs on the static type of the second argument.  If 
you pass not as a continuation, you get a version of read specialized 
for Bool, and if you pass (/ 2) you get a version of read specialized 
for some Fractional instance.

But I agree that it's probably easier to just think of dispatch on 
return type, since most programmers can't CPS-convert in their head. 
 (Another win for S-Expressions: you can CPS-convert in your sleep.)