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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to