[racket-dev] parse errors in types, poly-dots cause me headaches

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Nov 18 10:45:32 EST 2014

It's quite possible that this is Eli's bug again, but boy this causes headaches: 

> Type Checker: parse error in type;
>  type variable must be used with ...
>   variable: Y in: Y

And it points precisely to where Y is followed by ... 

	
#lang typed/racket 

(module+ test (require rackunit))

;; [Listof X] [X [Listof X] Y ... -> Y ...] Y ... -> Y ...
(: foldl* (All (X Y ...) (->* [Listof X] [->* X Y ... (Values Y ...)] Y ... (Values Y ...))))
(define (foldl* l f e1 . es)
  (define e+ (cons e1 es))
  (cond
    [(empty? l) (apply values e+)]
    [else (call-with-values 
           (lambda () (apply f (first l) e+))
           (lambda e*
             (unless (cons? e*) ;; should I check that (= (length e*) (length e+))
               (error 'fold* "f produced too few values: ~e" e*))
             (apply foldl* (rest l) f e*)))]))

(module+ test
  (define distances '(50 40 70 30 30))
  
  (check-equal? 
   (call-with-values 
    (lambda ()
      (foldl* distances
              (lambda (fst distance distance*)
                (values (+ fst distance) (cons (+ fst distance) distance*)))
              0
              '()))
    (lambda (_ x)
      (reverse x)))
   '(50 90 160 190 220)))



Posted on the dev mailing list.