User:Michiexile/MATH198/Lecture 5
From HaskellWiki
Michiexile (Talk | contribs) |
Michiexile (Talk | contribs) |
||
Line 1: | Line 1: | ||
IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ. |
IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ. |
||
+ | |||
+ | |||
+ | ===Cartesian Closed Categories and typed lambda-calculus=== |
||
+ | |||
+ | A category is said to ''have pairwise products'' if for any objects <math>A,B</math>, there is a product object <math>A\times B</math>. |
||
+ | |||
+ | A category is said to ''have pairwise coproducts'' if for any objects <math>A,B</math>, there is a coproduct object <math>A+B</math>. |
||
+ | |||
+ | Recall when we talked about internal homs in [[User:Michiexile/MATH198/Lecture 2|Lecture 2]]. We can now define what we mean, formally, by the concept: |
||
+ | |||
+ | ''Definition'' An object <math>C</math> in a category <math>D</math> is an ''internal hom object'' or an ''exponential object'' <math>[A\to B]</math> or <math>B^A</math> if it comes equipped with an arrow <math>ev: [A\to B] \times A \to B</math>, called the ''evaluation arrow'', such that for any other arrow <math>f: C\times A\to B</math>, there is a unique arrow <math>\lambda f: C\to [A\to B]</math> such that the composite |
||
+ | |||
+ | <math>C\times A\to^{\lambda f\times 1_A} [A\to B]\times A\to^{ev} B</math> |
||
+ | |||
+ | is <math>f</math>. |
||
+ | |||
+ | The idea here is that with something in an exponential object, and something in the source of the arrows we imagine live inside the exponential, we can produce the evaluation of the arrow at the source to produce something in the target. Using global elements, this reasoning comes through in a more natural manner: given <math>f: 1\to [A\to B]</math> and <math>x: 1\to A</math> we can produce the global element <math>f(x) = ev \circ f\times x: 1\to B</math>. Furthermore, we can always produce something in the exponential whenever we have something that looks as if it should be there. |
||
+ | |||
+ | And with this we can define |
||
+ | |||
+ | '''Definition''' A category <math>C</math> is a ''Cartesian Closed Category'' or a CCC if: |
||
+ | # <math>C</math> has a terminal object <math>1</math> |
||
+ | # Each pair of objects <math>A, B\in C_0</math> has a product <math>A\times B</math> and projections <math>p_1:A\times B\to A</math>, <math>p_2:A\times B\to B</math>. |
||
+ | # For every pair <math>A, B\in C_0</math> of objects, there is an exponential object <math>[A\to B]</math> with an evaluation map <math>[A\to B]\times A\to B</math>. |
||
+ | |||
+ | ====Currying==== |
||
+ | |||
+ | Note that the exponential as described here is exactly what we need in order to discuss the Haskell concept of multi-parameter functions. If we consider the type of a binary function in Haskell: |
||
+ | <haskell> |
||
+ | binFunction :: a -> a -> a |
||
+ | </haskell> |
||
+ | This function really lives in the Haskell type <hask>a -> (a -> a)</hask>, and thus is an element in the repeated exponential object <math>[A \to [A\to A]]</math>. Evaluating once gives us a single-parameter function, the first parameter consumed by the first evaluation, and we can evaluate a second time, feeding in the second parameter to get an end result from the function. |
||
+ | |||
+ | On the other hand, we can feed in both values at once, and get |
||
+ | <haskell> |
||
+ | binFunction' :: (a,a) -> a |
||
+ | </haskell> |
||
+ | which lives in the exponential object <math>[A\times A\to A]</math>. |
||
+ | |||
+ | These are genuinely different objects, but they seem to do the same thing: consume two distinct values to produce a third value. The resolution of the difference lies, again, in a recognition from Set theory: there is an isomorphism |
||
+ | |||
+ | <math>Hom(S, Hom(T, V)) = Hom(S\times T, V)</math> |
||
+ | |||
+ | which we can use as inspiration for an isomorphism <math>Hom(S,[T\to V]) = Hom(S\times T, V)</math> valid in Cartesian Closed Categories. |
||
+ | |||
+ | ---- |
||
+ | |||
+ | As it turns out, this is exactly what we need for <math>\lambda</math>-calculus. Any typed <math>\lambda</math>-calculus gives rise to a CCC in a natural manner, and any CCC has an ''internal language'' which satisfies, by the axioms for the CCC, all requirements to be a typed <math>\lambda</math>-calculus. |
||
+ | |||
+ | More importantly, by stating <math>\lambda</math>-calculus in terms of a CCC instead of in terms of ''terms'' and ''rewriting rules'' is that you can escape worrying about variable clashes, alpha reductions and composability - the categorical translation ignores, at least superficially, the variables, reduces terms with morphisms that have equality built in, and provides associative composition ''for free''. |
||
+ | |||
+ | At this point, I'd reccomend reading more on Wikipedia [http://en.wikipedia.org/wiki/Lambda_calculus] and [http://en.wikipedia.org/wiki/Cartesian_closed_category], as well as in Lambek & Scott: Introduction to Higher Order Categorical Logic. The book by Lambek & Scott goes into great depth on these issues, but may be less than friendly to a novice. |
||
Line 22: | Line 74: | ||
* Computer science applications |
* Computer science applications |
||
+ | |||
+ | |||
+ | ===Homework=== |
||
+ | # Prove that currying/uncurrying are isomorphisms in a CCC. Hint: the map <math>f\mapsto\lambda f</math> is a map <math>Hom(C\times A, B)\to Hom(C,[A\to B])</math>. |
Revision as of 18:05, 15 October 2009
IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.
Contents |
1 Cartesian Closed Categories and typed lambda-calculus
A category is said to have pairwise products if for any objects A,B, there is a product object .
A category is said to have pairwise coproducts if for any objects A,B, there is a coproduct object A + B.
Recall when we talked about internal homs in Lecture 2. We can now define what we mean, formally, by the concept:
Definition An object C in a category D is an internal hom object or an exponential object or B^{A} if it comes equipped with an arrow , called the evaluation arrow, such that for any other arrow , there is a unique arrow such that the composite
is f.
The idea here is that with something in an exponential object, and something in the source of the arrows we imagine live inside the exponential, we can produce the evaluation of the arrow at the source to produce something in the target. Using global elements, this reasoning comes through in a more natural manner: given and we can produce the global element . Furthermore, we can always produce something in the exponential whenever we have something that looks as if it should be there.
And with this we can define
Definition A category C is a Cartesian Closed Category or a CCC if:
- C has a terminal object 1
- Each pair of objects has a product and projections , .
- For every pair of objects, there is an exponential object with an evaluation map .
1.1 Currying
Note that the exponential as described here is exactly what we need in order to discuss the Haskell concept of multi-parameter functions. If we consider the type of a binary function in Haskell:
binFunction :: a -> a -> a
On the other hand, we can feed in both values at once, and get
binFunction' :: (a,a) -> a
which lives in the exponential object .
These are genuinely different objects, but they seem to do the same thing: consume two distinct values to produce a third value. The resolution of the difference lies, again, in a recognition from Set theory: there is an isomorphism
which we can use as inspiration for an isomorphism valid in Cartesian Closed Categories.
As it turns out, this is exactly what we need for λ-calculus. Any typed λ-calculus gives rise to a CCC in a natural manner, and any CCC has an internal language which satisfies, by the axioms for the CCC, all requirements to be a typed λ-calculus.
More importantly, by stating λ-calculus in terms of a CCC instead of in terms of terms and rewriting rules is that you can escape worrying about variable clashes, alpha reductions and composability - the categorical translation ignores, at least superficially, the variables, reduces terms with morphisms that have equality built in, and provides associative composition for free.
At this point, I'd reccomend reading more on Wikipedia [1] and [2], as well as in Lambek & Scott: Introduction to Higher Order Categorical Logic. The book by Lambek & Scott goes into great depth on these issues, but may be less than friendly to a novice.
2 Limits and colimits
- Generalizing these constructions
- Diagram and universal object mapping to (from) the diagram
- Express product/coproduct as limit/colimit
- Issues with Haskell
- No dependent types
- No compiler-enforced equational conditions
- Can be simulated but not enforced, e.g. using QuickCheck.
2.1 Useful limits and colimits
2.1.1 Equalizer, coequalizer
- Kernels, cokernels, images, coimages
- connect to linear algebra: null spaces et.c.
2.1.2 Pushout and pullback squares
- Computer science applications
3 Homework
- Prove that currying/uncurrying are isomorphisms in a CCC. Hint: the map is a map .