Unfortunately, this seems not to work with Typed Racket. I'm not quite sure why -- something is going wrong in how it tries to figure out the types of the internal variables generated by the expansion of `match'. I will look into this further, thanks for letting me know.
On Fri, Apr 13, 2012 at 9:43 PM, Timothy Nelson <tbnel...@gmail.com> wrote: > One more question. Thanks for your patience. :-) > > I had this before: > (list args ...) > > which became: > (list #{args : (Listof Sexp)} ...) > > 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: > >> (match '(a b c) > [(list (? symbol? args) ... (? symbol? lastarg)) > (list args lastarg)]) > '((a b) c) > > 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: > (list (? symbol? #{args : (Listof Symbol)}) ... (? symbol? lastarg)) > > I get a bizarre type error: "Type Checker: Expected (Listof Symbol), but got > (Listof Any) in:", and then my entire (match ...). > > 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. > > Am I mis-using annotations? > > Thanks, > - Tim > > > On Thu, Apr 12, 2012 at 12:48 PM, Timothy Nelson <tbnel...@gmail.com> wrote: >> >> That fixes it for me. Thanks, both of you! >> >> >> On Thu, Apr 12, 2012 at 12:27 AM, Sam Tobin-Hochstadt <sa...@ccs.neu.edu> >> wrote: >>> >>> On Wed, Apr 11, 2012 at 3:36 PM, Timothy Nelson <tbnel...@gmail.com> >>> wrote: >>> > >>> > I'd like to write a function that consumes an s-expression and produces >>> > a >>> > struct -- something similar to building a tree struct out of a tree >>> > sexp. In >>> > the past, I've always used match for this kind of sexp manipulation. >>> > However, if I have a match clause within a function like this: >>> > >>> > (: my-func (Sexp -> mystruct)) >>> > (define (my-func s) >>> > (match s >>> > [(list args ...) (make-mystruct (map my-func args))])) >>> >>> The problem here is that Typed Racket can't guess what type you mean >>> for `args' to have, so you have to tell it when you bind `args'. That >>> looks like this: >>> >>> (: my-func (Sexp -> mystruct)) >>> (define (my-func s) >>> (match s >>> [(list #{args : (Listof Sexp)} ...) >>> (make-mystruct (map my-func args))])) >>> >>> which typechecks correctly for me. >>> -- >>> sam th >>> sa...@ccs.neu.edu >> >> > > > ____________________ > Racket Users list: > http://lists.racket-lang.org/users > -- sam th sa...@ccs.neu.edu ____________________ Racket Users list: http://lists.racket-lang.org/users