[plt-scheme] Typed Scheme polymorphic variadic functions

From: David Van Horn (dvanhorn at ccs.neu.edu)
Date: Tue Mar 17 14:53:23 EDT 2009

Anthony Cowley wrote:
> I am now having problems with the union type constructor:
> (U A ... A)
> is this also not currently supported?

(U A) = A
(U A A) = A
(U A ... A) = A

Maybe you've omitted some context that makes this example more 
interesting, but in this particular case you can just write A.

> For my own help in writing the typed list helpers I ginned up a quick
> testing infrastructure. This includes a function that runs down a list
> of tests, and I struggled a bit with its type signature before
> settling on one that is more general than it should be. A test is
> generated by a macro that builds each test as a list of a thunked
> expression, a value, and a string. This triple of (actual, expected,
> message) is not important, but the polymorphism of the checking
> function is somewhat interesting. This type is too general, but works
> if I apply check-all to an appropriate list as in (check-all
> list-of-tests):
> (: check-all ((Listof (List (-> Any) Any String)) -> Void))
> This type almost works, but not quite if I (apply check-all list-of-tests):
> (: check-all (All (A ...) ((List (-> A) A String) ... A -> Void)))
> Yet, if I write out (check-all (car lot) (cadr lot)) then it's fine
> (lot = list-of-tests). This might make some sense if type checking is
> purely syntactic, but since we do know the type of list-of-tests, I
> was hoping that the apply function could sort things out. Instead, I
> get an error message such as the following:
> typecheck: Bad arguments to polymorphic function in apply:
> Domain: (List (-> A) A String) ... A
> Arguments: (List (List (-> (Listof Integer)) (Listof Integer) String)
> (List (-> (Listof Integer)) (Listof Integer) String)) *

Does your function work in an untyped setting?  I'm guessing no.  Try it 
out first without types.  If it works, then send the code (or some small 
representative of the code).


Posted on the users mailing list.