[racket] Question about match in typed/racket

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Thu Apr 12 00:27:32 EDT 2012

On Wed, Apr 11, 2012 at 3:36 PM, Timothy Nelson <tbnelson at 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
samth at ccs.neu.edu


Posted on the users mailing list.