Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define free parameters and concrete #549

Closed
wants to merge 9 commits into from
Closed

Conversation

@Havvy
Copy link
Collaborator

@Havvy Havvy commented Mar 19, 2019

Fixes #548

I'm dissatisfied by just having two definitions and then mostly showing examples. But still better than nothing.

And while they're called "free variables" elsewhere, while we say they're generic parameters, I'd also like to call them "free parameters". I'd be willing to change generic parameter -> generic variable.

@Havvy Havvy requested a review from Centril Mar 19, 2019
@Centril Centril self-assigned this Mar 19, 2019
@Havvy Havvy force-pushed the Havvy:concrete branch 2 times, most recently from e003e82 to 5596bf9 Mar 19, 2019
src/items/generics.md Outdated Show resolved Hide resolved
The *free variables* of an item or type are the type and lifetime variables
that refer to a generically declared parameter. A *concrete item* or *concrete
type* is one that does not have any free variables. See [Wikipeida][concrete
wikipedia] for more.

This comment has been minimized.

@Centril

Centril Mar 19, 2019
Contributor

Some general notes about this paragraph that I think are not well captured:

  • Bounds/Constraints can also have free variables, e.g. u8: 'a has 'a as a free variable.
  • A lifetime can be concrete: 'static.
@@ -83,6 +83,56 @@ where
}
```

## Free variables and concrete items and types

The *free variables* of an item or type are the type and lifetime variables

This comment has been minimized.

@Centril

Centril Mar 19, 2019
Contributor

Suggested change
The *free variables* of an item or type are the type and lifetime variables
In a given context, the *free variables* of an item or type are the type and lifetime variables
src/items/generics.md Outdated Show resolved Hide resolved
src/items/generics.md Outdated Show resolved Hide resolved
src/items/generics.md Outdated Show resolved Hide resolved
src/items/generics.md Outdated Show resolved Hide resolved
src/items/generics.md Outdated Show resolved Hide resolved
src/items/generics.md Outdated Show resolved Hide resolved
| Type | Free Variables |
| `i32` | concrete |
| `&'a i32` | `'a` |
| `&'static i32` | concrete |

This comment has been minimized.

@Centril

Centril Mar 19, 2019
Contributor

Would be good to have &i32 and say that it has an (anonymous) free (inference) variable.

This comment has been minimized.

@Havvy

Havvy Mar 21, 2019
Author Collaborator

How's that?

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Well &i32 really means &'_ i32 and _ is a placeholder for something that may be substituted or unified with something else, possibly concrete.

@Havvy Havvy force-pushed the Havvy:concrete branch from aeb3575 to 3f817e1 Mar 21, 2019
@Havvy Havvy force-pushed the Havvy:concrete branch from 3f817e1 to 68b4b1d Mar 21, 2019
@Havvy
Copy link
Collaborator Author

@Havvy Havvy commented Mar 21, 2019

Rebased against master because of conflicts in glossary.md

itself. Furthermore, `foo` has `A` as a free variable because it uses it as the
type of its first argument. The function `bar` has `A` as a free type variable,
getting `A` from the trait's generic parameters. However, the lifetime `'b` is
bound in `baz` but is free in tye type `&'b SomeStruct`. Both `baz` and `quux`

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Suggested change
bound in `baz` but is free in tye type `&'b SomeStruct`. Both `baz` and `quux`
bound in `baz` but is free in the type `&'b SomeStruct`. All of these functions
also have `Self` as a free variable despite not being explicitly quantified.

This comment has been minimized.

@matthewjasper

matthewjasper Mar 21, 2019
Collaborator

Bound in bar

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

I don't follow...

}
```

In it, the trait `Example` has a free variable `A` because it declares it

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Suggested change
In it, the trait `Example` has a free variable `A` because it declares it
In it, the trait `Example` has a bound variable `A` because it declares it
type of its first argument. The function `bar` has `A` as a free type variable,
getting `A` from the trait's generic parameters. However, the lifetime `'b` is
bound in `baz` but is free in tye type `&'b SomeStruct`. Both `baz` and `quux`
have no free type variables and are thus concrete.

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Suggested change
have no free type variables and are thus concrete.
```

In it, the trait `Example` has a free variable `A` because it declares it
itself. Furthermore, `foo` has `A` as a free variable because it uses it as the

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Suggested change
itself. Furthermore, `foo` has `A` as a free variable because it uses it as the
itself. The trait also has `Self` as an implicitly bound variable. Furthermore, `foo` has `A` as a free variable because it uses it as the
@Havvy
Copy link
Collaborator Author

@Havvy Havvy commented Mar 21, 2019

The trait example needs to be rewritten, but that can be done as another PR. We also need an actual section on type and item constructors, but that should be its own PR. Further exposition on binders (and how unbinding through item declarations works) should also be done; also as its own PR? Perhaps next time I look at this, since the build just failed?


* [Types]
* Type constructors (for example, `Option` in `enum Option<T> { ... }`)
* Lifetimes (only lifetime variables)

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Not sure what you mean by this parenthetical...?

This comment has been minimized.

@Havvy

Havvy Mar 21, 2019
Author Collaborator

As in, no type variables are allowed in lifetimes.

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Ah; can you expand to "(only lifetime variables are allowed here)"?

@@ -83,6 +83,98 @@ where
}
```

## Formulae and Free Variables

The syntatic locations a *variable* is allowed is a *formulae*. Formulae for

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Suggested change
The syntatic locations a *variable* is allowed is a *formulae*. Formulae for
The syntatic locations a *variable* is allowed is a *formulae*.
Formulae which may include type and lifetime variables are:
## Formulae and Free Variables

The syntatic locations a *variable* is allowed is a *formulae*. Formulae for
type and lifetime variables are:

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Suggested change
type and lifetime variables are:
* `<T>` in `fn identity<T>(x: T) -> T { x }` for item constructors
* [Traits] and [implementations] implicitly bind `Self`

All type and lifetimes are unbound at the boundaries of items.

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Suggested change
All type and lifetimes are unbound at the boundaries of items.
All types and lifetimes are unbound at the boundaries of items.
* `<T>` in `fn identity<T>(x: T) -> T { x }` for item constructors
* [Traits] and [implementations] implicitly bind `Self`

All type and lifetimes are unbound at the boundaries of items.

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Also not sure what this sentence is saying...

This comment has been minimized.

@Havvy

Havvy Mar 21, 2019
Author Collaborator

T'was the last thing I wrote before my brain turned off. I need to expand it, but it's the fact that in the following example, CONST has no free variables, whether implicitly Self from traits or the generic parameter T of the function itself:

fn generic<T>(t: T) {
    const CONST: () = ();
}

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Ah yes; that's a good point, we don't have scoped type variables. Be careful not to imply that this applies to bar in trait Foo { fn bar(); } because Foo and bar are both in the syntactic category of items here.

Formulae nest. For example, in a function item, the entire function item is a
formulae but so are the types of the parameters of the function. A type or
lifetime variable may be free in one formulae but bound in a containing
formulae. For example, in the function prototype `for<'a> fn foo(a: &'a i32>`,

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Suggested change
formulae. For example, in the function prototype `for<'a> fn foo(a: &'a i32>`,
formulae. For example, in the function prototype `for<'a> fn foo(a: &'a i32)`,

"prototype"?

This comment has been minimized.

@Havvy

Havvy Mar 21, 2019
Author Collaborator

Name for everything of a function except the block expression. The part you can put in a trait. Do you have a better name?

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

I'd call this "function signature" or "function declaration".

formulae but so are the types of the parameters of the function. A type or
lifetime variable may be free in one formulae but bound in a containing
formulae. For example, in the function prototype `for<'a> fn foo(a: &'a i32>`,
`'a` is bound by the `for<'a>` but in the formulae of the type

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Suggested change
`'a` is bound by the `for<'a>` but in the formulae of the type
`'a` is bound by the binder `for<'a>` but in the type
formulae while having no free variables when looked at as another formulae. Most
commonly, the type or item will have a free variable when the type or item
constructor does not. For example, `Option<T>` as a type has `T` as a free
variable but as a type constructor, has no free variables.

This comment has been minimized.

@Centril

Centril Mar 21, 2019
Contributor

Suggested change
variable but as a type constructor, has no free variables.
variable but as a type constructor, `Option` has no free variables.

(it's not the same type expression so it's not a valid example)

@Centril
Copy link
Contributor

@Centril Centril commented Apr 8, 2020

cc @Havvy -- this is waiting for you if you want to pursue this further :)

@Havvy
Copy link
Collaborator Author

@Havvy Havvy commented Nov 5, 2020

Every time I get back to this, I always lead myself into an unhappy path. So closing.

@Havvy Havvy closed this Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.