Programming with Categories - Lecture 13

preview_player
Показать описание

Lecturers: Brendan Fong, Bartosz Milewski, David Spivak

Summary: In this course we explain how category theory—a branch of mathematics known for its ability to organize the key abstractions that structure much of the mathematical universe—has become useful for writing elegant and maintainable code. In particular, we'll use examples from the Haskell programming language to motivate category-theoretic constructs, and then explain these constructs from a more abstract and inclusive viewpoint. Hands-on programming exercises will be used to demonstrate categorical ideas like "the universal property of products" in working Haskell code.

We will assume no background knowledge on behalf of the student, starting from scratch on both the programming and mathematics.

(Video: Paolo Perrone.)
Рекомендации по теме
Комментарии
Автор

For people with a lot of programming experience a lot of these monads are very interesting but sometimes so simple, that it is difficult to understand what the advantage is. The tricky thing is to get the Aha! Moment.
Monads come with a notion of context, though this has not been talked about yet. (And I guess it will be when talking about the IO monad).
I actually found that Future Monads to be helpful there (sometimes called Promises), as they make the notion of context that comes with a monad real. That is if you have a computation that takes time, and you create a Future of that computation, you get an immediate answer back (a future), on which you can, map or flatMap to get a new future computation. But clearly the computation may not be finished yet.

bblfish
Автор

For the State monad I found the the article by Bart Jacobs "Coalgebras and monads in the semantics of Java " to be one of the most illuminating. It is also quite easy to read for anyone who has followed this far in the course. It shows how one can think of the whole Java Virtual Machine equivalently as a state monad or as a colagebra with error handling. (The same would apply for JavaScript). So in a way this helps understand exactly the difference between a stateful programming language such as those OO languages and an FP language.

bblfish
Автор

Looking at the state monad in the Kleisli category blew my mind. Why oh why didn't anybody tell me about this before in all those tutorials out there ;-)

michaeldurig
Автор

I think that last function can be written like this:

join :: (s -> ((s -> (x, s)), s)) -> s -> (x, s)
join f s = (fst p) (snd p) where p = (f s)

Please correct if wrong!

EricRogstad