[plt-scheme] check underlying type when composing units

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Dec 8 20:42:54 EST 2004

I would change instantiate-A so that it re-exports its ordering unit 
and then change instantiate-V so that it always uses this ordering:

(define (instantiate-A impl-A@ order@)
   (compound-unit/sig
     (import)
     (link (O : ordered^ (order@))
           (A : A^ (impl-A@ O)))
     (export (unit O) (open A))))

(define (instantiate-B impl-B@ impl-A@)
   (compound-unit/sig
     (import)
     (link (O : ordered^ ((A O)))
           (A : A^ (impl-A@))
           (B : B^ (impl-B@ O A)))
     (export (open A))))

Now you're guaranteed that the two are the same. - Matthias


On Dec 8, 2004, at 6:24 PM, Pinku Surana wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> In the snippet below, how do I enforce that A@ and B@ have the same
> underlying implementation of ordered^ when I run instantiate-B? I want
> to prevent the following:
>
> (instantiate-B B@ string@ (instantiate-A A@ integer@))
>
> I'd prefer to keep A and B separate because their implementation might
> change, though the underlying ordered^ must be the same.
>
>
> Thanks.
>
>
> ;; code
>
> (define-signature ordered^ (elm= elm< elm<=))
> (define-signature A^ ((open ordered^) x y z))
> (define-signature B^ ((open ordered^) a b c))
>
> (define A@
>   (unit/sig A^ (import (o : ordered^))
>     ;; define elm=,elm<,elm<= in terms of the imported ordered^
>   ))
>
> (define B@
>   (unit/sig B^ (import (o : ordered^) (a : A^))
>     ;; define elm=,elm<,elm<= in terms of the imported ordered^
>     ;; these are different from A@
>   ))
>
> (define (instantiate-A impl-A@ order@)
>   (compound-unit/sig
>     (import)
>     (link (O : ordered^ (order@))
>           (A : A^ (impl-A@ O)))
>     (export (open A))))
>
> (define (instantiate-B impl-B@ order@ impl-A@)
>   (compound-unit/sig
>     (import)
>     (link (O : ordered^ (order@))
>           (A : A^ (impl-A@))
>           (B : B^ (impl-B@ O A)))
>     (export (open A))))



Posted on the users mailing list.