[racket] recommendations how to use Typed Racket with rackunit?

From: keydana at gmx.de (keydana at gmx.de)
Date: Sun Nov 28 12:41:44 EST 2010


changing some typed racket code from using define-struct: to struct:, I have problems getting my test code to run.
While still using define-struct:, I had a language specification of #lang typed/racket/no-check, because omitting the "no-check" I was getting the

Type Checker: Error in macro expansion -- untyped variable: run/inner

error. Now when using struct: with that language, I get the error:

Triple: illegal use of syntax in: (Triple "count" number? 1)

So now I have problems when using with and without "no-check"... Would someone perhaps have a suggestion what I might do to get the test code working in one or the other way?

Many thanks in advance!

BTW: Right now for posting, I wanted to put both the definitions and the test code in one file, and having everything in one module it worked fine. But when I have 2 modules like the code I'm appending below, I get the aforementioned error.

************   types.rkt   ***************************************************************************

#lang typed/racket

(provide (all-defined-out))

(define-type Value (U Number String)) 

(struct: Triple ((name : String) (type : (U (Any -> Boolean : Number) (Any -> Boolean : String))) (value : Value))
  #:property prop:equal+hash
    (list (lambda (t1 t2 equal?-recur) ; Attribute names are case insensitive, attribute type names are not; values are treated individually for each variant
            (and (string=? (string-upcase (Triple-name t1)) (string-upcase (Triple-name t2))) (eq? (Triple-type t1) (Triple-type t2)) (equal? (Triple-value t1) (Triple-value t2))))
          (lambda (t hash-recur)
            (+ (hash-recur (string-upcase (Triple-name t))) (* 3 (hash-recur (Triple-type t))) (* 3 (hash-recur (Triple-value t)))))
           (lambda (t hash2-recur)
            (+ (hash2-recur (string-upcase (Triple-name t))) (* 3 (hash2-recur (Triple-type t))) (* 3 (hash2-recur (Triple-value t)))))))

************   types-test.rkt   ***************************************************************************

#lang typed/racket/no-check
(require rackunit)
(require rackunit/text-ui)
(require "../types.rkt")

(define-test-suite equality-functions  
   "Triple equality"
   (let: ((t1 : Triple (Triple "count" number? 1)) (t2 : Triple (Triple "count" number? 1)) (t3 : Triple (Triple "count" string? "1")) (t4 : Triple (Triple "Count" number? 1)) (t5 : Triple (Triple "count" number? 2)))
         (check-equal? t1 t2)
         (check-equal? t1 t4)
         (check-not-equal? t1 t5))))

Posted on the users mailing list.