[plt-scheme] Matching typed structs in untyped code

From: Noel Welsh (noelwelsh at gmail.com)
Date: Tue Jun 9 12:19:16 EDT 2009

On Tue, Jun 9, 2009 at 5:15 PM, Matthias Felleisen<matthias at ccs.neu.edu> wrote:
> The philosophy behind Typed Scheme is "no matching required, needed, in
> demand". Code as you always have. -- Matthias

I don't quite follow that.  In this case pattern matching is very
compact and I would probably use pattern matching even if I wasn't
using Typed Scheme. This is the code:

(define (draw-mark dc mk)
  (match mk
   [(struct Dot (x y))
    (send dc draw-point x y)]
   [(struct Circle (x y r))
    (send dc draw-ellipse (- x r) (- y r) r r)]
   [(struct Box (l t w h))
    (send dc draw-rectangle l t w h)]
   [(struct Overlay mks)
    (for-each (lambda (mk)
                (draw-mark dc mk))


Posted on the users mailing list.