<div>How does one bind an identifier to the matched structure?</div><div><br></div><div>In SML, Scala one can do something along the lines of s@S (x y z)</div><div><br></div><div><div>#lang typed/racket</div><div><br></div>
<div>(struct: Thing ())</div><div>(struct: Person Thing ([fname : String] [lname : String]))</div><div><br></div><div>(: person-name (Person -> String))</div><div>(define (person-name p)</div><div> (string-append (Person-lname p) ", " (Person-fname p)))</div>
<div><br></div><div>(define js (Person "Joe" "Smith"))</div><div><br></div><div>(: do-it (Thing -> String))</div><div>(define (do-it thing)</div><div> (match thing</div><div> ([Person fn ln]</div>
<div> (displayln fn)</div><div> (person-name thing))))</div></div><div><br></div><div>This fails as `thing' is not recognized as a Person.</div><div><br></div><div>I guess I'm wondering if there is something along the lines of the following in `match'.</div>
<div><br></div><div><div>(match thing</div><div> (p@[Person fn ln]</div><div> (person-name p)))) ;; p is typed as a Person</div></div><div><br></div>