Types and Functions 6: Applicative

Both Http calls will happen instantly and renderPage will be called when both are resolved.

No idea why this is the case that ap makes the calls happen instantly and it is not explained. A paragraph later it is explained, the initial function is curried and is waiting for both of its parameters to arrive before it can run. What ap does is immediately execute whatever needs to be done to get such a parameter.

liftA2(add, Maybe.of(2), Maybe.of(3));

That is rather incredible.

Types and Functions 4: Containers

Functor is simply an interface with a contract. We could have just as easily named it Mappable, but now, where’s the fun in that?

It would have been nice if the name was easy and logical but at least now I finally know what a Functor is. None of the other guides or tutorials really managed to explain that.

At the time of calling, a function can be surrounded by map, which transforms it from a non-functory function to a functory one, in informal terms. We call this process lifting. Functions tend to be better off working with normal data types rather than container types, then lifted into the right container as deemed necessary.

A decent explanation of lifting is also nice to have though without too many examples I don’t think this will stick.

The rest of the chapter including the introduction of IO is just one big: “Why would you do this?”

Types and Function 5: Monads

I’m looking forward to this chapter. When they taught us Haskell as an undergrad they made sure to stop well short of Monads. At the time I was happy about that but by now I wish we had pushed on.

Monads are pointed functors that can flatten

I get this definition by now but it is exactly the kind of stuff that I wasn’t going for. But maybe an ELI5 introduction to functional programming is too much to ask for?

Mind you, we have not thrown out purity, but merely removed one layer of excess shrink wrap.

What is good here is that this tutorial does not gloss over this necessity with a bunch of jargon but in excruciating detail builds up the explanation.

If you’ve read about monads previously, you might have seen chain called >>= (pronounced bind) or flatMap which are all aliases for the same concept.

This ridiculous aliasing into tons of different names in large part explains my confusion. Chain, bind and flatMap ar all the same thing.

One question that I’m left with then is how much of this do you need to be able to use functional programming at an application level and how much do you need to be able to write functional libraries yourself.

The exercises in this chapter are hopeless. The tiny IDE does not help at all and it feels like the only way to do them is to poke at it with map and chain until it sticks. That may very well be the essence of functional programming for all I know.

Again, the thing is that I know what I want to do and that it theoretically should fit together but the various functions feel like broken legos. If they were physical legos with affordances, things would be a lot easier.

“Ja. Als het aan mij ligt wordt Shell morgen genationaliseerd en worden rijken onteigend. Dat is trouwens ook in hun belang.”

Go on king!

“D66 is ook in niets fundamenteel verschillend van extreemrechts. En GroenLinks is dat ook. Zij verdedigen de bestaande orde, die gebaseerd is op bezit en grenzen, en dus op geweld en destructie van de aarde. Ze verdedigen in die zin een extreemrechtse politiek.”

Analoog zou ik willen zeggen dat de meeste groene partijen op de wereld klimaatontkenners zijn, want als ze de klimaatverandering écht serieus zouden nemen, dan zouden ze een totaal andere politiek en aanpak kiezen.

“Drinking has to be against the rules for taking a drink to be breaking the rules. Only a Muslim can know how good that tastes.”

An amazing dive into the popularity of Johnny Walker Black in the Muslim world.

I remember the penchant of a certain kind of man to whiskey when I was a kid and how it would be used as an (expensive) present or bribe. I bet that in most of those cases it was also Black Label that they were going for.


Types and Functions 3: Composing

Then we get at Chapter 05: Composing and I really don’t understand the need to faff around so much when it comes to such a mathematically simple subject.

Composing is really easy, it’s just that programming languages make it hard. Especially if you look at this:

const compose = (...fns) => (...args) => fns.reduceRight((res, fn) => [fn.call(null, ...res)], args)[0];

That curried function is left unexplained and I’m still not sure I can read it.

I’m documenting this because every chapter is spawning off one too many bunny trails for my taste. That also makes it clear how learning functional programming is a reclusive undergrad’s game.