[plt-scheme] Recognizing Listof in typed-scheme
Sam TH wrote:
> On Mon, Apr 6, 2009 at 10:20 AM, David Van Horn <dvanhorn at ccs.neu.edu> wrote:
>> Which would give you the right info, but I don't think TS allows these sorts
>> of things:
>>
>> (: f (U (Number -> Number) (String -> String)))
>> (define (f x)
>> (cond [(number? x) 1]
>> [(string? x) "a"]))
>
> This is a pretty common mistake ...
>
> (: f (case-lambda (Number -> Number) (String -> String))
>
> is the type you want. The union type you wrote up there is useless,
> that function can never be applied (apart from the fact that TS won't
> let you give that function that type). It would require an argument
> that is both a Number and a String, because of contravariance.
Ah, right! So this makes Paulo's program go through as written:
(: funct (case-lambda (foo -> foo1) (bar -> bar1)))
(define (funct f) ...)
David