Start of topic | Skip to actions

Type of Cast Operator

Comparison With Softly Typed Languages' Cast

In concoqtion, the cast operator has the following type:

cast : \forall a, b. a = b -> a -> b

in most other languages, we have

cast : \forall a, b. a -> b

but this is type-unsafe. This type corresponds to one of two behviors:

(1) let rec f x = fx [non-termination]

(2) let f x = raise Exception [side-effect]

These are impossible to do in purely functional language with guaranteed termination. In a proof system, the type "\forall a, b. a -> b" says "you can prove anything", which trivializes the logical system and is undesirable. But Java has this; it does runtime type (tag) checking. This approach is equivalent to saying "just go ahead and do it, and worry later if it's sound, by checking tags."

By contrast, OCaml and other Hindley-Milner systems don't really need tags (if only for GC). E.g. Python -> OCaml conversion can enhance performance for that reason.

The other type (cast : \forall a, b. Eq a b -> a -> b) represents a sound inference. This only fails to work if the 'a is unsupplied due to non-termination. In concoqtion, because of the phase separation, this operation should be done statically.

Obj.magic

Obj.magic shouldn't show up anywhere. Hunt them and extinguish them! It's one of those dirty utilities that the language implementor needs to implement type-safe constructs, and never meant for the programmers who use the language. Its use must be avoided at all costs.

Inhabitance Game

Inhabitance means whether a type has a corresponding object. Example: how many inhabitants does this have?

\forall a. a -> a

This has one:

lambda x. x

Here's another.

\forall a. a -> a -> a

This has

lambda x. lambda y. x

lambda x. lambda y. y

(the terms' types are actually more general but we don't care as long as they're subtypes of the given type). We don't allow

lambda x. lambda y. car (cons x y)

because that reduces to the ones above. When we talk about inhabitance, we need some sort of normalization measure to look at the semantics of a piece of code instead of the syntax.

\forall a, b. a -> a

is inhabited only by

lambda x. lambda y. x

Here's a (at least intuitively) vacuous type:

\forall a. (a -> a) -> a

We don't have an a to feed to the function, i.e. we don't have the premise of the theorem (a -> a).

System F (probably) can type

lambda x. x x

but not

(lambda x. x x)(lambda x. x x)

Difference between \forall and \Pi

\Pi allows

\Pi a:k. T(a) \forall a.T(a) = \Pi _:a. T(a)

e.g.

\Pi n:nat. List (n) \Pi _:A . B = A -> B

Dual of \forall = \exists. Dual of \Pi a:k. T(a) = \Sigma a:k . T(a).

lambda x. e : A -> B Lambda a. e : \Pi x:A. B ?

Dr. Taha doesn't remember this well, so he'll sort things out by next time. More notes to come.

Reference: Roger Hindley "Basic Simple Type Theory"

-- Jun Inoue


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.