[racket] TR and ports (in two senses)

From: Asumu Takikawa (asumu at ccs.neu.edu)
Date: Sun May 18 16:52:28 EDT 2014

On 2014-05-16 10:04:17 -0700, Jordan Johnson wrote:
>    As part of familiarizing myself with Typed Racket I thought I'd port one
>    or two of the untyped Racket libraries to TR. This raised a few questions:
>    1) Looking at the TR docs and GitHub repo, AFAICT new library ports go
>    in pkgs/typed-racket-pkgs/typed-racket-more/typed -- is that right?

Yes, that's right. Though in the long term with packages, I wonder if we
should have separate packages for the typed versions of libraries.

>    2) I don't see documentation or tests for other ported libraries in
>    general, presumably because they're just wrappers; so, does it suffice to
>    submit only one file -- the library itself -- or are there more files I'm
>    not noticing, that go with each library? (Seems I should be documenting
>    the types I define, but I don't see where those docs would go.)

You're right, we don't currently have docs or tests in place for those
wrappers. If you'd like to add some tests, it would probably make sense
to put them under `typed/<library>/tests` or `typed/tests/<library>`
perhaps.

>    3) One of the libs I looked at porting, openssl, raised a question about
>    subtyping: SSL ports. It appears to me that internally these are standard
>    Racket input/output ports tagged as special by the openssl library. It
>    seems straightforward enough to create an opaque type like
>
>      (require/opaque-type SSL-Port ssl-port? openssl)
>
>    but that doesn't capture the idea that every ssl-port should also be of
>    type Input-Port or Output-Port (as defined in TR already). First, is that
>    idea correct? And if so, what piece am I missing, to make that happen?

Unfortunately, there isn't currently a good way to specify that a
datatype implements an "interface" like being a port, a synchronizable
event, etc. in Typed Racket.

For this case, it probably makes sense to just use the built-in Port
types, which makes the types less precise but it'll work. So you'd give
`ssl-abandon-port` a type like `(-> Port Void)`. Similarly, the
`tcp-abandon-port` function has that same type even though it's supposed
to only take tcp-ports.

Cheers,
Asumu

Posted on the users mailing list.