[racket] Typed Racket: Command-line parsing problems

From: Tim K. (tk at crono.co.uk)
Date: Sun Jun 23 14:21:36 EDT 2013


I am using Typed Racket (version 5.2.1) and I'm porting an existing Racket 
program over to it. It's working well, except for a few minor things like 
"assoc" exclusively accepting lists of pairs and not lists of lists, which I 
found very odd (nothing a "filter" couldn't solve, though).
After porting nearly everything I was left with typing up the command-line 
parser. However, I am getting a type error at the following simplified part:

    #lang typed/racket
    (define: *filename* : String "")
    (define: *mode* : (U 'version 'unset 'do-something-useful) 'unset)
       #:program "mysuperprogram"
       (("-v" "--version") "Prints the version of the program"
                           (set! *mode* 'version))
       (("-i" "--file") fname
                        "The path to the file"
                        (set! *filename* fname)))

The error is:

    Type Checker: Mutation only allowed with compatible types:
    Any is not a subtype of String in: (set! *filename* fname)

I wonder, why does fname have the "Any" type? Yes, I didn't explicitly give 
fname a type, but I was hoping that the typed version of "command-line" 
would do that (after all, you'd expect a text interface to give you some 
sort of text in some encoding).
Also there doesn't seem to be a "command-line:" function. I tried using "
(fname : String)" instead of just "fname" but that doesn't work...

How can I get Strings out of this?

Best regards,

Posted on the users mailing list.