Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created June 20, 2012 19:04
Show Gist options
  • Save nikomatsakis/2961599 to your computer and use it in GitHub Desktop.
Save nikomatsakis/2961599 to your computer and use it in GitHub Desktop.

Map API

iface map<K, V: copy> {
    fn size() -> uint;
    fn insert(K, V) -> bool;
    fn contains_key(^K) -> bool;
    fn get(^K) -> V;
    fn find(^K) -> option<V>;
    fn remove(^K) -> option<V>;
    fn each(fn(^K, ^V) -> bool);
    fn each_key(fn(^K) -> bool);
    fn each_value(fn(^V) -> bool);
}


iface map<K, V: copy> {
    fn size() -> uint;
    fn insert(K, V) -> bool;
    fn contains_key(*K) -> bool;
    fn get(*K) -> V;
    fn find(*K) -> option<V>;
    fn remove(*K) -> option<V>;
    fn each(fn(*K, *V) -> bool);
    fn each_key(fn(*K) -> bool);
    fn each_value(fn(*V) -> bool);
}

Named regions

Right now we write:

^a.T
*a.T

However I think we should probably move away from .. If we want to use . as the module separator it will conflict and also it resembles field access. Maybe /?

^a/T
*a/T

This would kind of tie in with the notation for explicit region bounds (next section). But this is ultimately a separate question.

Explicit region bounds in types

You won't write these often (actually, hopefully never), but if you do need to name the region bound of a slice or closure, or name the "self" region for a nominal type in a box, it would probably look like:

[]/^r
fn/^r(S) -> T
@foo/^r

vs

[]/*r
fn/*r(S) -> T
@foo/*r

Alternatively, we could just drop the sigil in such cases altogether and write:

[]/r
fn/r(S) -> T
@foo/r

This loses the "intuitition" (if you can claim that there is anything intuitive about a type like @foo/^r) that the thing after the slash is a region but is substantially prettier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment