[plt-scheme] Recognizing Listof in typed-scheme

From: Sam TH (samth at ccs.neu.edu)
Date: Mon Apr 6 10:27:25 EDT 2009

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.

sam th
samth at ccs.neu.edu

Posted on the users mailing list.