[plt-dev] Typed Scheme: function type declarations should support optional args

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Mon Mar 29 11:06:35 EDT 2010

On Mon, Mar 29, 2010 at 11:01 AM, Noel Welsh <noelwelsh at gmail.com> wrote:
> On Mon, Mar 29, 2010 at 2:48 PM, Matthias Felleisen
> <matthias at ccs.neu.edu> wrote:
>> Can't he write a macro that unfolds into a type specification, at least for
>> his uses?
> I have, but it seems like something that is generally useful. PLT
> Scheme has had case-lambda for a long time. We know from experience
> that most of the time we use case-lambda to implement optional
> arguments using the pattern I described and hence the evolution from
> opt-lambda to built-in support for optional args in untyped Scheme.
> There is no reason to expect the situation is different in Typed
> Scheme.

I completely agree.

> This kind of code is not beautiful (a type defn for one of the
> built-ins that I recently added):
> [write-bytes-avail*  (cl-> [(-Bytes) (-opt -Nat)]
>                           [(-Bytes -Output-Port) (-opt -Nat)]
>                           [(-Bytes -Output-Port -Nat) (-opt -Nat)]
>                           [(-Bytes -Output-Port -Nat -Nat) (-opt -Nat)])]

If you're hacking on the internals of TS, there's a convenience
function for doing that. Look for `->opt'.

>> On Mar 29, 2010, at 9:44 AM, Sam Tobin-Hochstadt wrote:
>>> Really, there are two separate issues here - a convenient syntax for
>>> types with optional arguments, and support for defining functions with
>>> optional arguments.  The first is less of a pain, but probably
>>> something I could implement pretty easily.
> This would be nice.

I'll try to do this in the reasonably near future.  Suggestions for
syntax?  Note that it has to be work with the eventual addition of
possibly-optional keyword arguments.

>>> is significantly harder, because the expansion of such definitions is
>>> quite convoluted.  As a short-term work-around, you can use
>>> `opt-lambda' from `mzlib/etc', whose expansion is much simpler.
> So Typed Scheme doesn't currently implement it's own define?

I don't know what you mean here.  `define' and `lambda' in Typed
Scheme are the ones that don't support keyword or optional arguments,
as they are in the `mzscheme' language.  Typed Scheme does not
implement a separate `define'.
sam th
samth at ccs.neu.edu

Posted on the dev mailing list.