[plt-scheme] Using one signature in place of two

From: Noel Welsh (noelwelsh at gmail.com)
Date: Tue Dec 30 11:57:16 EST 2008

Hello all,

I'm having some fun with the unit system.

I have two signatures a^ and b^ which are used by mutually recursive
units.  The consumers of the resulting compound unit always want to
use the union of a^ and b^, so I defined a signature thus:

(define-signature c^ extends a^
  ((open b^)))

and consumers specify they import c^ and I invoke thus:

(define-values/invoke-unit consumer@
  (import c^)
  (export consumer^))

This, however, doesn't work.  I get complaints about duplicate
identifiers.  E.g.:

:unit: rename created duplicate identifier row-col->idx40 at: (rename
row^ (struct:row22 struct:row) (make-row23 make-row) ...

If I do instead:

(define-values/invoke-unit consumer@
  (import a^ b^)
  (export consumer^))

define-compound-unit: unit argument expects an untagged import with
signature c^, which this usage context does not supply

[I also got vector->values complaining about an out of range index,
which I think came from a sig with a struct, but I can't reproduce
right now]

Is there any way to preserve the abstraction?  I know if I define
consumer^ to import a^ and b^ then things work.

Example code below.  Play around with quoting to see different errors.

TIA,
Noel

----------

#lang scheme/base

(require scheme/unit)

(define-signature a^ (a))
(define-signature b^ (b))
(define-signature c^ extends a^ ((open b^)))
(define-signature consumer^ (foo))

(define-unit a@
  (import b^)
  (export a^)
  (define a 1))

(define-unit b@
  (import a^)
  (export b^)
  (define b 2))

(define-unit consumer1@
  (import c^)
  (export consumer^)
  (define foo (+ a b)))

(define-unit consumer2@
  (import a^ b^)
  (export consumer^)
  (define foo (+ a b)))

(define-values/invoke-unit
  (compound-unit/infer
   (import)
   (export a^ b^)
   (link a@ b@))
  (import)
  (export a^ b^))

'(define-values/invoke-unit consumer1@
  (import c^)
  (export consumer^))

'(define-values/invoke-unit consumer1@
  (import a^ b^)
  (export consumer^))

(define-values/invoke-unit consumer2@
  (import a^ b^)
  (export consumer^))


Posted on the users mailing list.