[racket] Typed Racket Confusing Error Message / Type Check Error

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Wed Aug 1 13:45:40 EDT 2012

This looks like something that should work -- I'm not sure why TR
thinks that `Nothing` is the right type to infer for the second
parameter to the `Collection` type.  However, changing the last line
to:

  (((inst Collection-append D C) coll) elem))

makes it typecheck.

On Wed, Aug 1, 2012 at 12:17 PM, Ray Racine <ray.racine at gmail.com> wrote:
> The following gives an error of "Expected Nothing, but got D in elem."
> Type checking error?
>
> #lang typed/racket/base
>
> (struct: (D C) Collection ([append   : (D -> Void)]
>                            [build    : (-> C)]))
>
> (: List-Builder (All (D) -> (Collection D (Listof D))))
> (define (List-Builder)
>
>   (: lst (Listof D))
>   (define lst '())
>
>   (Collection (λ: ((datum : D))
>                 (set! lst (cons datum lst)))
>               (λ () lst)))
>
> (: build-Collection (All (D C) (Collection D C)-> C))
> (define (build-Collection collection)
>   ((Collection-build collection)))
>
> (: append-Collection (All (D C) (Collection D C) D -> Void))
> (define (append-Collection coll elem)
>   ((Collection-append coll) elem))
>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>



-- 
sam th
samth at ccs.neu.edu


Posted on the users mailing list.