graydon/rust — pull request #1051 by brson (2011-10-20 00:35:48+00:00)
Title: Bare functions, typesafe spawn, function subtyping

This series does a lot of things to implement bare functions. It results in some things being more complicated and/or less pleasant to use, so I'd like to provide an opportunity to review it before I push.

At the end of the series, `fn` is a bare function, `fn@` is a shared function and `lambda` is sugar for `fn@`.

385e595c introduces a spawn function that takes a bare function. This commit is still using a temporary `fn#` syntax for bare functions. Spawning now looks like

```
spawn(my_data, fn#(my_data: my_data_type) { /* work */ });
```

788be700 creates a subtyping relationship between function types, where `fn# < fn@ < block`. This is the only subtyping in the language besides `mutable?`, and the implementation is currently trivial as I've left the implementation of bare functions the same as closures.

7c814305 makes the big conversion from the existing `fn` to bare functions and shared closures. In the process many higher-order functions had to be changed to `fn@` and many generic functions had to be instantiated with bind (to convert them to a `fn@`).

TODO:

* After snapshotting, the temorary syntax needs to be removed.
* We need to make a decision about `fn@/lambda` and `fn&/block`, whether we want one or both forms.
* Spawn is still ultimately implemented in terms of shared closures, but that implementation is unexpected. Spawn should be rewritten.
* We need to be able to instantiate generic bare functions, but that requires monomorphising.
* Remove the environment parameter from bare functions and give them a single-word representation.