[plt-scheme] How to define exceptions in typed-scheme?

From: Richard Cobbe (cobbe at ccs.neu.edu)
Date: Tue Jan 19 23:13:34 EST 2010

I'm using Typed Scheme, and I'm trying to define exception structures that
inherit from the native PLT exception hierarchy.  Typed-Scheme doesn't
provide types for these structs, so I'm having to do it myself with
require/typed.

I'm going to be defining exceptions (all extensions of exn:contract:fail)
in multiplex modules, so I would like to write an exn-typed module that
provides the necessary exn structs with types.  Unfortunately, that doesn't
work.

exns-typed.ss:

    #lang typed-scheme

    (require/typed scheme
      [struct exn ([message : String]
                   [continuation-marks : Continuation-Mark-Set])]
      [struct (exn:fail exn) ()]
      [struct (exn:fail:contract exn:fail) ()])

    (provide [struct-out exn]
             [struct-out exn:fail]
             [struct-out exn:fail:contract])

date.ss:

    #lang typed-scheme

    (require "exns-typed.ss")

    (define-struct: calendar-date ([month : Integer]
                                   [day : Integer]
                                   [year : Integer]))

    (define-struct: (exn:fail:contract:invalid-date-string exn:fail:contract)
      ([str : String]))

When I try to compile date.ss in DrScheme, I get the following error
message:

  struct-out: multiple imports (struct:exn and struct:exn) for structure-type identifier in: struct:exn

If I comment out the require in date.ss and replace it with the
require/typed clause from exns-typed.ss, things compile fine.  So this
appears to mean that I can't abstract out this clause into a separate
module.

Am I out of luck, or is there a way to accomplish this?

Thanks,

Richard


Posted on the users mailing list.