Live data from Hacker News

Conversations with a six-year-old on functional programming (2018)

byorgey.wordpress.com

31–40 of 161 posts

Re: Conversations with a six-year-old on functional programming (2018)

#31
post #7

>> 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.

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.

Re: Conversations with a six-year-old on functional programming (2018)

#32
post #22

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

Interesting question. If you have a prior distribution for the space of possible functions, you can find the input that minimizes the entropy of the posterior distribution (ie. makes it more like a delta and less like a uniform distribution)

Re: Conversations with a six-year-old on functional programming (2018)

#33

Earlier quoted context omitted.

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…

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 t…

Current list of words is consistent with "has an even number of letters".

What about "Hacks"? It uses only letters found in accepted words, but should be rejected because of the odd number of letters.

Re: Conversations with a six-year-old on functional programming (2018)

#34

Earlier quoted context omitted.

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…

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 t…

Check for odd or even string length?

  "Above the line" if len(s) % 2 == 0 else "Below the line"

Re: Conversations with a six-year-old on functional programming (2018)

#35
post #29
post #25

Earlier quoted context omitted.

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.

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…

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.

Re: Conversations with a six-year-old on functional programming (2018)

#36

Earlier quoted context omitted.

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…

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 t…

(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

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

Re: Conversations with a six-year-old on functional programming (2018)

#37

Earlier quoted context omitted.

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…

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 t…

Just a guess:

    data TheLine = Above | Below

    categoriseWord :: String -> TheLine
    categoriseWord s
      | length s 
There's not a lot to go on, though.

Re: Conversations with a six-year-old on functional programming (2018)

#38

Earlier quoted context omitted.

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…

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 t…

Words go below the line iff they contain the same letter twice in a row

Re: Conversations with a six-year-old on functional programming (2018)

#39

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 thi…

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…

I remember a friend pranking other friends, the quizmaster would rotate his pair of hands palm up or palm down and the victim had to guess either "opened" or "closed". Slowly the kids would get it after a few steps, frustrating the "main" victim of the prank. In the end it turned out the state was whether the quizmaster left his arms pressed against his body (closed) or a few inches "opened". A variant would be whether he'd leave his lips pressed together or slightly apart...

Re: Conversations with a six-year-old on functional programming (2018)

#40
post #22

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

I wanted to argue imps, dwarfs and other types of programs when I noticed that I was applying core wars terminology to a completely non core wars problem...
Post reply on HN