On Saturday, October 1, 2016 at 3:10:12 PM UTC+5:30, Sourav Datta wrote:
> I am currently trying to use racket/tcp library in a TR program and used 
> require/typed to import the necessary functions as I could not find this 
> provided with TR by default. However, the following code has a problem when 
> it runs:
> 
> #lang typed/racket
> 
> (require/typed racket/tcp
>                [opaque TCP-Listener tcp-listener?]
>                [tcp-listen (-> Number TCP-Listener)]
>                [tcp-accept (-> TCP-Listener (Values Number Number))])
> 
> (: server (-> Number Void))
> (define (server port)
>   (let ([listener (tcp-listen port)])
>     (define-values (inp outp) (tcp-accept listener))
>     (displayln inp)
>     (displayln outp)))
> 
> The code compiles fine but while running the "server" function with a valid 
> port it errors out:
> 
>  tcp-listen: broke its own contract
>   promised: tcp-listener?
>   produced: #<tcp-listener>
>   in: (-> any/c tcp-listener?)
>   contract from: (interface for tcp-listen)
>   blaming: (interface for tcp-listen)
>    (assuming the contract is correct)
>   at: unsaved-editor:5.16
> 
> I am not sure what exactly this error message means as tcp-listener is 
> creating a valid listener as given by "produced: #<tcp-listener>" but still 
> the predicate seems to be failing. The program runs fine with #lang racket. 
> Any help?
> 
> Thanks!

I found the cause of the problem. Already there are base type TCP-Listener 
which I should have used in the code instead of defining a new opaque type. 
Using that solves the problem and I found there are types for Input-Port and 
Output-Port as well. So that fixes the issue. However, it's still a bit 
surprising why the opaque type definition did not work with the tcp-listener? 
predicate though.

Thanks.

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