[plt-scheme] typed-scheme: conditional branches and parametric polymorphism

From: Jon Zeppieri (zeppieri at gmail.com)
Date: Thu Jan 28 15:43:10 EST 2010

2010/1/28 Jon Zeppieri <zeppieri at gmail.com>:
> For this particular function, it's easy just to handle the Fail case
> of Parser-Result first, and handle the Ok case in the else clause:
>
> (: || (All (A T) ((Parser A T) (Parser A T) -> (Parser A T))))
> (define (|| p1 p2)
>  (λ (tks ncur nmax)
>    (let ((r1 (p1 tks ncur nmax)))
>      (cond ((Fail? r1) (p2 tks ncur nmax))
>            (else r1)))))
>

Anyhow, I decided to give the alternative combinator variable arity,
so its type is now:
 (All (A T) ((Parser A T) * -> (Parser A T)))
... and the problem doesn't arise in the new function.

But, I have a new question.  I'm trying to type an analogous variable
arity sequence combinator.  The binary case would have the type:

(All (A B T) ((Parser A T) (Parser B T) -> (Parser (List A B) T)))

Can the vararg case be typed?  Following the example given for map in
the guide, I tried:

(All (T A ...) ((Parser A T) ... A -> (Parser (List A ... A) T)))

... but I get the error:

typecheck: Type variable A must be used with ... in: A

The first 'A' in the return type is highlighted.

-Jon


Posted on the users mailing list.