[plt-scheme] structs in signatures

From: Dave Herman (dherman at ccs.neu.edu)
Date: Sun Jul 31 14:56:46 EDT 2005

Is there any real variation possible in a unit's implementation of a 
struct type exported by a signature?

Theoretically, you could add extra fields to the struct type, although 
in order for the constructor to have the same interface you'd have to 
give them all default values, and the unit would probably have to set! 
them elsewhere.

I tried doing this, incidentally, and couldn't get it to work with 
define-struct (as opposed to make-struct-type) because the following:

     (define-signature thing^
       (struct thing (foo bar)))

     (define thing@
       (unit/sig thing^ (import)
         (rename (make-thing/auto make-thing))
         (define-struct thing (foo bar baz))
         (define (make-thing/auto foo bar)
           (make-thing foo bar 'default-baz))))

..seems to silently ignore the `rename' clause and just export the 
original constructor instead of make-thing/auto; as a result you get an 
arity error when you try to use the constructor.

I don't understand the value in putting structs in a signature when 
there's nothing you can really do except force every implementing unit 
to provide exactly the same define-struct declaration.


Posted on the users mailing list.