
Conversations with a six-year-old on functional programming (2018) - _ttg
https://byorgey.wordpress.com/2018/05/06/conversations-with-a-six-year-old-on-functional-programming/
======
dmlorenzetti
_\lambda x. 6 was also surprisingly difficult for him to guess... It simply
hadn’t occurred to him that the machine might not care about the input._

One Christmas when my whole family got together, I made a "stink detector"
which consisted of a USB cable stuck inside a ziplock bag. My nephews were
invited to put anybody's sock in the bag, then enter some parameters (like
sock color, how long since it was washed, and, crucially, the name of the
sock's owner) in a GUI.

Under the hood of the GUI was a grep engine that checked for a whitelist of
names and titles ("uncle" among them to be sure), and assigned those names the
lowest possible stink number. Whereas my nephews of course were guaranteed to
get a high value. That result was fed through a random number generator, to
produce a fuzzed-up normal distribution for display on the screen.

They spent a long time varying the parameters, trying to figure out how they
affected the "analysis" before figuring out it was all driven by the name.

~~~
johndubchak
Now that would have been fun to watch. Nicely done!

------
Scapeghost
The most key point of this is right at the start:

"I decided to just answer straightforwardly"

That can make all the difference in your interactions with your child and how
they learn about this world.

Too many problems are caused by parents not being honest with their kids. Be
straightforward, no matter how awkward the explanations may be. Avoid
patronizing simplifications and saying things like "you'll understand when
you're older". If they're not able to understand or decide they don't want to,
they'll stop asking.

and also one of the best ways of improving your own understanding of something
is to try explaining it to someone else, and who better than a child? If they
say some tradition is stupid or silly, maybe it is! If you can't defend it to
them, why do you follow it?

Who knows, maybe you'll even make an unexpected friend to share your interests
with. :)

~~~
impendia
I remember, when I was a kid, that I had a toy piano where the notes C, D, E,
etc. were labeled 1, 2, 3, etc.

Later, I tried to get a computer to play a simple melody and assumed that 1=A,
2=B, etc. The result sounded wrong, and eventually by trial and error I
figured out that if I put C# in place of C, then everything sounded good.

I asked my father why, and he gave me a version of "you'll understand when
you're older". My father was a wonderful man, but this is still one of my
sadder memories from childhood.

~~~
darkerside
You may have asked him at the worst possible time for him personally. Whyever
he didn't explain it at the time, I'm sure it's nothing to do with his love
for you.

~~~
impendia
Oh, no question about that. When I was a kid, I tended to assume that my
parents always were available to drop what they're doing and engage with you.

(And which, incidentally, is surely a reason why many parents are finding
working from home during quarantine to be so difficult.)

~~~
gowld
Your question may have touched a nerve, if he was getting older and no longer
could see sharp.

~~~
Hermandw
Maybe he was like me who had some degree of hearing loss when I grew older and
could no longer hear C sharp.

~~~
sullyj3
musical notes repeat once every doubling of frequencies, so there are many C#s
spread throughout the range of human hearing. The only way someone could be
unable to hear c# would be if they were unable to hear at all.

~~~
Naracion
Your parent and grandparent comments were (imo, clever) word plays on C# / see
sharp and back to _hear_ c# (instead of see sharp).

Edit: Point being--scientific accuracy not required. :)

~~~
sullyj3
oops!

------
grey-area
I find kids understand the concept of functions really intuitively if it is
stated simply - input -> func -> output, it doesn't have to be difficult
maths, and it can make for some great games. It looks a little intimidating if
using the notation in this article but they easily grasp that a function
transforms inputs and returns outputs, and it can be a fun introduction to
maths and programming, and then later to things like graphs based on
functions.

Another game I play with my kids to introduce the concept of functions which
aren't just for numbers is a haircut function. You start by deciding on what
the function does (curls hair, cuts it short, makes it longer), write that in
the middle of the page, then you draw some input people on the left of the
page, and on the right hand side draw the output for each input. Bonus points
for running the function twice to see what happens to that person. This is a
popular game with my kids and gets them involved as they can draw their own.

~~~
chrisweekly
Agreed! My kids are slightly older but we've long enjoyed a roadtrip game
that's a variation on 20 questions: "give me an input, I'll respond with an
output, then you guess what the 'machine' [algorithm|function] did". They'd
get to provide one input, I'd respond w one output, then they'd get one chance
to define the operation -- to which I'd respond only yes or no -- before the
next person's turn to test it. Whoever solves it gets a point (if we're
keeping score; not important). Then the next person gets to be the function
maker. They got pretty good at hypothesizing plausible solutions and refining
them to hone in on the precise answer, and it was more interesting than
standard 20 questions.

It's also fun to go beyond strictly numeric types, eg responding to a number
with the name of a country, or turning a letter or word into a number, etc.

~~~
bspammer
I taught at a programming camp one summer, and my favourite example of this
that I drove several kids crazy with was "above the line, below the line".

Given any input word, I would tell them whether it was above the line, or
below the line (which corresponded to acceptable and unacceptable behaviour in
camp-speak). I think only two kids figured it out on their own, and each time
I challenged them to write a program to categorize words automatically.

I wonder if hacker news can figure it out :)

"Hacker" -> Above the line

"News" -> Above the line

"chrisweekly" -> Below the line

"functional" -> Above the line

"programming" -> Below the line

~~~
marviel
(Spoiler?)

I think it's called "above the line" "below the line" because the characters
in each of the accepted words don't travel below the "character placement
line" that runs along the bottom of every word. I've forgotten the "real name"
for this line.

Thus,

    
    
      toothpaste -> below the line, because of "p"
    
      tooth -> above the line, no characters pass below it.
    

Generally, if the word contains a y,p,q,g, or j, then it's "below".

Right?

EDITS:

1: TIL the name for this property of a character is called a descender[1].
(And yet I _still_ can't find the name for that blasted line.)

2: It's called a baseline[2], thanks taylorlunt

REFS:

[1] [https://www.merriam-
webster.com/dictionary/descender](https://www.merriam-
webster.com/dictionary/descender)

[2] [https://typedecon.com/blogs/type-
glossary/baseline/](https://typedecon.com/blogs/type-glossary/baseline/)

~~~
bspammer
This is the right answer! I think it was made harder in the camp due to "above
the line" and "below the line" already having semantic meaning in the context
of the camp, most kids didn't expect that to literally be the answer.

~~~
marviel
yeah that makes sense, thanks for sharing it with us!

I'll likely use it to mystify kids someday soon.

------
maze-le
>> a free theorem is when you can say something that is always true about a
function machine if you only know its type, but you don’t know anything about
what it does on the inside.” This seemed a bit beyond him...

To be fair, this is a bit beyond most who had no contact with functional
programming and category theory.

~~~
sfvisser
Has nothing to do with category theory. Not necessarily at least.

Also, there is a strong intuition to free theorems that many people without an
FP background will easily understand.

------
jpz
"He gasped in astonishment at the idea of putting function machines into
function machines"

"He gasped in astonishment as I carefully explained the results of the double-
slit experiment."

Surely more like that this describes a 6yo kid being excited about something
their parent is excited about and a product of implicit empathy, than any
significant insight?

I hate to lose reputation with downvotes for sounding negative, but I find my
credulity challenged with this story.

~~~
jerf
"Surely more like that this describes a 6yo kid being excited about something
their parent is excited about and a product of implicit empathy, than any
significant insight?"

Also possible is that what the kid actually understands and what the parent
thinks they are understanding are two different things. The kid is quite
likely still wrong in some critical way.

But that is where we all start with new things. I've got two boys in 3rd & 5th
grade right now and I'm actively fighting with both of them the idea that
"learning" is a matter of being told the correct answer and then they forever
after know the correct answer in its every nuance. (Not just since the
lockdown. It's been a theme for the past six months with me.)

The older one has just started learning Spanish with school... well...
nominally with the school, that's actually going very badly, but I started him
on Duolingo in the meantime... and that's been a very good doorway into the
idea that you can't just be exposed to a single isolated fact once and then
have it just magically be internalized, you need to be re-exposed to it over
and over, use it, practice it, and discover how your initial impressions were
wrong over time.

~~~
darkerside
Education is a series of increasingly smaller lies

~~~
JadeNB
> Education is a series of increasingly smaller lies

Could you be swayed to the more optimistic "Education is a series of
decreasingly incomplete truths"? I'm a math professor, and we do tend to be
able to tell our students the truth, nothing but the truth, but very much not
the whole truth, at least in every part of the curriculum that I've seen.

(That we're able to do so doesn't mean _no_ math teachers lie, but it's not as
integral—ha!—a part of the curriculum as in physics, say.)

~~~
wolf550e
In my school, I was lied to by teachers instead of just saying "we will get to
that later" or something. For example:

Q. how much is 3 - 5?

A. nothing because you cannot take 5 out of 3.

Q. how much is 2 divided by 3?

A. nothing because you cannot divide 2 by 3.

Q. what are the roots of the quadratic function ...?

A. this quadratic function doesn't have roots because you can't take the
square root of a negative number

I believe it's possible to not lie when teaching math, but I guess it's harder
to do.

~~~
JadeNB
To be sure, there is a habit to make the teacher's life easier by lying, and I
certainly believe you when you say that you were lied to; but all of these can
be rescued, as a sequence of decreasingly incomplete truths, just by adding
quantifiers. Since the human brain is (excessively) good at ignoring
quantifiers, a skilled teacher (not me, in this context—I'm a college teacher,
so am not claiming that this is the right language for primary schoolers, just
that it's true) can speak truthfully without impairing the pedagogy:

Q. how much is 3 - 5?

A. taking 5 out of 3 does not give a whole-number answer.

Q. how much is 2 divided by 3?

A. dividing 2 by 3 does not give an integer answer.

Q. what are the roots of the quadratic function ...?

A. this quadratic function doesn't have real roots because you can't take a
real square root of a negative number

~~~
Viliam1234
> A. this quadratic function doesn't have real roots because you can't take a
> real square root of a negative number

This one is actually true. If someone tells you they have a square root of a
negative number, just laugh at them and tell them it's just imaginary.

------
minipci1321
I was 16 and learning FORTRAN at school. I was a lazy bum at that time (well,
that stayed ;-), didn't really prepare, and at the final exam, the teacher
asked me in what order the program is executed. Not knowing any better I
replied "a value is calculated when the rest of the code needs it" (like in
regular math that we did a lot at the time too). She said "not correct, it
executes in the order it is written".

\-- I doubt she knew anything about functional programming back then.

\-- It took me 40+ years to get to the universe where this answer was not
completely laughable.

\-- And meanwhile what 16 y.o. kids were doing at the time, 6 y.o ones are
capable of doing now.

~~~
krebs_liebhaber
It looks like you projected your own laziness onto the language.

------
chime
Thanks _ttg for posting this! I just spent an hour with my 5-year old going
over all the functions mentioned in the post and then some. I would give him
an 'x' and he returned f(x) to me. Eventually we ended up at Collatz
Conjecture and he absolutely loved it. I've always wanted to explain that one
to him but it was hard to simplify the concept. Starting with simpler f(x) and
building up to comparisons like min/max worked out perfectly. He completed the
entire chain of 7 on his own! Thank you :)

------
porsager
I remember the first time this was posted, almost 2 years ago. I've played the
functional machine game with my daugther (then 6) a lot since, and she still
at times ask if we should play! It's such a good way to make things like these
interesting. Thank you!

ps. Maybe add [2018] to the title?

------
sideshowb
I will try to remember this in a few years time!

We inadvertently taught our 2yo something which I think relates to
programming. We play an animal-pairs-matching card game, with the twist that
if you draw a shark card you can then steal a card off another player (while
pretending to be a shark, obviously). Inadvertently my wife and I had taught
different rules: I taught that pairs already matched up were safe from the
sharks, while she taught that they weren't. So now every game has to start
with 2yo deciding what the rules are, which often leads to discussion of
consequences for each rule.

~~~
sideshowb
...it gets better! this morning she brought her doll to the game, and we had
to draw cards and play on dolly's behalf too...

------
serpix
My seven year old would glaze over somewhere in the first sentence and switch
topics to Pokemon.

Your child might be gifted.

~~~
Aissen
To quote the traditional meme on Pokémon:
[https://9gag.com/gag/534844/serious-pokemon-
math](https://9gag.com/gag/534844/serious-pokemon-math)

My point being that maybe it's possible to take interest in what the kids
like, and use that to teach them something ? With pokémon it could be
Statistics, Biology, Storytelling, Programming, etc. Whatever you like :-)

------
soared
Ive always thought an under appreciated point in this story is the word
“machine”. A function doesn’t mean anything to a kid, but a machine is so easy
to visualize and understand. I’d imagine that with calling it a function
“machine” it would be much harder to understand, since you can’t imagine a
factory doing work to an input to get an output with the word machine.

------
sytelus
Surprising because I have seen few 6 years olds can do multiplications and
divisions. If I'm not mistaken, standard US 1st grade curriculum expects kids
to be familier with only addition below 100 and subtraction in low teens.

~~~
detaro
The specific examples are with factors 2 and 10, most kids can handle those
earlier.

------
defaultcompany
Kids definitely can grasp this on a very tangible level. I just explained
function input and output to my 8yr old and she immediately said "Oh so like
food is input and poop is output!" Yes we are all functions!

~~~
arthurcolle
Golden response - bright future in programming for her.

------
foobarian
I had a fun conversation with my 6yo about recursion (or is it
encapsulation?). We were out of green Play-doh so she came up with the idea to
pretend blue Play-doh is green and to make a lump of green Play-doh out of the
blue. When I suggested we can telescope this she spent the whole day saying
sentences like "X made out of <p1> made out of <p2> made out of <p3>....". Was
cool to see how tickled she was by the idea.

------
gigatexal
This kid is going to be so much better of in life in a STEM field than his
peers without a parent who teaches functional programming/theory courses and
as one that takes an interest in their children (which I am sure most, of not
all, parents do). I say this because reading the story helped me see that I
should do this when I have kids: expose them early on to what I’m doing and
help them get ahead anyway I can (if they so choose a STEM aligned career
they’ll be advantaged some) but also wishing I had parents that finished
college so they could do this for me. They didn’t and I made it out okay so
I’ll just better the next generation where I can. What a cool post. And that
kid sounds really smart. I bet he’s going to go on to do big things.

------
jcpst
My daughter was in kindergarten when I first read this a few years ago. She
loves the “guess what the function does” game.

------
teekert
So nice! This morning my 7 y/o son said the epic words: I really know a lot, I
think about 50% of all there is. Naturally triggered and with Dunning-kruger
in the back of my mind I start explaining about how he knows about rain, but
not about molecules and exactly why it falls down and that generally smart and
knowledgeable people realize that there is still a lot they don't know and
that it is a sign of deeply understanding something if you realize it. But I
was wrong he said, because he saw a movie about rain during his (home
schooling) curriculum...

------
OJFord
What's the optimal strategy for choosing inputs in order to guess the nature
of the machine?

~~~
ThreeFx
I don't think that this problem is even computable, since the functions could
be arbitrarily complex.

If you restrict the nature of the functions e.g. "polynomials of degree at
most d", then the answer depends on the restriction. For the polynomial of
degree <= d case the solution is d+1 inputs, every polynomial of degree at
most d is uniquely determined by d+1 points.

~~~
OJFord
I'm having flashbacks to middle school when this was a (childish and easy, I
thought, because we were 12 or whatever, not 6) exercise in a maths lesson.

I vividly recall facetiously making this point, that for all we knew it was
the 'number machine' (as I think the teacher called them) that responded 'as
described for the inputs shown, and zero for all others', or something; that
'it sure looks like 2x, but we can't possibly know for all numbers'.

If I'd been told the machines were linear I would have learnt something
(probably, hard to recall one's knowledge at a specific time) and shut up.
Alas, I was sent out...

~~~
mcny
I had a similar experience in eighth grade with introduction to trigonometry.

The teacher put in 0, 30, 60, 90, ... on the x axis and sine (x) on y. Then
they began to join them with a beautiful curve. I protested and inquired how
we can just join those dots seemingly on faith. The teacher just ignored me in
spite of my repeated protests.

------
rednosehacker
Such a beautiful story about love and passion. Thank you for sharing this
inspiring annecdote !

------
dang
Discussed at the time:
[https://news.ycombinator.com/item?id=17015661](https://news.ycombinator.com/item?id=17015661)

------
d--b
I remember having these kinds of games all the time in middle school in
France. They also were called "machines" at the time.

------
shric
(2018)

~~~
mar77i
146

------
gregoriol
Maybe we should let kids be kids and do kids stuff instead?

~~~
sideshowb
what by ignoring their questions? the difference between engaging with their
curiosity and forcing stuff on them is... not at all nuanced, really.

~~~
gregoriol
The question of the kid was legit, but the "a free theorem is when you can say
something that is always true about a function machine if you only know its
type, but you don’t know anything about what it does on the inside" is likely
not what he asked for.

~~~
OJFord
The author acknowledged that was a bit much and pivoted it to a game that his
son loves, who put you in charge of taking that away from him?

> This seemed a bit beyond him [...] But the whole conversation had given me a
> different idea. "Hey, I have a good idea for a game," I said. [...] He
> immediately liked this game and it has been a huge hit; he wants to play it
> all the time.

It's probably made even better by being 'the game that daddy reads about/does
at work'.

------
rb808
I see a lot of articles that try to make FP look really easy. The majority of
programmers have a lot of trouble figuring out how to figure out a typical FP
program with its layers of nested functions. It isn't easy, which is why most
code bases are not FP.

~~~
iLemming
You should watch Rich Hickey's "Simple made easy", to understand why "easy" is
almost never better than "simple". FP programs are almost always simpler than
similar OOP programs.

