One more question. Thanks for your patience. :-)<div><br></div><div>I had this before:</div><div>(list args ...)<br><br>which became:</div><div>
(list #{args : (Listof Sexp)} ...)<br><br>Now suppose I want to match only a list of *symbols* instead of a list of Sexps, finishing with a symbol bound separately. In normal Racket, this would be:</div><div><br></div><div>
<div>> (match '(a b c) </div><div> [(list (? symbol? args) ... (? symbol? lastarg)) </div><div> (list args lastarg)])</div><div>'((a b) c)</div></div><div><br></div><div>If I leave this as-is in typed/racket I naturally get the same error as before, but if I annotate args in the same way as in my last question:</div>
<div>(list (? symbol? #{args : (Listof Symbol)}) ... (? symbol? lastarg))</div><div><br></div><div>I get a bizarre type error: "Type Checker: Expected (Listof Symbol), but got (Listof Any) in:", and then my entire (match ...). </div>
<div><br></div><div>If I annotate the (? symbol args) instead of just args -- I wasn't sure what the right syntax was -- I get the original expected (Listof Symbol) got (Listof Any) error.</div><div><br></div><div>Am I mis-using annotations?</div>
<div><br></div><div>Thanks,</div><div>- Tim<br>
<br><div class="gmail_quote">On Thu, Apr 12, 2012 at 12:48 PM, Timothy Nelson <span dir="ltr"><<a href="mailto:tbnelson@gmail.com" target="_blank">tbnelson@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
That fixes it for me. Thanks, both of you!<div><div></div><div><br><br><div class="gmail_quote">On Thu, Apr 12, 2012 at 12:27 AM, Sam Tobin-Hochstadt <span dir="ltr"><<a href="mailto:samth@ccs.neu.edu" target="_blank">samth@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Wed, Apr 11, 2012 at 3:36 PM, Timothy Nelson <<a href="mailto:tbnelson@gmail.com" target="_blank">tbnelson@gmail.com</a>> wrote:<br>
><br>
> I'd like to write a function that consumes an s-expression and produces a<br>
> struct -- something similar to building a tree struct out of a tree sexp. In<br>
> the past, I've always used match for this kind of sexp manipulation.<br>
> However, if I have a match clause within a function like this:<br>
><br>
> (: my-func (Sexp -> mystruct))<br>
> (define (my-func s)<br>
> (match s<br>
> [(list args ...) (make-mystruct (map my-func args))]))<br>
<br>
</div>The problem here is that Typed Racket can't guess what type you mean<br>
for `args' to have, so you have to tell it when you bind `args'. That<br>
looks like this:<br>
<div><br>
(: my-func (Sexp -> mystruct))<br>
(define (my-func s)<br>
(match s<br>
</div> [(list #{args : (Listof Sexp)} ...)<br>
<div> (make-mystruct (map my-func args))]))<br>
<br>
</div>which typechecks correctly for me.<br>
<font color="#888888">--<br>
sam th<br>
<a href="mailto:samth@ccs.neu.edu" target="_blank">samth@ccs.neu.edu</a><br>
</font></blockquote></div><br>
</div></div></blockquote></div><br></div>