Hi,

Here is a MWE for something that is puzzling me. In file testtyped.rkt, I have

#lang typed/racket

(provide foobar)

(struct (T) foo
  ([x : (T -> T)]))

(define (foobar [a : Boolean])
  (if a
      (foo (lambda ([x : Number]) x))
      (foo (lambda ([x : String]) x))))

In the REPL, I can test this file and it works fine:

Language: typed/racket; memory limit: 2048 MB.
> foobar
- : (-> Boolean (U (foo Number) (foo String)))
#<procedure:foobar>
> (foobar #t)
- : (U (foo Number) (foo String))
#<foo>
> (foobar #f)
- : (U (foo Number) (foo String))
#<foo>


However, using it from non-typed racket causes an error.  If, in file
test.rkt we have:

#lang racket
(require "testtyped.rkt")

;;Note that this is _not_ typed/racket

Then the same example stops working:

> (foobar #t)
. . foobar: broke its own contract
  two of the clauses in the or/c might both match: (struct/c foo (->
Number any)) and (struct/c foo (-> String any))
  produced: #<foo>
  in: the range of
      (->
       (or/c #f #t)
       (or/c
        (struct/c foo (-> Number any))
        (struct/c foo (-> String any))))
  contract from:
      C:\Users\aml\Dropbox\AML\Projects\Rosetta\testtyped.rkt
  blaming: C:\Users\aml\Dropbox\AML\Projects\Rosetta\testtyped.rkt
   (assuming the contract is correct)
  at: C:\Users\aml\Dropbox\AML\Projects\Rosetta\testtyped.rkt:3.9

I know that Typed Racket has limitations in the generation of
contracts. Is this one of them? Is there a workaround?

Best,
António.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to