Start of topic | Skip to actions

Product (Big Pi) Types

How does

\Pi x:A.B

differ from

\Forall x.B

We will show that the big pi type is a generalized case of both

A -> B
and
\forall x.B

It is so powerful and complicated that both are its special cases.

Big pi typing rules

Big pi has the following typing rule:

\gamma \turn A type 
\gamma,x:A \turn M:B
----------------------
\gamma \turn \lambda x:A.M : \Pi x:A.B

A and B are types. We could get more detailed by making decisions via the lambda cube, but this is the basic structure.

The most important thing to note is that x occurs freely in BOTH M and B, not just M, as it would be in a classic lambda expression.

What can we write potentially with this kind of type? This allows dependent types. For example, sized lists. What does application look like?

\gamma \turn M:\Pi x:A.B
\gamma \turn N:A
----------------------
\gamma \turn M N : B[x = N]

x occurs as a free variable in B. Remove a free variable via substitution. The type B depends on the term N. This is dependent typing. Using arbitrary expressions in this way could potentially cause us to lose decidability in type checking.

We can introduce a new rule that allows us to test for equivalence. Equality might not be decidable.

\turn t1 = t2
\gamma \turn e : t1
----------------------
\gamma \turn e : t2

In concoqtion, introducing new rules like big pi types could break OCaml's type inference. To avoid this, concoqtion was developed with a strict separation between Coq types and classic OCaml types. Foralls introduce Coq variables, and tick expressions are Coq expressions. Terms of the tick type are not inferred.

Classic lambda typing rules

Looking at the typing rule for a classic lambda

\gamma,x:A \turn M:B
----------------------
\gamma \turn x:A.M : A -> B

We can determine that this is just a special case of the big pi type above. If we look at the application typing rule without dependent types, the only thing that goes away is the substitution of x to N in the return type.

Forall typing rules

So what is the difference between the big pi type and the forall type?

\gamma,x \turn M:B
----------------------
\gamma \turn \lambda x.M : \forall x.B

The only difference is that we don't care about the type of x. x is still a free variable in M and B. A is fixed here, it is always Type. Lets look at application for a forall type.

\gamma \turn M:\forall x.B
\gamma \turn N
----------------------
\gamma \turn M N : B[x = N]

How do you write the identity function using this?

\lambda X. \lambda x:X. x

which has type

\forall x. x -> x

Here, we have two different types of lambdas. Instead of using the same one, in Concoqtion, we use a big lambda instead. (Introduction of big lambdas is not necessary for decidability, but it creates much less clutter).

/\x.M:\forall x.B

There is only one universe of types - there is only one BNF for expressions, types, etc. It is up to the type system to differentiate the levels later on.


End of topic
Skip to actions | Back to top
Creative Commons LicenseThis work is licensed under a Creative Commons Attribution 2.5 License. Please follow our citation guidelines.