• No results found

The previous two presentations assume that, while linear and non-linear variables should be treated differently, all types are inherently the same. Kind-based presentations of linear logic suggest that linear data is inherently different from non-linear data, and the type system should distinguish them.

System F○ (pronounced “F-pop”), introduced by Mazurak et al. (2010), has a kind ∗ (“star”) for non-linear types and a kind ○(“pop”) for linear types. The kinding judgment ⊢Kσ∶κassigns each typeσa kindκ∈ {∗,○}. Like System F (Girard, 1971, 1986), System F○

allows type variables and quantification over type variables X. Φ⊢Kσ∶ ∗ Φ⊢Kσ∶ ○ sub Φ⊢Kσ1∶κ1 Φ⊢Kσ2∶κ2 Φ⊢Kσ1 κ Ð→σ2∶κ → X∶κ∈Φ Φ⊢KX∶κ tvar Φ, X∶κ1⊢Kσ∶κ2 Φ⊢K∀X∶k1. σ∶k2 ∀

In the first rule, non-linear types can be coerced into linear types. In the second rule, a function depends on three parameters: the kind of its argument; the kind of its result; and the kind of the function itself, which annotates the top of the arrow. For example, the linear identity type may be given the type σ Ð→∗ σ for ⊢K σ ∶ ○, because although the

function uses its argument linearly, the function itself is linearly closed, and so can be used arbitrarily many times. So, although System F○ doesn’t include a ! operator on types, it can be approximated as !σ ≡Unit Ð→∗ σ ∶ ∗, where Unit ∶ ∗ is a non-linear unit type, and σ∶ ○ is a linear type.

Typing contexts can either be separated according to the kind of the type being stored, as in DILL, or they can be combined as in the resource-annotated calculi. We choose the latter presentation, and we again write Φ1+Φ2 for the linear merge of contexts Φ1 and Φ2.

The subkinding relation can be written as a reflexive, transitive relationκ1≥κ2, with∗ ≥ ○.

This relation can be extended to contexts Φ≥ κ to say that every type in Φ has kind κ′ such thatκ′≥κ. Φ≥ ∗ Φ, x∶σ⊢Ke∶σ F○-var Φ, x∶σ⊢Ke∶τ Φ≥κ Φ⊢Kλx.eˆ ∶σ κ Ð→τ F○-→-I Φ1⊢Ke∶σ κ Ð→τ Φ2⊢Ke′∶σ Φ1+Φ2⊢Keˆe′∶τ F○-→-E

Related work. Later calculi including Alms (Tov and Pucella, 2011) and Quill (Morris, 2016) present variations of System F○ with the addition of kind polymorphism and more nuanced subkinding. For example, in Alms (which is actually an affine type system), the identity function can be given the type ∀κ,∀(σ ∶κ), σ Ð→∗ σ. This makes it easier to reuse code and means that every well-typed program has a single most general type. However, the presentation of that most general type can be quite complex.

For example, in plain System F○, the expression ˆλx. ˆλy. x, which discards its second argument, can be given one of four types:

∀(X∶ ○)(Y ∶ ∗), XÐ→∗ Y Ð→○ X ∀(X∶ ○)(Y ∶ ∗), XÐ→○ Y Ð→○ X

∀(X∶ ∗)(Y ∶ ∗), XÐ→∗ Y Ð→∗ X ∀(X∶ ∗)(Y ∶ ∗), XÐ→○ Y Ð→∗ X In Alms, however, this argument can be given a single most general type:

∀(X∶κ)(Y ∶ ∗), XÐ→∗ Y Ð→k X (2.1) The four types above are all subtypes of Equation (2.1).

Embedded System F○. An embedded version of System F○ would have its types of kind ∗ overlap with host-language types, but types of kind ○ be distinct. Let Kind be a type with two constructors, ○ and ∗, and define Pop : Type to be a data kind of linear types. Then we can define JK∶Kind→Typeso that JK=Pop:

data Pop where Var : Nat → Pop Sub : Type → Pop

PopArrow : Π {κ1 κ2 : Kind}, Jκ1K → Jκ2K → Pop

data Kind where ∗ : Kind ○ : Kind

J∗K ≡ Pop J○K ≡ Type

The linear type Sub α : Pop corresponds to the subkinding rule sub. The linear type PopArrow σ1 σ2 corresponds only to σ1 Ð→○ σ2, as σ1 Ð→∗ σ2 must be a host-language type.

In particular, ifσ1 and σ2 both have kind∗, thenσ1Ð→∗ σ2 should correspond to the regular

host-language function type σ1→σ2. However, if either σ1 orσ2 has kind○, then the type

should be uninhabited.

data StarArrow : Π (κ1 κ2 : Kind), Jκ1K → Jκ2K → Type where

Arrow : Π (α β : Type), (α→β)→ StarArrow α β

If made explicit, the subkinding relation from ∗ to ○could give some indication about the behavior of put, which injects host-language data into the linear embedded language. For example, we might expect host data a ∶α can be embedded into put a of ∗-type α, which can then be coerced to a linear typeSub α.

a∶α Φ≥ ∗

puta∶LExpK Φα

e∶LExpK Φα

e∶LExpK Φ(Sub α)

The subtyping relation should further coerce the type Sub (StarArrow σ1 σ2) into

PopArrow σ1 σ2 so that put(Arrow f)ˆput a reduces to put(f a). But this doesn’t fully

explain the semantics ofput—what if the argument toput Arrowf does not have the form puta?

System F○’s subkinding relation is implicit, but in an embedded language the two kinds would be explicit; thus F○’s meta-theory does not characterize a linear embedding.