by igorbark · 9y ago · 0 comments
"Let's tweak our sum function a a bit: ... That's it."
I really dislike articles that earnestly try to convince the audience that some subject which many find extremely difficult to understand is actually very simple. My impression is that the intent is to help people who lack the confidence to engage with the topic, but in my opinion the exact opposite effect is achieved. At that point in the article, nothing about recursion had been explained and it's not reasonable to expect someone who previously did not understand recursion to read that section and come to the conclusion "that's it!" Instead they'll be sitting there, extremely confused by something which they're being reassured is actually quite simple. This is not going to help their confidence.
So while I appreciate the author's intent, I think that someone who is struggling to understand recursion might leave this article worse off than when they started. And I wish this trope would disappear from tutorials.
I did that kind of thing more than once, just working through algorithms in my head, I guess learning to trust that it'll work, as long as there's a path from the allowed arguments down to the base case. For me, it was never something that reading a few words could clarify.
It feels bad when a topic you find hard to understand is called simple, and actively discourages those with less self confidence from approaching it.
I was thinking of things like monads. They’re a class of type constructors with a couple of associated functions (unit & bind or unit & join). The definition is undoubtedly simple, as well as fundamental in Haskell. But understanding how to use them, what to use them for, how to tell whether & why a type admits monad/applicative/functor instances, &c., are still difficult things for a lot of people, because these are unfamiliar abstractions. Moreover, they take advantage of unfamiliar features like higher-kinded types, so you can’t even explain them by offering a translation to other languages, because most other languages lack the ability to adequately express them.
For myself, I think of learning as “discovering simplicity”. I know I understand something when it finally feels as simple as it really is.
For example, in German there are straightforward ways you modify the definite article associated with a noun based on whether it is the subject or object in a sentence. A fairly simple, and useful concept! But first you have to remember what gender that noun is, which is fairly challenging in german because there are several word endings for each gender. Next you might need to pay attention to how the sentence has been constructed: in a relative clause, the definite article after the comma is associated with the noun BEFORE the comma - and that definite article is different because it is in a relative clause!
I always try to explain it thusly: Recursion makes big, complicated problems easier to solve. But it's a bit like using a cannon to swat a fly if you have no big, complicated problems to wrestle.
Explanations like this do not deny the complexity present in the scene, but reframe it so that were using a technique to tackle said complexity.
pure :: a -> List a
flatten :: List (List a) -> List a
map :: (a -> b) -> List a -> List b
The above types are for lists, but you can substitute your own type constructor for List.For lists, the implementation is as follows:
pure x = [x]
flatten [] = []
flatten (x:xs) = x ++ flatten xs
map f [] = []
map f (x:xs) = f x : map f xs
A flatMap method can be defined once for all monads: flatMap f m = flatten (map f m)
This method is sometimes called "bind" and is written ">>=" in Haskell (where pure is also called "return" and flatten is also called "join"): m >>= f = flatMap f m
The methods are related by the monad laws - you can look them up if you're interested, but they're not required to gain an intuition.