[plt-scheme] Recognizing Listof in typed-scheme

From: Paulo J. Matos (pocmatos at gmail.com)
Date: Mon Apr 6 10:30:45 EDT 2009

On Mon, Apr 6, 2009 at 2:29 PM, David Van Horn <dvanhorn at ccs.neu.edu> wrote:
> 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) ...)
>

Indeed, thanks very much for all the help everyone! :)

> David
>
>



-- 
Paulo Jorge Matos - pocmatos at gmail.com
Webpage: http://www.personal.soton.ac.uk/pocm


Posted on the users mailing list.