[racket] Typed Racket: Command-line parsing problems

From: Tim K. (tk at crono.co.uk)
Date: Mon Jun 24 04:40:09 EDT 2013

Sam Tobin-Hochstadt <samth at ...> writes:

> Can you say more about the problem here?  The type of `assoc` mentions
> pairs, but you should be able to use it with lists, since they're made
> of pairs.

Yeah, that's what I had expected as well. This code produces type errors (in
5.3.3, too):

    ;; Definitions
    (define: mystringlistlist : (Listof (Listof String)) (list (list "a"
"b") (list "c" "d")))
    (define: mystringpairlist : (Listof (Pairof String String)) (list (cons
"a" "b") (cons "c" "d")))

    ; Works!
    (assoc "a" mystringpairlist)
    => '("a" . "b")

    ; Type error
    (assoc "a" mystringlistlist)

    Type Checker: Polymorphic function assoc could not be applied to arguments:
    Argument 1:
      Expected: a
      Given:    String
    Argument 2:
      Expected: (Listof (Pairof a b))
      Given:    (Listof (Listof String))
     in: (assoc "a" mystringlistlist)


I thought that Racket maybe didn't accept "a" as a String, so I defined it
as one and called assoc with that, but the error is exactly the same.



> Here's a version that type checks: https://gist.github.com/samth/5847063
> 
> The key is giving a type annotation to `fname` using the #{} syntax.
> Typed Racket can figure out how to typecheck the expansion only if you
> give it that hint.  And the #{} syntax is for adding such hints with
> macros like `command-line` that didn't anticipate Typed Racket.

Ah, that works, thank you :)
Did I not see that in the documentation or is this feature "experimental"?


Best Regards,
Tim






Posted on the users mailing list.