[plt-scheme] structs in signatures

From: Scott Owens (sowens at cs.utah.edu)
Date: Sun Jul 31 15:32:20 EDT 2005

On Sunday 31 July 2005 12:56 pm, Dave Herman wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> Is there any real variation possible in a unit's implementation of a
> struct type exported by a signature?

(require (lib "unitsig.ss")
         (lib "plt-match.ss"))

(define-signature s^ ((struct s (f1 f2))))

(define u1
  (unit/sig s^ (import)
    (define struct:s #f)
    (define make-s cons)
    (define s? pair?)
    (define s-f1 car)
    (define s-f2 cdr)
    (define set-s-f1! set-car!)
    (define set-s-f2! set-cdr!)))

(define u2
  (unit/sig () (import s^)
    (match (make-s 1 2)
      ((struct s (x y)) (+ x y)))))

(invoke-unit/sig
 (compound-unit/sig
   (import)
   (link (U1 : s^ (u1))
         (U2 : () (u2 (U1 : s^))))
   (export)))

-Scott



Posted on the users mailing list.