You can use the #{x : T} reader syntax to annotate variables in macros
like `command-line`. Here's a working version of your code:

```
#lang typed/racket

(define *channel* (make-parameter "#general"))
(define *message* : (Parameterof (Listof String)) (make-parameter '()))


(define (parse-cmdline)
  (command-line
   #:program "q"
   #:once-each
   [("-c" "--channel") #{ch : String} "slack channel to post (default:
use .qrc setting or default)" (*channel* ch)]
   #:args #{msg : String}
   (*message* msg)))
```

On Mon, Mar 6, 2017 at 2:08 AM, kay <klu...@gmail.com> wrote:
> For a complex syntax form like `command-line`, I have difficulty correctly 
> annotate the bindings it defines.
>
> More specifically, in the below code, for variable `msg`, even the 
> document[1] says the `#:args` binds as list of **strings**, but the error 
> indicates that it somehow is declared as `Listof Any`.
>
> Similarly, for variable `ch` bound in line 11, I believe it should always be 
> `String`, but it somehow is declared to be `Any`.
>
> What should I do with this type of error, if I want my varaibles to be more 
> precisely typed than just `Any`?
>
>
> [1]: 
> https://docs.racket-lang.org/reference/Command-Line_Parsing.html?q=command-line#%28form._%28%28lib._racket%2Fcmdline..rkt%29._command-line%29%29
>
> ```
>  1      #lang typed/racket
>  2
>  3      (define *channel* (make-parameter "#general"))
>  4      (define *message* : (Parameterof (Listof String)) (make-parameter 
> '()))
>  5
>  6
>  7      (define (parse-cmdline)
>  8          (command-line
>  9           #:program "q"
> 10           #:once-each
> 11           [("-c" "--channel") ch "slack channel to post (default: use .qrc 
> setting or default)" (*channel* ch)]
> 12           #:args msg
> 13           (*message* msg)))
> 14
> 15
> 16      #|
> 17      tr.rkt:11:91: Type Checker: Wrong argument to parameter - expected 
> String and got Any in: (*channel* ch)
> 18      tr.rkt:13:5: Type Checker: Wrong argument to parameter - expected 
> (Listof String) and got (Listof Any) in: (*message* msg)
> 19      |#
> ```
>
> --
> 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.

-- 
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