<div dir="ltr"><div class="markdown-here-wrapper" style><p style="margin:1.2em 0px!important">Following from a discussion on the list a few days ago, I’ve created a package for Typed Racket that lets you define function arguments to have some types by default, like so:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre;overflow:auto;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important">#lang typed/racket
(require type-conventions)
(define-type Bit (U Zero One))
(define-type-convention Bit bit)
(define: (flip bit) : Bit
(if (zero? bit) 1 0))
</code></pre><p style="margin:1.2em 0px!important">It keeps a table of conventions and provides a modified version of <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline;background-color:rgb(248,248,248)">define:</code> that extracts types based on the conventions table. Currently it supports typed keyword arguments, optional arguments, and rest arguments, as well as mixing explicitly typed arguments in with conventionally typed ones, even explicitly typed parameterized arguments. There’s some more functionality I want to implement, such as forms for anonymous functions and partially-applied functions, but it feels quite useful currently. The source is on Github here: <a href="https://github.com/JackFirth/type-conventions">https://github.com/JackFirth/type-conventions</a></p>
<p style="margin:1.2em 0px!important">I haven’t yet added documentation, but “example.rkt” details the exported forms and how they work. If anyone has any suggestions for more improvements, let me know.</p>
<div title="MDH:Rm9sbG93aW5nIGZyb20gYSBkaXNjdXNzaW9uIG9uIHRoZSBsaXN0IGEgZmV3IGRheXMgY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