27 ms·
Conversations with a six-year-old on functional programming (2018)
- defaultcompany 6y agoKids 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 6y agoGolden response - bright future in programming for her.
- deleted 6y ago[deleted]
- dang 6y agoDiscussed at the time: https://news.ycombinator.com/item?id=17015661 https://news.ycombinator.com/item?id=17015661
- chime 6y agoThanks _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 :)
- soared 6y agoIve 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.
- serpix 6y agoMy seven year old would glaze over somewhere in the first sentence and switch topics to Pokemon. Your child might be gifted.
- ralusek 6y agoNobody will remember that nerd, though. Now, your kid...your kid's name will be echoed in the halls of Gym Leaders worldwide.
- speedgoose 6y agoI did the same to be honest.
- Aissen 6y agoTo 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 :-)
- grey-area 6y agoI 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.
- sullyj3 6y agoThe way maths is taught in Australia, for a long time the term function was synonymous with the concept "2D plot that passes the vertical line test" in my mind. I was completely unaware of how much broader and more interesting a concept functions are. There are probably many people whose understanding never progresses beyond this, which I think this is extremely unfortunate.
- chrisweekly 6y agoAgreed! 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.
- shric 6y ago(2018)
- mar77i 6y ago146
- porsager 6y agoI 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?
- maze-le 6y ago>> 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 6y agoHas 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.
- sideshowb 6y agoI 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 6y ago...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...
- gregoriol 6y agoMaybe we should let kids be kids and do kids stuff instead?
- sideshowb 6y agowhat by ignoring their questions? the difference between engaging with their curiosity and forcing stuff on them is... not at all nuanced, really.
- gregoriol 6y agoThe 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.
- sideshowb 6y agoFair, tbh it may not have been needed, but I also struggle with letting go the original question asked even though the child may have moved on! Still, this example is hardly robbing anyone of their childhood.
- OJFord 6y agoThe 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'.
- DonHopkins 6y agoKids stuff like staying up all night playing Factorio!
- detaro 6y agoPlaying games with them they seem to enjoy isn't kids stuff?
- minipci1321 6y agoI 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 6y agoIt looks like you projected your own laziness onto the language.
- justmyname 6y agoFun fact about fortran: its creator (John Backus) was fond of functional programming, but that was after the fortran creation.
- d--b 6y agoI remember having these kinds of games all the time in middle school in France. They also were called "machines" at the time.
- sytelus 6y agoSurprising 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.
- mark-r 6y agoMy kid took an evaluation test in elementary school to see what they already knew. He hadn't been taught long division yet, but when he was presented with the problem he figured it out on the spot. The teacher thought that was remarkable enough to bring to my wife's attention.
- andai 6y agoSome people get it earlier. Some people never really get it.
- detaro 6y agoThe specific examples are with factors 2 and 10, most kids can handle those earlier.
- OJFord 6y agoWhat's the optimal strategy for choosing inputs in order to guess the nature of the machine?
- ThreeFx 6y agoI 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 6y agoI'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 6y agoI 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.
- OJFord 6y agoSure, but it's bounded by human creativity, and there's anyway a difference between reliably and deterministically computing the function, and a sort of approximation with repeated guesses, or reaching a certain confidence. I only have vague recollections of numerical analysis, I remembered the Newton-Raphson method (no good: we don't have an oracle for f'(x), just f(x)) and stumbled into the Runge-Kutta Wikipedia page which I'd forgotten about (also no good). But it seems like a good strategy would be to test one number, guess assuming constant, test a second, guess assuming linear, test a third, guess assuming first order polynomial, and so on. In the presence of step changes or the like though I suppose there's nothing you can do.
- rednosehacker 6y agoSuch a beautiful story about love and passion. Thank you for sharing this inspiring annecdote !
- jpz 6y ago"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.
- whateveracct 6y agoI mean, 6 year olds get excited about all sorts of learning because their proper teachers are enthusiastic. But that enthusiasm helps them enjoy learning real things. And the concepts in the blog post aren't much more complicated than the other fundamentals children learn at that age. So like learning addition and reading, it's probably both the excitement of learning and the mirroring of their teacher.
- FpUser 6y ago"I hate to lose reputation with downvotes for sounding negative, but I find my credulity challenged with this story." My opinion about downvotes is that they reflect way more on reputation of those who actually does the thing (unfortunately they stay anonymous). Well HN rates you using down/up votes but personally since I do not agree with this whole anonymous anti-feature I do not really care. Alternatively (lets add some conspiracy to spice it up) they might be doing hidden user profiling on whole range of social patterns and sending data to interested parties.
- Causality1 6y agoI've found HN to be incredibly unpredictable when it comes to public opinion. I've had comments start out with a dozen up votes only to sink into the negatives hours later, and comments that spent a day at negative four suddenly rise into the positives.
- FpUser 6y agoPositive sinking into negatives... Yes that is what I often observe. As for predictability - it seems to me like anything that deviates from the "party line" (whatever that is for any particular area) gets downvoted. Looks like a usual herd mentality to me.
- gigatexal 6y agoThis 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.
- mayalan 6y agoI want to ask this kid what does he think about Kant's deontological moral theory or the Collatz Conjecture. I'm sure he can figure it out.
- Scapeghost 6y agoThe 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. :)
- vharuck 6y ago>If they're not able to understand or decide they don't want to, they'll stop asking. And they'll only stop asking for a very short while (if they're like all the kids I've talked with). Children are people and value honesty and attention like everyone else. If you try, they'll be back. Plus, I enjoy it even when they don't understand and leave halfway through the answer. They make the best faces to show they're done.
- ergothus 6y agoParents observe their child learn the most in-depth actions and knowledge from a dizzying array of input...and then too often decide that children can't handle nuance or depth. I know _I_ can't, but children seem to be quite good at it.
- impendia 6y agoI 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.
- rb808 6y agoI 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 6y agoYou 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.
- jcpst 6y agoMy daughter was in kindergarten when I first read this a few years ago. She loves the “guess what the function does” game.
- foobarian 6y agoI 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.
- teekert 6y agoSo 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...
- dmlorenzetti 6y ago\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 6y agoNow that would have been fun to watch. Nicely done!