[plt-scheme] Matching typed structs in untyped code

From: Sam TH (samth at ccs.neu.edu)
Date: Tue Jun 9 12:18:28 EDT 2009

On Tue, Jun 9, 2009 at 12:09 PM, Noel Welsh<noelwelsh at gmail.com> wrote:
> It would be nice if I could pattern match in untyped code on
> structures defined in Typed Scheme code. Presently I get:
>
>  match: Dot does not refer to a structure definition in: Dot

Unfortunately, there's not really a way for Typed Scheme to make this
work in general.  The static information that match uses contains
references to the unprotected versions of the structure functions, so
it can't be allowed to be used from untyped code.  It's possible that
I could create a struct-info-specific workaround for this, but that
seems kind of ugly.

The other possibility is to create your own static struct info. For example:

#lang scheme/load

(module m typed-scheme
  (define-struct: x ([y : Number]))
  (define z (make-x 1))
  (provide (all-defined-out)))

(module n scheme
  (require (except-in 'm x))
  (define-struct x (y)
    #:omit-define-values)
  (match z
    [(struct x (a)) a]))

(require 'n)

-- 
sam th
samth at ccs.neu.edu


Posted on the users mailing list.