[racket-dev] typed/scheme n00b question

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Tue Sep 7 08:28:29 EDT 2010

On Tue, Sep 7, 2010 at 8:04 AM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
>
>> Why does everyone always want to use union for this?  Everything you
>> wrote there is correct, except that `U' should be `case-lambda'.
>
> There is something to be said for making the things that everyone
> writes first be the thing they should write. It is natural to me to
> think of a function with multiple arrow types as a union of some arrow
> types. Would it be so hard for Typed Racket to see a union of all
> arrows and just consider that the same as case-lambda? Is that wrong?

Yes, that's fundamentally wrong.  But I think your description makes
me see why people get this wrong.  If you think of a case-lambda as
"combining" in some sense a bunch of different functions, so that the
actual function is a set of smaller functions, then the union
interpretation makes sense.

The reason this is wrong is that isn't what union types mean at all -
they're a union in the set of *possible* values.  For example, the
inhabitants of the type (U Number String) aren't values that are some
combination of numbers and strings, the values are either numbers, or
strings.  Similarly, the inhabitants of the type Eli wrote might be a
function with *just one* of those behaviors (that type is a perfectly
good TR type), which wouldn't serve the purpose at all.

> If it is fundamentally wrong, some better form of explanation in the
> docs seem warranted.

I'll see about adding a note those.
-- 
sam th
samth at ccs.neu.edu


Posted on the dev mailing list.