juchiyama / study-category-theory

Study category theory

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

study-category-theory

This resource is for my study on Functional Programming, Generic Programming, Typelevel Programming and Category Theory. I will be using Haskell and Scala/Scalaz and whatever else comes my way.

Disclaimer

Quoting the great Brendan McAdams "I am by no means a Haskell/Scala/Scalaz/Cats expert. I'm a beginner that has made a lot of progress." which also applies to me I guess. So don't learn from me, but maybe, get inspired and go look at Functional Programming, Haskell, Scala, Scalaz, the typelevel project, Cats, Scala Hamsters, Shapeless and overall create happy and therefor easy to reason about composable functions that, when applied, are called programs.

Category Theory Video

Functional Programming Videos

Books

What is Category Theory? It is the abstract theory of functions, and because functions are everywhere and everywhere that functions are, there are categories. Maybe Category Theory should have been called Abstract Function Theory (AFT)!

The the notion of a category arose in order to define a functor. The notion of a functor arose to define natural transformations. The notion of natural transformations arose to define adjoints.

Definitions

Note: The following is in context of programming and not mathematically correct, and should

  • Functional Programming: The practice of composing programs using functions Wikipedia,
  • Category Theory: the study of collections of concepts (types) and arrows (functions/morphisms) and the relationships between them Wikipedia,
  • Concept: a concept is a type, like String, Int, and so on,
  • Object: an alternative name for a concept,
  • Type: an alternative name for a concept,
  • Arrow: an arrow is a morphism (function) between concepts (types), something that converts from one concept (type) to another. Usually a morphism, which is a function defined against two types, that converts one type to another type,
  • Composability: Arrows are composable, this is the most important part of arrows,
  • Category: a category is a bunch of objects/grouping of objects (concepts/types) and a bunch of arrows (functions/morphisms) connecting these objects and an object is abstract. Objects don't have any structure. The only way you can think about objects is how objects connect to other objects by means of arrows. Its like a graph, but it might have infinitely many objects and infinately many arrows between any two objects. It can also be two dots with one arrow, but it can also be no dots and no arrows - Bartosz
  • Nodes: objects can have a name,
  • Functor: functors are transformations from one category (grouping of types) to another category (grouping of types), that can also transform and preserve morphisms. A functor would be something that convert cats into dogs.
  • Morphism: A morphism is the changing of one value in a category (grouping of types) to another in the same category (grouping of types), thus a morphism is a function that converts from one type to another. For example, a morphism is something that can change a fat cat into a slim cat Wikipedia
  • Isomorphism: Isomorphism is a very general concept that appears in several areas of mathematics. The word derives from the Greek iso, meaning "equal," and morphosis, meaning "to form" or "to shape.". An isomorphism is a map that preserves sets and relations among elements,
  • Homomorphism: similarity of form,
  • Proposal: something proposed/an assumption,
  • Proposition: A statement that affirms or denies something and is either true or false,
  • Axiom: An axiom is a proposition regarded as self-evidently true without proof,
  • Associative: (a math operation) yielding an equivalent result independent of the grouping of the terms,

Types

We write our programs in a way is composable, split a huge problem in small problems, solve the small pieces seperately and compose the solutions to these problems into one bigger program. - Bartosz

In category theory, an object in a category corresponds to a type corresponds to a proposition. - Bartosz

There are different kinds of category, a Set is one kind of category in which 'objects' are sets, and arrows are functions that go from one set to another set. - Bartosz

Yoneda Lemma

In mathematics, specifically in category theory, the Yoneda lemma is an abstract result on functors of the type morphisms into a fixed object.

Modern ideas in FP

The two most important ideas in modern Functional programming are:

  1. Data first: Functional programming is all about putting data first. First define what kinds of data we have in a problem domain and what kind of transformations we want on them. Then we are building up the data structures and the code to do the transformations.

  2. Managing of side-effects: Functional programming is not (only) about pure funcions any more. Eventually programs will produce side-effects and side-effect management is a puzzle in many parts.

So its about data management and controlling side-effects.

Data is represented by Structure and Types are represented by functions.

History of programming languages

Visual Studio Code

Visual Studio Code a.k.a. 'Code' is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, OS X and Linux. Code is an open source source code editor developed by Microsoft. It comes with built-in support for JavaScript, TypeScript, Node.js, Markdown and git and has a rich ecosystem of extensions for other languages and runtimes that are available on the Visual Studio Code Marketplace.

Installation

Code can be installed using brew:

$ brew cask install visual-studio-code 

After installation, the editor can be found with Spotlight by typing: code.

Haskell support

Code has support for Haskell by means of Haskell extensions. These extensions can be installed in Code by typing (⌘+P) and pasting:

ext install language-haskell

Haskell lint support

You'll first have to install hlint

$ cabal install hlint

Cabal will install hlint to /Users/your-user-name/Library/Haskell/bin.

Now install the hlint extension (⌘+P) and pasting:

ext install haskell-linter

Configuring hlint

Set the following (⌘+P) + settings.json:

{
	"haskell.hlint.executablePath": "/Users/your-user-name/Library/Haskell/bin/hlint",
	"haskell.hlint.run": "onType", // also: "onSave", "never"
    "haskell.hlint.logLevel": "log"
}

Note: Please replace your-user-name with the directory name of your system.

Setting hits

HLint's hints can be configured (⌘+P) + settings.json:

{
	"haskell.hlint.hints": ["Default", "Dollar", "Generalise"],
    "haskell.hlint.ignore": ["Redundant do"],
}

Haskell build

Code has a build option (SHIFT+CMD+B), but this has to be configured (F1: Configure Task Runner), replace the code with the following:

{
	"version": "0.1.0",
	"command": "runghc",
	"isShellCommand": true,
	"args": ["${file}"],
	"showOutput": "always"
}

You can now run a haskell file when opened, but note that you'll have to have main in scope like so:

main :: IO ()
main = putStrLn "Hello World, this is Haskell!"

Show spaces and tabs in editor

Set the following (⌘+P) + settings.json:

{
	"editor.renderWhitespace": true,
	"editor.insertSpaces": true
}

Autosave

Set the following (⌘+P) + settings.json:

{
	"files.autoSave": "afterDelay",
	"files.autoSaveDelay": 1000,
}

Dart support

Code has support for Dart and can be installed by typing (⌘+P) and pasting:

ext install dart

https://inoio.de/blog/2014/07/20/type-class-101-monoid/

Resources

About

Study category theory

License:Apache License 2.0


Languages

Language:Scala 92.9%Language:Haskell 6.5%Language:Shell 0.2%Language:Rebol 0.2%Language:Dart 0.2%Language:Frege 0.1%