Trisha Shetty (Editor)

Kappa calculus

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

In mathematical logic, category theory, and computer science, kappa calculus is a formal system for defining first-order functions.

Contents

Unlike lambda calculus, kappa calculus has no higher-order functions; its functions are not first class objects. Kappa-calculus can be regarded as "a reformulation of the first-order fragment of typed lambda calculus".

Because its functions are not first-class objects, evaluation of kappa calculus expressions does not require closures.

Definition

The definition below has been adapted from the diagrams on pages 205 and 207 of Hasegawa.

Grammar

Kappa calculus consists of types and expressions, given by the grammar below:

τ = 1 τ × τ

e = x i d τ ! τ lift τ ( e ) e e κ x : 1 τ . e

In other words,

  • 1 is a type
  • If τ 1 and τ 2 are types then τ 1 × τ 2 is a type.
  • Every variable is an expression
  • If τ is a type then i d τ is an expression
  • If τ is a type then ! τ is an expression
  • If τ is a type and e is an expression then lift τ ( e ) is an expression
  • If e 1 and e 2 are expressions then e 1 e 2 is an expression
  • If x is a variable, τ is a type, and e is an expression, then κ x : 1 τ . e is an expression
  • The : 1 τ and the subscripts of id, !, and lift are sometimes omitted when they can be unambiguously determined from the context.

    Juxtaposition is often used as an abbreviation for a combination of " lift " and composition:

    Typing rules

    The presentation here uses sequents ( Γ e : τ ) rather than hypothetical judgments in order to ease comparison with the simply typed lambda calculus. This requires the additional Var rule, which does not appear in Hasegawa

    In kappa calculus an expression has two types: the type of its source and the type of its target. The notation e : τ 1 τ 2 is used to indicate that expression e has source type τ 1 and target type τ 2 .

    Expressions in kappa calculus are assigned types according to the following rules:

    In other words,

  • Var: assuming x : 1 τ lets you conclude that x : 1 τ
  • Id: for any type τ , i d τ : τ τ
  • Bang: for any type τ , ! τ : τ 1
  • Comp: if the target type of e 1 matches the source type of e 2 they may be composed to form an expression e 2 e 1 with the source type of e 1 and target type of e 2
  • Lift: if e : 1 τ 1 , then lift τ 2 ( e ) : τ 2 ( τ 1 × τ 2 )
  • Kappa: if we can conclude that e : τ 2 τ 3 under the assumption that x : 1 τ 1 , then we may conclude without that assumption that κ x : 1 τ 1 . e : τ 1 × τ 2 τ 3
  • Equalities

    Kappa calculus obeys the following equalities:

  • Neutrality: If f : τ 1 τ 2 then f i d τ 1 = f and f = i d τ 2 f
  • Associativity: If f : τ 1 τ 2 , g : τ 2 τ 3 , and h : τ 3 τ 4 , then ( h g ) f = h ( g f ) .
  • Terminality: If f : τ 1 and g : τ 1 then f = g
  • Lift-Reduction: ( κ x . f ) lift τ ( c ) = f [ c / x ]
  • Kappa-Reduction: κ x . ( h lift τ ( x ) ) = h if x is not free in h
  • The last two equalities are reduction rules for the calculus, rewriting from left to right.

    Properties

    The type 1 can be regarded as the unit type. Because of this, any two functions whose argument type is the same and whose result type is 1 should be equal – since there is only a single value of type 1 both functions must return that value for every argument (Terminality).

    Expressions with type 1 τ can be regarded as "constants" or values of "ground type"; this is because 1 is the unit type, and so a function from this type is necessarily a constant function. Note that the kappa rule allows abstractions only when the variable being abstracted has the type 1 τ for some τ . This is the basic mechanism which ensures that all functions are first-order.

    Categorical semantics

    Kappa calculus is intended to be the internal language of contextually complete categories.

    Examples

    Expressions with multiple arguments have source types which are "right-imbalanced" binary trees. For example, a function f with three arguments of types A, B, and C and result type D will have type

    If we define left-associative juxtaposition (f c) as an abbreviation for ( f lift ( c ) ) , then – assuming that a : 1 A , b : 1 B , and c : 1 C – we can apply this function:

    Since the expression f a b c has source type 1, it is a "ground value" and may be passed as an argument to another function. If g : ( D × E ) F , then

    Much like a curried function of type A ( B ( C D ) ) in lambda calculus, partial application is possible:

    However no higher types (i.e. ( τ τ ) τ ) are involved. Note that because the source type of f a is not 1, the following expression cannot be well-typed under the assumptions mentioned so far:

    Because successive application is used for multiple arguments it is not necessary to know the arity of a function in order to determine its typing; for example, if we know that c : 1 C then the expression

    is well-typed as long as j has type ( C × α ) β for some α and β . This property is important when calculating the principal type of an expression, something which can be difficult when attempting to exclude higher-order functions from typed lambda calculi by restricting the grammar of types.

    History

    Barendregt originally introduced the term "functional completeness" in the context of combinatory algebra. Kappa calculus arose out of efforts by Lambek to formulate an appropriate analogue of functional completeness for arbitrary categories (see Hermida and Jacobs, section 1). Hasegawa later developed kappa calculus into a usable (though simple) programming language including arithmetic over natural numbers and primitive recursion. Connections to arrows were later investigated by Power, Thielecke, and others.

    Variants

    It is possible to explore versions of kappa calculus with substructural types such as linear, affine, and ordered types. These extensions require eliminating or restricting the ! τ expression. In such circumstances the × type operator is not a true cartesian product, and is generally written to make this clear.

    References

    Kappa calculus Wikipedia