# Type Theory And Functional Programming Pdf

File Name: type theory and functional programming .zip
Size: 2669Kb
Published: 04.06.2021

Theoretical Computer Science Stack Exchange is a question and answer site for theoretical computer scientists and researchers in related fields. It only takes a minute to sign up. I'm recently studying Haskell and programming languages.

## Functional programming

Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up. I'm learning Haskell and I'm fascinated by the language. However I have no serious math or CS background. But I am an experienced software programmer. Which topics in category theory should I learn to provide a good basis for understanding Haskell? In a previous answer in the Theoretical Computer Science site , I said that category theory is the "foundation" for type theory.

Here, I would like to say something stronger. Category theory is type theory. Conversely, type theory is category theory. Let me expand on these points. Category theory is the algebraic theory of such "types" and "functions". Officially, category theory calls them "objects" and "morphisms" so as to avoid treading on the set-theoretic toes of the traditionalists, but increasingly I see category theorists throwing such caution to the wind and using the more intuitive terms: "type" and "function".

But, be prepared for protests from the traditionalists when you do so. We have all been brought up on set theory from high school onwards. If you never thought of them that way, you are in good shape.

You have escaped set-theoretic brain-washing. Category theory says that there are many kinds of types and many kinds of functions. So, the idea of types as sets is limiting.

Instead, category theory axiomatizes types and functions in an algebraic way. Basically, that is what category theory is. A theory of types and functions.

It does get quite sophisticated, involving high levels of abstraction. But, if you can learn it, you will acquire a deep understanding of types and functions. By "type theory," I mean any kind of typed formal language, based on rigid rules of term-formation which make sure that everything type checks. It turns out that, whenever we work in such a language, we are working in a category-theoretic structure. Even if we use set-theoretic notations and think set-theoretically, still we end up writing stuff that makes sense categorically.

That is an amazing fact. Historically, Dana Scott may have been the first to realize this. He worked on producing semantic models of programming languages based on typed and untyped lambda calculus. The traditional set-theoretic models were inadequate for this purpose, because programming languages involve unrestricted recursion which set theory lacks. Scott invented a series of semantic models that captured programming phenomena, and came to the realization that typed lambda calculus exactly represented a class of categories called cartesian closed categories.

There are plenty of cartesian closed categories that are not "set-theoretic". But typed lambda calculus applies to all of them equally. Scott wrote a nice essay called " Relating theories of lambda calculus " explaining what is going on, parts of which seem to be available on the web.

The original article was published in a volume called "To H. Berry and Curien came to the same realization, probably independently. They defined a categorical abstract machine CAM to use these ideas in implementing functional languages, and the language they implemented was called "CAML" which is the underlying framework of Microsoft's F. That means that they not only map types to types, but also functions between types to functions between types.

Polymorphic functions preserve all such functions resulting from functor actions. Category theory was invented in 's by Eilenberg and MacLane precisely to formalize the concept of polymorphic functions.

They called them "natural transformations", "natural" because they are the only ones that you can write in a type-correct way using type variables.

So, one might say that category theory was invented precisely to formalize polymorphic programming languages, even before programming languages came into being!

A set-theoretic traditionalist has no knowledge of the functors and natural transformations that are going on under the surface when he uses set-theoretic notations. But, as long as he is using the type system faithfully, he is really doing categorical constructions without being aware of them. All said and done, category theory is the quintessential mathematical theory of types and functions. So, all programmers can benefit from learning a bit of category theory, especially functional programmers.

Unfortunately, there do not seem to be any text books on category theory targeted at programmers specifically. The book by Benjamin Pierce, Basic category theory for computer scientists is perhaps the most readable of them. However, there are plenty of resources on the web, which are targeted at programmers.

The Haskellwiki page can be a good starting point. At the Midlands Graduate School , we have lectures on category theory among others. Graham Hutton's course was pegged as a "beginner" course, and mine was pegged as an "advanced" course.

But both of them cover essentially the same content, going to different depths. University of Chalmers has a nice resource page on books and lecture notes from around the world. The enthusiastic blog site of "sigfpe" also provides a lot of good intuitions from a programmer's point of view.

My own lecture notes in the Midlands Graduate School covers all these topics except for the last one monads. There are plenty of other resources available for monads these days. So that is not a big loss. The more mathematics you know, the easier it would be to learn category theory. Because category theory is a general theory of mathematical structures, it is helpful to know some examples to appreciate what the definitions mean. When I learnt category theory, I had to make up my own examples using my knowledge of programming language semantics, because the standard text books only had mathematical examples, which I didn't know anything about.

Then came the brilliant book by Lambek and Scott called " Introduction to categorical logic " which related category theory to type systems what they call "logic". It is now possible to understand category theory just by relating it to type systems even without knowing a lot of examples. A lot of the resources I mentioned above use this approach to explain category theory.

Once you are an FP guru, it might be easier to pick up category theory if you still care. Category theory is simple for somebody with broad mathematical education groups, rings, modules, vector spaces, topology etc. Lacking this background, category theory is nearly impenetrable. The beauty of category theory is that it unifies a lot of seemingly unrelated things e. But if you are not familiar with the multiple examples that category theory unifies, category theory is just an additional layer of complexity that makes your life harder.

In my experience, learning is easier by building on things one already knows. As a software developer, you know a lot about programming, and Haskell programming is not that different from other programming, so my recommendation is to approach Haskell from a pragmatic programming point of view, ignoring category theory.

The bit of category theory that is in Haskell, e. After all, monads are merely generalised composition and you will have used monads in your programming practise already -- albeit without knowing you did , and Haskell doesn't really support monads for real, as it does not enforce the monadic laws.

I'm going to try and keep it short and sweet. There is an informal correspondence between Haskell programs and certain classes of categories, which can be made more formal with some work. This correspondence is known as the Curry-Howard-Lambek correspondence and relates:.

The list goes on and on, but one crucial point is that you can define things like monads and algebras in category theory and come up with notions that are both useful to mathematicians but also pervasive in the practice of Haskell programming.

I'm not sure which book to recommend, as I haven't found a completely satisfactory introductory book on categories for computer scientists. The idea is to learn basic definitions up to adjunctions, and then maybe try and read some of the excellent blogs out there to try and understand these concepts. Don't go to Category Theory or any other theoretical domain to become good in Haskell. Learn functional programming techniques, such as tail recursion, map, reduce, and others.

Read as much code as you can. Implement as many ideas as you can. If you have issues, read and read. If you want a good theoretical reference to learn Haskell and other functional programming paradigms then have a look at: An Introduction to Functional Programming Through Lambda Calculus, Greg Michaelson available online.

There are other similar books. Category theory is a very sophisticated branch of mathematics and mastering it will unify most of your previous learnings by making them instances of same abstract objects. So it is very useful and very intuitive. But it is vast and broad, and you will find yourself in a plenty of new concepts that will don't even know which one is suitable for your needs and which one you should skip.

So your purposeful approach needs choice among concepts, otherwise mastering in it inevitably needs long time and is really not a self study domain. By the way, I suggest a very well start point for your purpose to be here. Category theory has certain but limited use for learning functional programming or in actual practice of functional programming.

I recently made a presentation to answer that question. Sign up to join this community. The best answers are voted up and rise to the top. Is Category Theory useful for learning functional programming?

Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up. I'm learning Haskell and I'm fascinated by the language. However I have no serious math or CS background. But I am an experienced software programmer. Which topics in category theory should I learn to provide a good basis for understanding Haskell? In a previous answer in the Theoretical Computer Science site , I said that category theory is the "foundation" for type theory.

Functional programming languages often feature mechanisms that involve complex computations at the level of types. These mechanisms can be analyzed uniformly in the framework of dependent types, in which types may depend on values. The purpose of this chapter is to give some background for such an analysis. Unable to display preview. Download preview PDF.

There is a free pdf version of this book with nicer typesetting available for download. You may order a hard-cover version with color illustrations at Blurb. Or you may watch me teaching this material to a live audience. Mind you, not computer scientists but programmers — engineers rather than scientists. I know this sounds crazy and I am properly scared.

Homotopy type theory is a new branch of mathematics that combines aspects of several different fields in a surprising way. It is based on a recently discovered connection between homotopy theory and type theory. The present book is intended as a first systematic exposition of the basics of univalent foundations, and a collection of examples of this new style of reasoning — but without requiring the reader to know or learn any formal logic, or to use any computer proof assistant.

#### Want to add to the discussion?

Daily news and info about all things Haskell related: practical stuff, theory, types, libraries, jobs, patches, releases, events and conferences and more Best introduction to type theory self. I want to learn type theory. Hopefully something relatively comprehensive, hopefully something that covers dependant types and so on. I am NOT looking to learn practical type theory, I've already used Haskell for a long time now, I'm looking to further my understanding and abilities and I've determined this is the best way for me.

In computer science , functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program. In functional programming, functions are treated as first-class citizens , meaning that they can be bound to names including local identifiers , passed as arguments , and returned from other functions, just as any other data type can. This allows programs to be written in a declarative and composable style, where small functions are combined in a modular manner. Functional programming is sometimes treated as synonymous with purely functional programming , a subset of functional programming which treats all functions as deterministic mathematical functions , or pure functions.

0 Response