[racket] Typed Racket: Command-line parsing problems

From: Roman Klochkov (kalimehtar at mail.ru)
Date: Mon Jun 24 08:31:57 EDT 2013

I know, what is the problem.

 (Listof (Listof String)) is too wide. It allows '(() ("a" "b")), that is inusable for assoc.

So you should promise your sublists not to be empty.

(define: mystringlistlist : (Listof (Pairof String (Listof String))) (list (list "a"
"b") (list "c" "d")))
(assoc "a" mystringlistlist) => '("a" "b")

Понедельник, 24 июня 2013, 8:40 UTC от "Tim K." <tk at crono.co.uk>:
>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,
>  Racket Users list:
>   http://lists.racket-lang.org/users

Roman Klochkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130624/e34f0167/attachment-0001.html>

Posted on the users mailing list.