[racket] comparing structure types through contracts

From: John Clements (clements at brinckerhoff.org)
Date: Tue Feb 7 02:19:02 EST 2012

I'm working with Dave Herman's JavaScript package. I've found a problem and a workaround, but I want to make sure there's not an easier workaround before I convert a bunch of code.  The following program illustrates the issue:

#lang racket/load

(module a racket
  ;; this formulation "works" (prints #t):
  (define-struct/contract s ((a number?) (b number?)) #:transparent)
  (provide (struct-out s))
  ;; this formulation does not work (prints #f):
  #;(define-struct s (a b) #:transparent)
  #;(provide/contract [struct s ([a number?]
                               [b number?])]
                    #;(struct-out s)))

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

(require 'b)

The problem is that when a structure is defined using define-struct and then a contract is provided at the boundary, the structure type returned by struct-info doesn't compare to the exported struct's value using eq?.  As the code illustrates, I can work around this by pushing the contract down into the definition of the structure itself.

Before I change many pairs of structure-definitions & contracts, is there some other simpler way to make this code "work"--that is, print #t?



-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4624 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20120206/bb80aec0/attachment-0001.p7s>

Posted on the users mailing list.