r/ProgrammerHumor • • Dec 18 '17

My function programming lecturer's 'Map of The Course'

Post image
88 Upvotes

11 comments sorted by

5

u/elaru Dec 18 '17

Mind to share who your lecturer is, and where I can find their course materials? I'd really like to take a look :)

7

u/Keywarn Dec 18 '17

Dr Nicolas Wu - University Of Bristol, should probably have made that info available to start with, it’s out there now :)

3

u/benny-powers Dec 18 '17

looks awesome, enjoy. Is the course published?

1

u/Keywarn Dec 19 '17

I don’t think so. I’m not sure how much of his content is available to the public...

12

u/chisui Dec 18 '17

Roast Mutation

meλirl.

2

u/ralgrado Dec 18 '17

Yeah, the dragon would've killed me. Never really got monads :/

3

u/derleth Dec 18 '17

Eh, at the level of programming languages, a monad is a box with a value inside of it.

What's fun is when the box can be empty, too.

For example:

readInt :: String -> Maybe Integer

readInt is an imaginary function which takes a string and either parses it into an integer or fails to; either way, in Haskell a function has to return something, so what should we return if the parse fails?

Nothing. Return a value which cannot be confused for a valid result. If you think of monads as boxes, Nothing is the empty box.

Here's a simple example of how it works in practice:

case (readInt str) of
    Just v -> putStrLn ("Got the integer " ++ (show v))
    Nothing -> putStrLn "NO INTEGER FOUND! LAUNCH MISSILES!"

Just v is what the Maybe monad looks like when the box contains a value, and Nothing is what it looks like when it does not. Notice that we went from Just v to v without missing a step: You can take values out of the Maybe monad very easily.

The IO monad is what most people think of when they think of Haskell monads, but IO is special. The language is constructed such that you can't take values out of it, just shift them from one IO monad box to another, in sequence. This is how Haskell imposes a sequence on actions which communicate with the outside world.

3

u/Delearyus Dec 19 '17

Boxes aren't a very good way to think about monads. A list is a monad, so clearly the box can have multiple elements in it, but a binary tree is not a monad. Also, the 'boxiness' of monads doesn't give a good intuition of how monads are meant to be used.

The box example actually fits much better for the Functor typeclass, which includes all monads as well as arbitrary 'boxes' like trees, and the typeclass function (fmap) actually makes sense given the box analogy (ie when you have a box with some stuff in it, you want to be able to access the contents of the box without opening it)

Honestly it's my personal opinion that people who talk about trying to 'understand monads' are going about things the wrong way. Like, if you want to learn programming, you don't start by learning the general theory of programming languages, you probably start by learning one language, and then another, and over time you start to see what things are similar and different between them, and you develop an intuitive understanding of programming language theory in a much more natural way. Trying to understand monads is the same, just focus on learning to use Maybes and Lists and IOs and eventually you will develop an understanding of monads that can then be supplemented with some higher-level category theory stuff if you want

1

u/Night_Thastus Dec 18 '17

Dang. This is nice. Wish we had a course like this where I go.

0

u/[deleted] Dec 18 '17

[deleted]

4

u/Keywarn Dec 18 '17

All covered! :p

0

u/[deleted] Dec 18 '17

[deleted]

1

u/Keywarn Dec 18 '17

Yeah our lecturer is very good and covers things very well!