Sorry for my misunderstanding, but what’s the point of this? Why not just 
require the typed code in untyped code directly (as you’re doing in 'violator)? 
As far as I can tell, it looks like you’re just manually rewriting the 
generated contracts, so I’m not really sure what this achieves.

> On Mar 21, 2015, at 11:09, Matthew Butterick <m...@mbtype.com> wrote:
> 
> Is there an approved way of using #lang typed/racket/base/no-check (or maybe 
> `with-type`) to create libraries that have both a typed and untyped 
> interface? (The goal being to avoid use of `require/typed`)
> 
> For instance, the following works, but maybe it's a bad idea for other 
> reasons:
> 
> ;;;;;;;;;;;;;;;;;;;
> 
> ;; adder.rkt = write typed code, but leave off #lang line & `provide`
> 
> (: fladd (Flonum Flonum . -> . Flonum))
> (define (fladd f1 f2)
>  (+ f1 f2))
> ;;;;;;;;;;;;;;;;;;;
> 
> 
> ;;;;;;;;;;;;;;;;;;;
> 
> ;; typed.rkt = compile in typed context
> 
> #lang typed/racket/base
> (require racket/include)
> (provide fladd)
> (include "adder.rkt")
> ;;;;;;;;;;;;;;;;;;;
> 
> 
> ;;;;;;;;;;;;;;;;;;;
> 
> ;; untyped.rkt = compile in untyped context with contract
> 
> #lang typed/racket/base/no-check
> (require racket/include racket/contract racket/math)
> (provide (contract-out [fladd (flonum? flonum? . -> . flonum?)]))
> (include "adder.rkt")
> ;;;;;;;;;;;;;;;;;;;
> 
> 
> ;;;;;;;;;;;;;;;;;;;
> 
> ;; test.rkt
> 
> #lang racket/base
> 
> (module typed typed/racket/base
>  (require "typed.rkt")
>  (require typed/rackunit)
>  (check-equal? (fladd 1.0 2.0) 3.0)) ; typechecks correctly
> 
> (module untyped racket/base
>  (require "untyped.rkt")
>  (require rackunit)
>  (check-equal? (fladd 1.0 2.0) 3.0) ; meets `provide` contract
>  (check-exn exn:fail:contract? (λ () (fladd 1 2)))) ; violates `provide` 
> contract
> 
> (module violator racket/base
>  (require "typed.rkt")
>  (require rackunit)
>  (check-exn exn:fail:contract? (λ () (fladd 1 2)))) ; violates typed/untyped 
> contract barrier
> 
> (require 'typed)
> (require 'untyped)
> (require 'violator)
> ;;;;;;;;;;;;;;;;;;;
> 
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users


____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to