<HTML><BODY><P>I know, what is the problem.<BR><BR> (Listof (Listof String)) is too wide. It allows '(() ("a" "b")), that is inusable for assoc.<BR><BR>So you should promise your sublists not to be empty.<BR><BR>(define: mystringlistlist : (Listof (Pairof String (Listof String))) (list (list "a"<BR>"b") (list "c" "d")))</P>
<P>(assoc "a" mystringlistlist) => '("a" "b")<BR><BR><BR><BR>Понедельник, 24 июня 2013, 8:40 UTC от "Tim K." <tk@crono.co.uk>:<BR></P>
<BLOCKQUOTE class=mailru-blockquote style="PADDING-BOTTOM: 0px; PADDING-TOP: 0px; PADDING-LEFT: 10px; MARGIN: 10px; BORDER-LEFT: #0857a6 1px solid; PADDING-RIGHT: 0px">
<DIV>
<DIV class="js-helper js-readmsg-msg">
<STYLE type=text/css></STYLE>
<DIV class=mr_read__body id=style_13720754850000001016><BASE href="https://e.mail.ru/" target=_self>
<DIV id=style_13720754850000001016_BODY>Sam Tobin-Hochstadt <samth@...> writes:<BR><BR>> Can you say more about the problem here? The type of `assoc` mentions<BR>> pairs, but you should be able to use it with lists, since they're made<BR>> of pairs.<BR><BR>Yeah, that's what I had expected as well. This code produces type errors (in<BR>5.3.3, too):<BR><BR> ;; Definitions<BR> (define: mystringlistlist : (Listof (Listof String)) (list (list "a"<BR>"b") (list "c" "d")))<BR> (define: mystringpairlist : (Listof (Pairof String String)) (list (cons<BR>"a" "b") (cons "c" "d")))<BR><BR> ; Works!<BR> (assoc "a" mystringpairlist)<BR> => '("a" . "b")<BR><BR> ; Type error<BR> (assoc "a" mystringlistlist)<BR><BR> Type Checker: Polymorphic function assoc could not be applied to arguments:<BR> Argument 1:<BR> Expected: a<BR> Given: String<BR> Argument 2:<BR> Expected: (Listof (Pairof a b))<BR> Given: (Listof (Listof String))<BR> in: (assoc "a" mystringlistlist)<BR><BR><BR>I thought that Racket maybe didn't accept "a" as a String, so I defined it<BR>as one and called assoc with that, but the error is exactly the same.<BR><BR><BR><BR>> Here's a version that type checks: <A href="https://gist.github.com/samth/5847063" target=_blank>https://gist.github.com/samth/5847063</A><BR>> <BR>> The key is giving a type annotation to `fname` using the #{} syntax.<BR>> Typed Racket can figure out how to typecheck the expansion only if you<BR>> give it that hint. And the #{} syntax is for adding such hints with<BR>> macros like `command-line` that didn't anticipate Typed Racket.<BR><BR>Ah, that works, thank you :)<BR>Did I not see that in the documentation or is this feature "experimental"?<BR><BR><BR>Best Regards,<BR>Tim<BR><BR><BR><BR><BR><BR>____________________<BR> Racket Users list:<BR> <A href="http://lists.racket-lang.org/users" target=_blank>http://lists.racket-lang.org/users</A><BR></DIV><BASE href="https://e.mail.ru/" target=_self></DIV></DIV></DIV></BLOCKQUOTE><BR><BR>-- <BR>Roman Klochkov<BR></BODY></HTML>