|
| ||
|
|
Start of topic | Skip to actions
Signatures of eval and type_checkJoseph asked about the relation between typing judgment and typing at runtime. If we look at type of eval, eval : forall env. forall t. (env, t) tterm -> '(eval_env env) -> '(eval_t t) its type is indexed by env and t. The runtime typing comes from the type checker. type_check : term -> exists env. exists t. (env, t) tterm option Use of indexed types forces you to construct a type checker as a gateway to the indexed world from the unindexed. The typing judgment, i.e. the type of the type_check, is a constructive proof of well-typedness.Type-theoretic plusFor types we have a + operator augmented with deconstructors Left and Right, where the operands of the + are variants of the resultant type. For instance,type bool = 1 + 1 = True | Falsewhere = denotes isomorphism and "1" denotes a variant with only one concrete data corresponding to it. This works as: True = Left (1 + 1) = Left (bool) False = Right (1 + 1) = Right (bool)or vice versa. An option type is given by 'a option = 1 + 'a -> None = Left (1 + 'a) = 1 Some 'a = Right (1 + 'a) = 'aand denotes a construction that may fail. Uses of Indexed TypesIndexed type allows for highly parametrized interpreter. E.g. switch between call-by-name and value without incurring overhead. Staging removes layering cost.Crash-Course on Category TheoryDefinitionWikipedia Article A category C is a pair <ob(C), hom(C)>. ob(C) is the class of ''objects'' of C, and hom(C) is the class of morphisms, aka arrows, of C. Morphisms are like functions: they have a domain and a codomain, both in ob(C). A morphism f from A to B is written f : A -> B. Composition is defined between any pair of morphisms f : B -> C and g : A -> B. hom(C) is closed under composition. f . g : A -> C \in hom(C) Note that all morphisms whose domain and codomain match must be composable. With these in mind, here are the axioms that a category must satisfy. (1) Every object A has an identity id_A : A->A such that \forall (f : A -> B), id_A . f = f and \forall (g : B -> A), g . id_A = g. (2) Composition is associative.ExamplesThe example of a category is Set, the function space. ob(Set) is the class of all sets(*1), and hom(Set) is the class of all functions. Composition is the usual function composition. (*1) The underlying set theory of category theory is often taken to be NBG or some other set theory that allows for proper classes. Hence ob(C) can be things like the class of all sets that don't contain themselves. A category whose objects form a proper class is called a large category. Grp is another major category. ob(Grp) is the set of all groups and hom(Grp) are group homomorphisms. Intuitively, morphisms are usually structure-preserving relations, such as the homomorphisms in Grp that preserve group structure. The arrows are composable because they preserve certain structural information.Basic Concepts and ConstructionsIsomorphismIsomorphism is the "equivalence" in category theory. Objects A and B are isomorphic when there's an invertible morphism between them: \exists f : A -> B such that \exists g : B -> A, and f . g = id_B, g . f = id_A.ProductA * B is an object such that, there exist "projection" morphisms pi1 and pi2, and for any pair of arrows f : C -> A and g : C -> B, there is a pair-wise morphism <f, g>: C -> A * B such that pi1 . <f, g> = f and pi2 . <f, g> = g. This corresponds to the fact that in Set, taking any c \in C and making <f(c), g(c)>, then projecting to (extracting) one component, is the same as creating only f(c) or only g(c) and not bothering with the other component to begin with. See Wikipedia article for a nice drawing of the relation.SumSum, or coproduct, is the reverse of products. A + B is an object such that, there exist injection arrows in1 and in2, where for any two morphisms f : C -> A, g : C -> B, there's [f, g] : C -> A+B for which [f, g] . in1 = f, [f, g] . in2 = g.Further ReadingSee Basic Category Theory for Computer Scientists by Benjamin C. Pierce, MIT Press.Misc.Do we have enough things to work on? -> yes There is lots of theory going on behind concoqtion. We may want to look at theoretical papers. One candidate is Mixing Indexed Types and Hindley-Milner Type Inference by Jeremy Siek; it's linked from the concoqtion website. Category theory is useful for understanding how types work; it takes quite an expertise to use it to design type systems. The reason is that it gives you insights and intuition, but it's not very helpful in inference algorithms and decidability proofs. The proofs missing in "Mixing..." is mostly of the latter type. -- Jun Inoue Topic Actions: Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r3 < r2 < r1 | More topic actions
Webs: Main | TWiki | Africa | CPSX | EmbeddedSystems | Gpce | Houston | International | K12 | MetaOCaml | MulticoreOCR | ProgrammingLanguages | RAP | RIDL | Sandbox | SpeechClub | Teaching | Texbot | WG211 Web Actions: | |
This work is licensed under a Creative Commons Attribution 2.5 License. Please follow our citation guidelines.