[racket] the typed Values restriction

From: Michael Wilber (gcr at sneakygcr.net)
Date: Wed Mar 18 17:16:28 EDT 2015

To expand a little bit on Sam's answer, this doesn't work in vanilla
Racket either.

    > (define (my-apply f) (let ([tmp (f)]) f))
    > (my-apply (lambda () (values 1 2)))
    result arity mismatch;
     expected number of values not received
      expected: 1
      received: 2
      values...:
       1
       2

Sam Tobin-Hochstadt <samth at cs.indiana.edu> writes:
> Type variables range only over types, and `(Values A B)` isn't a type.
> If your program type checked, then the following program would too:
>
> (: my-force : (All (A) (-> A) -> A))
> (define (my-force f)
>   (let ([tmp : A (f)]) tmp))
>
> (my-force (lambda () (values (void) (void)))
>
> but this program has a runtime error with the wrong number of values.
>
> Sam
>
> On Wed, Mar 18, 2015 at 4:48 PM, Benjamin Greenman <blg59 at cornell.edu> wrote:
>> Today I got a surprising type error that I think is worth sharing.
>>
>> (: my-force (All (A) (-> (-> A) A))
>> (define (my-force x) (x))
>>
>> (my-force (lambda () (values (void) (void)))
>> ;; ERROR! 'my-force' cannot be applied to argument.
>> ;; expected "(-> A)", got "(-> (values Void Void))"
>> ;; result type "A", expected result "AnyValues"
>>
>> (inst my-force (Values Void Void))
>> ;; Parse Error in type: "Values" is unbound
>>
>> That is all. I see now that Values is only allowed in result positions, but
>> I'd still expected this to work.
>>
>>
>> ____________________
>>   Racket Users list:
>>   http://lists.racket-lang.org/users
>>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.