[racket] Possible issue in the typed version of foldl

From: Vincent St-Amour (stamourv at ccs.neu.edu)
Date: Mon Oct 20 17:45:38 EDT 2014

Thanks for the report!

I pushed a fix earlier today.

Vincent



At Sun, 19 Oct 2014 23:16:11 -0700,
Jack Firth wrote:
> 
> I think there may be a mistake in the type definition of foldl for the case
> that accepts an initial value and three lists and a function of four values
> to fold them over. The following untyped code runs correctly:
> 
> #lang racket
> (define (f a b c d) d)
> (define ns '(0 1 2))
> (define vs '(a 2 "b"))
> (foldl f 'ok ns ns vs)
> 
> However, the typed form of this code gives a type error:
> 
> #lang typed/racket
> (define: (f [a : Natural] [b : Natural] [c : Any] [d : Symbol]) : Symbol d)
> (: ns (Listof Natural))
> (define ns '(0 1 2))
> (: vs (Listof Any))
> (define vs '(a 2 "b"))
> (foldl f 'ok ns ns vs)
> 
> Specifically, the type checker outputs:
> 
> Type Checker: Polymorphic function `foldl' could not be applied to arguments:
> Types: (-> a b c d d) d (Listof a) (Listof b) (Listof d) -> d
>        (-> a b c c) c (Listof a) (Listof b) -> c
>        (-> a b b) b (Listof a) -> b
> Arguments: (-> Nonnegative-Integer Nonnegative-Integer Any Symbol
> Symbol) 'ok (Listof Nonnegative-Integer) (Listof Nonnegative-Integer)
> (Listof Any)
> Expected result: AnyValues
>  in: (foldl f (quote ok) ns ns vs)
> 
> I think the issue may be in that first line of the type definition, (-> a b
> c d d) d (Listof a) (Listof b) (Listof d) -> d. Shouldn’t that last
> argument type be (Listof c) instead of (Listof d)?
>> [1.2  <text/html; UTF-8 (quoted-printable)>]
> 
> [2  <text/plain; us-ascii (7bit)>]
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users


Posted on the users mailing list.