[racket] comparing structure types through contracts

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Tue Feb 7 10:30:23 EST 2012

Would a structure type property be a viable alternative?  Example:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#lang racket/load

(module a racket

  (define-values (prop:S S? S-ref) (make-struct-type-property 'S))
  (provide S?)

  (define-struct s (a b) #:transparent #:property prop:S #t)

  (provide/contract [struct s ([a number?]
                               [b number?])]))

(module b racket
  (require 'a)
  (define a-struct (make-s 3 4))
  (define-values (type _) (struct-info a-struct))
  (printf "type: ~s\n" type)
  (printf "S?: ~s\n" (S? (make-s 3 4)))
  (printf "eq? ~s\n" (eq? type struct:s)))

(require 'b)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Posted on the users mailing list.