> On Aug 19, 2016, at 8:05 AM, Matthew Eric Bassett <mebass...@gegn.net> wrote:

> Is there a "correct" way to handle these sorts of cases?

The "correct" way right now is to give typed racket the information it needs 
for chaperoning on it, and unfortunately that means using the `#:struct` option 
in require/typed. 

However, that doesn't work if the untyped module hides the struct from the rest 
of the world, as your example does. I thought that using `unsafe-require/typed` 
with `#:opaque` would work, but actually, that gives the same warning:

#lang typed/racket
(require typed/racket/unsafe)
(unsafe-require/typed "untyped.rkt" [#:opaque My-Type my-type?] [my-type 
My-Type])
(my-type? my-type) ; produces #t
;; But also displays this warning:
;my-type?: contract violation
;  any-wrap/c: Unable to protect opaque value passed as `Any`
;  value: #<my-type>
;  This warning will become an error in a future release.
;  in: the 1st argument of
;      a part of the or/c of
;      (or/c
;       struct-predicate-procedure?/c
;       (-> Any boolean?))
;  contract from: (interface for my-type?)
;  blaming: .../typed.rkt
;   (assuming the contract is correct)
;  at: .../typed.rkt:3.54

To Everyone Else, should this be fixed, or is this the intended behavior?

So to work around that, you can use `define-new-subtype` along with 
`unsafe-require/typed`.

#lang typed/racket
(require typed/racket/unsafe)
(define-new-subtype My-Type (make-my-type My-Type))
(unsafe-require/typed "untyped.rkt" [my-type? (-> Any Boolean : My-Type)] 
[my-type My-Type])

;; Using it:
my-type ; #<my-type>
(my-type? my-type) ; #t
(my-type? 5) ; #f
(: f : My-Type -> Any)
(define (f x) x)
(f my-type) ; #<my-type>

Despite the `#:opaque` option being called `#:opaque`, it doesn't actually 
treat the value as opaque; it treats it as a value that a predicate can 
recognize. A different predicate could also return true for it, occurrence 
typing could assign it a new type, and it wouldn't be opaque at all. 

One solution for future typed racket would be another option more in the spirit 
of the `#:exists` option in `contract-out`. This would wrap the values of this 
type in a new opaque structure that it knows how to chaperone.

Alex Knauth

> Hi all,
> 
> I note that Racket 6.6 now issues warnings for certain generated
> contracts in typed/untyped interactions.  In particular, these warnings
> come up when requiring an untyped file from a typed file.  For example,
> say I have
> 
> test.rkt:
> ---------
> #lang racket
> 
> 
> (define my-type
> (let ()
>  (struct my-type () )
>  (my-type)))
> (define (my-type? x)
> (eq? x my-type))
> 
> 
> (provide my-type? my-type)
> 
> And follow that with type interactions:
> 
> $ racket -I typed/racket
> Welcome to Racket v6.6.
> -> (require/typed "test.rkt" [#:opaque My-Type my-type?] [my-type My-Type])
> my-type?: contract violation
>  any-wrap/c: Unable to protect opaque value passed as `Any`
>  value: #<my-type>
>  This warning will become an error in a future release.
>  in: the 1st argument of
>      a part of the or/c of
>      (or/c
>       struct-predicate-procedure?/c
>       (-> Any boolean?))
>  contract from: (interface for my-type?)
>  blaming: top-level
>   (assuming the contract is correct)
>  at: readline-input:1.44
> 
> I use a similar pattern to call the untyped db library from typed code,
> say with
> (require/typed db [#:opaque Sql-Null] [sql-null Sql-Null]), which would
> bring up a similar warning.
> 
> Is there a "correct" way to handle these sorts of cases?
> 
> Thanks!
> 
> Matthew Eric
> 
> -- 
> Matthew Eric Bassett | http://mebassett.info

-- 
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