Hello,

First thank Greg and Mathias for looking at my problem.

And yes, the proposed solution is working! I didn't think at all by putting a "module in the middle", to by-pass my cast operation.

Thank you!
Denis

On 04/16/2018 04:01 PM, Matthias Felleisen wrote:

Have you considered organizing your program as follows:

#lang racket

(module a racket
   (provide f)
   (define (f x) 10))

(module b racket
   (provide g)
   (define g (dynamic-require '(submod "foo.rkt" a) 'f)))

(module c typed/racket
   (require/typed (submod ".." b) [g (-> Integer Integer)])
   (g 20))

(require 'c)

That is, run the dynamic-require in an untyped module and then import it at the desired type?



On Apr 16, 2018, at 5:22 AM, mailoo <dmichi...@mailoo.org <mailto:dmichi...@mailoo.org>> wrote:


Hello,

I'm new to racket, and even more with typed/racket.

I play a little with the "Any" type (due to 'dynamic-require' which return Any), and I'm not able to cast them back in a function.

I (over) simplify my question with this little program :

```
(: p Any)
(define (p i) (displayln i))

; Here I want to get back my function
(define proc (cast p (-> Integer Void)))
(proc 2)

```

but I get this error when I try to execute the function :

```
; contract violation
;   Attempted to use a higher-order value passed as `Any` in untyped code: #<procedure:p>
;   in: Any
;   contract from: typed-world
;   blaming: cast
;    (assuming the contract is correct)
;   at: <pkgs>/racketFBP/test.rkt:13.13
; Context:
;  /home/denis/dev/racket/racketFBP/test.rkt:1:1 [running body]
; [Due to errors, REPL is just module language, requires, and stub definitions]
```

In reality, I get my function by `(dynamic-require path 'p)`, and I didn't find a typed version of this function...

Is there a way to go from Any to a function, or to replace my use of `dynamic-require`?

Thank you in advance,
Denis Michiels

--
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 <mailto:racket-users+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.


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