Thanks for pointing it out. I also figured later that the multiple return 
values was the problem here.

Is this a TR type system limitation that polymorphic functions don't like 
multiple return values? Looks like it might be worth mentioning somewhere in 
the documentation or better in the error message.


On Sunday, March 5, 2017 at 1:54:54 AM UTC-8, WarGrey Gyoudmon Ju wrote:
> The problem is not the `AnyValues` since it accepts all types, but you cannot 
> instantiate a polymorphic type to return multiple values, so you have to 
> return (cons ... ...) in dynamic-wind then extract that pair as two return 
> values of the function.   
> 
> 
> On Sun, Mar 5, 2017 at 3:23 PM, kay <klu...@gmail.com> wrote:
> I have the following simple module that I'm converting to typed/racket. I got 
> a type check error that I don't know how to fix. More specifically, it's 
> related to the polymorphic function dynamic-wind's arguments. I read from 
> document [1] that type inference doesn't work for a lambda that is an 
> argument to a polymorphic function. But since here the three arguments are 
> all thunks (without input argument), I don't know how to properly annotate 
> them.
> 
> 
> 
> Note that I tried to even annotate the first argument:
> 
> 
> 
>   (λ () (ann #f AnyValues))
> 
> 
> 
> And the type checker complained:
> 
> 
> 
>   Argument 1:
> 
>     Expected: (-> AnyValues)
> 
>     Given:    (-> AnyValues)
> 
> 
> 
> which is really weird.
> 
> 
> 
> 
> 
> [1]: 
> https://docs.racket-lang.org/ts-guide/more.html#%28part._when-annotations~3f%29
> 
> 
> 
> 
> 
> 
> 
> Here's the module:
> 
> ------------------
> 
> 
> 
> #lang typed/racket
> 
> 
> 
> ;;(require racket/string racket/list racket/match racket/system racket/port 
> racket/function)
> 
> (provide execute)
> 
> 
> 
> (: execute (-> String * (Values String String)))
> 
> (define (execute . args)
> 
>   (define cmdln (string-join args))
> 
>   (displayln (format "running ~a" cmdln))
> 
>   (match (process cmdln)
> 
>     [(list out in pid err f)
> 
> 
> 
>      (define cust (make-custodian))
> 
>      (dynamic-wind
> 
>       (λ () (ann #f AnyValues))
> 
> 
> 
>       (thunk
> 
>        (parameterize ([current-custodian cust])
> 
>          (define buf_stdout (open-output-string))
> 
>          (define buf_stderr (open-output-string))
> 
> 
> 
>          (thread (λ () (copy-port out buf_stdout (current-output-port))))
> 
>          (thread (λ () (copy-port err buf_stderr (current-error-port))))
> 
> 
> 
>          (displayln (f 'status))
> 
>          (f 'wait)
> 
> 
> 
>          (values (get-output-string buf_stdout) (get-output-string 
> buf_stderr))))
> 
> 
> 
>       (thunk (custodian-shutdown-all cust)))
> 
>      ]))
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Here's the type error:
> 
> ----------------------
> 
> 
> 
> . executor.rkt:14:5: Type Checker: Polymorphic function `dynamic-wind' could 
> not be applied to arguments:
> 
> Argument 1:
> 
>   Expected: (-> AnyValues)
> 
>   Given:    (-> AnyValues)
> 
> Argument 2:
> 
>   Expected: (-> a)
> 
>   Given:    (-> (values (String : (Top | Bot)) (String : (Top | Bot))))
> 
> Argument 3:
> 
>   Expected: (-> AnyValues)
> 
>   Given:    (-> Void)
> 
> 
> 
> Result type:     a
> 
> Expected result: (values String String)
> 
>  in: (dynamic-wind (λ () (ann #f AnyValues)) (thunk (parameterize 
> ((current-custodian cust)) (define buf_stdout (open-output-string)) (define 
> buf_stderr (open-output-string)) (thread (λ () (copy-port out buf_stdout 
> (current-output-port)))) (thread (λ () (copy-port err buf_stderr 
> (current-error-port)))) (displayln (f (quote status))) (f (quote wait)) 
> (values (get-output-string buf_stdout) (get-output-string buf_stderr)))) 
> (thunk (custodian-shutdown-all cust)))
> 
> 
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> 
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users...@googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to