Inflicting Haskell on N00bs for Science



  • @Captain said:

    But you can explain foldr a lot more clearly: it adds up all the things in the list.

    How would you explain the loop? "You start with i, which is 0, and then you take the first thing in the list and add it to i, and then you take the next thing in the list and add it to i, and you keep doing that, until the list is empty."

    Interesting.

    Just FYI, very few people think the way you do. Most people will look at the for loop and, maybe with a bit of prodding, understand it as a list of things to do. I've been programming forever, and I look at your Haskell expression and still don't understand it.

    Next time I find a complete computer noob, I'll give them these two examples and ask them to try and interpret what each does. We'll see.


  • I survived the hour long Uno hand

    @cartman82 said:

    Next time I find a complete computer noob

    oh hey, I have one of those around here somewhere. Let me bug him and get back to you



  • You see that the for loop is a list of things to do. Fair enough. The foldr takes a thing to do (the addition) and applies it to a list.

    By factoring it out that way, you can apply the same function to other data structures.

    That said, @Yamikuronue came up with a better explanation for the for loop than I did.



  • @Yamikuronue said:

    oh hey, I have one of those around here somewhere. Let me bug him and get back to you

    YES! Do it.

    @boomzilla, new thread, if you please.


  • I survived the hour long Uno hand

    Preferably with the actual code snippets in it someplace 😉



  • foldr (+) 0 [1..10]



  • fold...
    i learnt that stuff in college. it's really powerfull once you get the vibe of it.



  • foldr is basically LINQ's Aggregate.

    foldr (+) 0 [0..10]
    
    Enumerable.Range(0, 11).Aggregate(0, (x, y) => x + y)
    

    And the implementation for Aggregate:

    public static TAccumulate Aggregate<TSource, TAccumulate>(
    	this IEnumerable<TSource> source,
    	TAccumulate seed,
    	Func<TAccumulate, TSource, TAccumulate> func)
    {
    	if (source == null)
    	{
    		throw Error.ArgumentNull("source");
    	}
    	if (func == null)
    	{
    		throw Error.ArgumentNull("func");
    	}
    	TAccumulate tAccumulate = seed;
    	foreach (TSource current in source)
    	{
    		tAccumulate = func(tAccumulate, current);
    	}
    	return tAccumulate;
    }
    

    Here's a simplified version

    public static B Aggregate<A, B>(
    	this IEnumerable<A> source,
    	B seed,
    	Func<B, A, B> func)
    {
    	B result = seed;
    	foreach (var current in source)
    	{
    		result = func(result, current);
    	}
    	return result;
    }
    

    It's just encapsulating an accumulating for loop. If you can understand such a loop, you can understand Aggregate/foldr.

    I also question the notion that something being easier for a beginner to understand makes it not a good thing.

    A noob would also understand an if chain better than dynamic dispatch/subtype polymorphism. So stop writing sublcasses and just use if chains?



  • @Bort said:

    I also question the notion that something being easier for a beginner to understand makes it not a good thing.

    Was this an argument being made?


  • I survived the hour long Uno hand

    The email I sent:

    Please tell me what you think each of these code snippets means. Be as descriptive as possible, the point is to get a feel for what you're thinking 🙂

    =============================================
    SNIPPET 1:
    foldr (+) 0 [1..10]

    =============================================
    SNIPPET 2:

    i = 0;
    for j in (0..n) {
    i = i + j;
    }



  • Is this someone with no programming experience or just no functional programming experience?


  • I survived the hour long Uno hand

    This is my roommate the business major graduate



  • Really minor nitpick - the second snippet goes to n while the first is capped at 10. This might make one or the other more or less confusing.

    However, given both at the same time, they look like they have the same symbols, just re-arranged.



  • I should have something too after the weekend.


  • Discourse touched me in a no-no place

    @Bort said:

    I also question the notion that something being easier for a beginner to understand makes it not a good thing.

    It depends. Ideally, beginners eventually become competent, then experts. If making it easier for beginners doesn't make it more time-consuming or limiting for the experts then it's all good.



  • Everything should be made as simple as possible, but no simpler.

    Tradeoffs lie in either direction.



  • @Bort said:

    foldr is basically LINQ's Aggregate.

    Which is a very nice thing, and that's why C# has both this and a for loop. So that you can use Aggregate where a for loop would be needlessly obtuse (e.g. in String.Join, which is basically Aggregate with a specific use case), and you can use a for loop for when Aggregate would disrupt the connection between code flow and program flow too much.


  • Discourse touched me in a no-no place

    @boomzilla said:

    Tradeoffs lie in either direction.

    Yes, and depending how you handle the tradeoff, you can get a PHP, a C# or Haskell. Or you can bungle both sides of the tradeoff and end up with C++. 🚎



  • C# does everything right forever.


  • I survived the hour long Uno hand

    Snippet 1:

    foldr (+) 0 [1..10]
    

    It's either telling the computer which folder to look into (folder 0) or, actually, more likely is that it's creating folder 0 to add to the array of folders 1-10.

    Snippet 2:

    i = 0;for j in (0..n) {   i = i + j;}
    

    Ummm. the first bit is establishing the value of 'i' for the upcoming parts. so... to find 'j' in the range of 0 to numbers, you have to.... solve 0 = 0 + j so j is also 0?


    Roommate: So how'd I do?
    Me: Uh...
    Roommate: That bad?
    Me: They both do the same thing.
    Roommate: What?
    Me: And there's no folders involved.
    Roommate: Bollocks that. F-O-L-D-R, what is that supposed to spell?!
    Me: Fold Right.
    Roommate: The hell it does! Wait, is this Physics?
    (apparently he's thinking of subspace folds or protein folding)


    Don't remember where we discussed, but yeah, with no programming experience, he's thinking Algebra, solving for variables. In theory this means functional programming would be easier to grasp, but in practice, cryptic syntax makes it inaccessible.



  • Maybe the experiment would be more helpful if you could explain what the keywords do, without going into too much detail. So something like "foldr applies an operation to the elements of a list, [0..10] produces a list of numbers 0 to 10," etc. Then see what they make of each example. I mean, i know programming, but not Haskell and i wouldn't know what to make of foldr, even of i knew it meant "fold right".



  • When I do my experiment, I think I'll go with a more standard C syntax and use more meaningful var names, as I'd write this in RL:

    var sum = 0;
    var i = 0;
    while (i < 10) {
        sum  = sum + i;
        i++;
    }
    
    

    I might also try something more verbose, such as Pascal:

    Sum := 0
    FOR i := 1 TO 10 DO
    BEGIN
        Sum := Sum + i;
    END;
    

    As a counterpoint, this python one-liner is still more readable than Haskell:

    sum(range(0, 10))
    

    Might be interesting to see what an outsider thinks about one functional style vs another.

    Of course, I'll have to vary examples, so they don't figure out it's all doing the same thing.



  • @Bort said:

    foldr is basically LINQ's Aggregate.

    Or the other way around, of course, since Haskell sort of predates LINQ. And both stem from LISP's reduce.



  • Those three snippets are infinitely more intuitive than the two above.



  • @cartman82 said:

    As a counterpoint, this python one-liner is still more readable than Haskell:

    sum(range(0, 10))
    ```</blockquote>
    If we're being honest, that Haskell example was stupid before it left the IDE, simply because it would not be wrong to rename `foldr` to `AbstractAggregatorFactory`
    The actual way you'd do it is `sum [0..10]`


  • @Yamikuronue said:

    Don't remember where we discussed, but yeah, with no programming experience, he's thinking Algebra, solving for variables.

    A cognitive study of early learning of programming

    We (Saeed Dehnadi, Richard Bornat) have discovered a test which divides programming sheep from non-programming goats. This test predicts ability to program with very high accuracy before the subjects have ever seen a program or a programming language.

    Discusses/investigates the mental model people have of programming before being taught, and why some simply can't be taught.

    Jeff's covered it here.



  • @PJH said:

    A cognitive study of early learning of programming

    We (Saeed Dehnadi, Richard Bornat) have discovered a test which divides programming sheep from non-programming goats. This test predicts ability to program with very high accuracy before the subjects have ever seen a program or a programming language.

    Discusses/investigates the mental model people have of programming before being taught, and why some simply can't be taught.

    Jeff's covered it here.

    I just skimmed through the conclusions and Jeffs post. At first glance it strikes me as groundwork for excuses." I don't fail as a teacher is just that my students are consistently dumb." And I am a special snowflake "I has the power to program" let me feel good stuff. If I have the time i would like to really read their work and see if It can be taken seriously at all ( i.e. They made a good effort at isolating external variables etc). At face value I am skeptic, a couple of years ago I gave tutoring lessons to a couple of engineering students failing at programming 101, I have a feeling they are the kind of kids this study would gave up upon, and they just needed someone that would bother teaching them how you need to think about the kind of problem programming represents. This ain't magic just a set of instructions mathematically expressed that make something happen.



  • This is so weird. How can "assigning values to variables" be such an impossible concept?

    Although, in the questionnaire, they apparently jump straight to C syntax with no explanation. Of course people aren't going to magically know that "a = b" means "we copy the value from b to a" when they've been taught their entire lives it means "we declare a and b to have the same value". Or that the statements are executed sequentially.


  • kills Dumbledore

    I think that study has been fairly thoroughly discredited. I would imagine that any truth it has is more about how current teaching standards work for students with different learning styles or mental models.

    I don't think anybody is incapable of learning any particular thing, but that some respond better to the standard way certain things are taught over others. It also helps if you're interested in a subject enough to read around and/or practise it in your own time.


  • kills Dumbledore

    @anonymous234 said:

    Of course people aren't going to magically know that "a = b" means "we copy the value from b to a" when they've been taught their entire lives it means "we declare a and b to have the same value". Or that the statements are executed sequentially

    IIRC, the hypothesis wasn't about people understanding C syntax, more about being consistent. Consistently right or wrong was seen as better than answering each question differently. Although, if you have no idea, it makes sense to spread your net a bit wider in te hopes of picking up a few points rather than going all-or-nothing



  • @Jaloopa said:

    I think that study has been fairly thoroughly discredited.

    I think we talked about it in some depth around here....

    Jeff mentioned it first:

    http://what.thedailywtf.com/t/more-proof-that-discourse-sucks/714/23?u=boomzilla

    Then more recently (and the episode I remembered)...

    http://what.thedailywtf.com/t/programming-language-learning-curves/6735/164?u=boomzilla



  • Nice one. Good anecdata and analysis. 😄



  • @Yamikuronue said:

    Me: And there's no folders involved.
    Roommate: Bollocks that. F-O-L-D-R, what is that supposed to spell?!

    I have to admit - I did not see that coming.

    @Yamikuronue said:

    In theory this means functional programming would be easier to grasp, but in practice, cryptic syntax makes it inaccessible.

    Both the syntaxes must have been pretty cryptic for him. He didn't seem to understand that the curlys indicate scope and that the block would be repeated. Recognizing function application is right out.

    Ask him what this does: println "Hello, world!"

    Does he think it will spit a piece of paper from the printer with those words on it?

    What about echo "Hello, world!"?

    Can we come up with a name for println/echo that an unfamiliar person would understand? Wouldn't they have to understand the concept of the console first? Just how they'd have to understand the concept of iteration or scoping or function application?



  • Although, if you have no idea, it makes sense to spread your net a bit wider in te hopes of picking up a few points rather than going all-or-nothing

    Back when I was in middle school, I took a math quiz and got some points wrong. I talked about it to my dad, and I explained that I wasn't sure which formula was right, so I used one in one problem and another possibility in another.

    He was impressed that I hedged that way.



  • I'm not a n00b 😢



  • That's what they're doing with Common Core.

    Trying to teach math, before they teach math.

    First Jeff is making the assumption that the three weeks of training provided were worth the shit that finds its way onto my shoes while walking through this shit-landmine-field in the original article.

    between 30% and 60% of every university computer science department's intake fail the first programming course.

    I saw this. And to me it looked more like...

    "That's programming. Fine whatever, let me just get through this first class and change degrees".

    I truly believe it had more to do with the draw to programming being some mystical art that's never fully described to a lot of people, and so someone wants to be a programmer, but waits until college to let a class expose the art.

    Um.... that's not how a discipline works.

    If you haven't shown enough interest by the time you reach college to know what "assignment" is, then you don't need to be in a programming degree.

    I'm sure if some welder pulled me aside and asked me to identify what kind of weld was on two joints in his car's frame, and I shrugged, he wouldn't form an investigation on why people can't learn to weld.


    They didn't just look for "correct" answers, they looked for consistency. So, if you don't know that a=b means the value of b gets assigned to the value of a, then the group in the first bullet would create a mental rule for what it means, and consistently apply that rule throughout the test. The folks in the second bullet would 'change' that mental rule for each question.

    They're guessing. They're taking educational guesses. If they were told to be consistent beforehand, you think that might alter the results. If they were taught properly? It sounds like the premise is self-conflicting.

    But if you told someone to be consistent when guessing what might happen, and they chose not to be consistent.... then.... well.... something doesn't add up here.

    What you are really saying is that 40% of people can't consistently follow a pattern of predictability. That's a much bigger domain problem than teaching programming. I would think that these people would fail at math, grammar, and other scenarios where patterns have to stay consistent.

    http://www.wikihow.com/Use-You're-and-Your

    Well then....



  • Does hedging actually help in general?

    If it's one of two possibilities, you can do half one way and half the other: 100% odds of getting 50% right. Do them all one way: 50% odds of getting 100% right and 50% odds of getting 100% wrong.

    It gets more severe with more possibilities.

    50%/33%/25% are pretty low. If you're going to fail anyway by hedging, might as well take an approach that might work - just go with one.



  • I wasn't going to fail, just miss some points. But, the answer to your question is that it depends on the risk-free rate (i.e., what you can get if you hedge) and your aversion to risk. There's little point in not hedging if the difference is between getting an A or maybe getting an A+ or B+.



  • If I had been given that test before I knew anything about programming? With no explanation about how programming notation redefines some symbols? I would have seen that the third line was incorrect. My hypothesis would have been that the author of the test was either stupid or dishonest. I would have consistently refused to answer the question.



  • Also realize if your test is going to be graded by a human who might give some leeway, consistently applying the wrong formula is more likely to give you partial credit than picking a different random possibility for each question. Even owning up and giving both answers might work.



  • @tharpa said:

    I would have consistently refused to answer the question.

    Oh, don't do that.

    Hell hath no fury like a programmer community that hears someone is unwilling to answer stupid questions.



  • The test hinges on someone's ability to predict that it is assignment and not equivalence.
    What assignment would even mean.

    And shows a fundamental flaw in how we are teaching programming.

    If the test was somehow

    Assignment is [definition]

    a is assigned to the value of b
    b is assigned to the value of a

    What is a and what is b?

    Then maybe you'd have a chance.

    But what they're really testing is someone's ability to throw away everything they know and understand about symbols, meanings, maths, and identify syntax and guess at its function.

    All without any prodding.


    What they've admitted is that programming is an immature field where you have very little guidance, and it takes a very disciplined person to be able to achieve understanding, because we can't really teach it to you.

    They're basically taking the StackOverflow approach to programming.

    "Oh you want to learn programming. Show me what you've tried."



  • @xaade said:

    The test hinges on someone's ability to predict that it is assignment and not equivalence.
    What assignment would even mean.

    And shows a fundamental flaw in how we are teaching programming.

    If the test was somehow

    Assignment is [definition]

    a is assigned to the value of b
    b is assigned to the value of a

    What is a and what is b?

    Then maybe you'd have a chance.

    But what they're really testing is someone's ability to throw away everything they know and understand about symbols, meanings, maths, and identify syntax and guess at its function.

    All without any prodding.


    What they've admitted is that programming is an immature field where you have very little guidance, and it takes a very disciplined person to be able to achieve understanding, because we can't really teach it to you.

    They're basically taking the StackOverflow approach to programming.

    "Oh you want to learn programming. Show me what you've tried."

    I remember when I was learning programming, not so long ago, that the books had definitely not reached the same level of maturity as textbooks in other subjects. If I was getting some kind of error, I would have to figure out if the error was in my following the directions or the directions themselves. I agree that this helps keep out people without tenacity. Kind of like old Kung Fu teachers would not start to teach you until you had proved your sincerity by standing in the horse stance for two hours.


  • Discourse touched me in a no-no place

    @Captain said:

    Back when I was in middle school, I took a math quiz and got some points wrong.

    My greatest moment of awesome in my school test-taking career was in one exam which had multiple parts. I one section, I had no idea what the answers were; I literally did not know at all. Fortunately, it was multiple choice, so I just picked a random option for each of the questions (time taken, about a second each) and used the time to focus more strongly on the other parts where I knew what I was doing.

    I aced the exam. 😃 😈



  • Oh yeah, that's standard advice for actuarial exams (not to demean your ace). Do the easy ones first, fast; focus on the hard ones until you have 3 minutes left, guess randomly on the rest.


  • Discourse touched me in a no-no place

    @Captain said:

    Do the easy ones first, fast; focus on the hard ones until you have 3 minutes left, guess randomly on the rest.

    That only works with multi-choice exams, which is the major weakness with them. I favour avoiding multi-choice exams for exactly that reason; a semi-trained lemur can get an answer right.

    Lemurs are cool, but they really shouldn't be entrusted with professional qualifications.



  • All they have to do to adjust for luck is raise the standard by a point. In fact they do, and they explicitly tell examinees that it's in their interest to guess if they don't know an answer.


  • I survived the hour long Uno hand

    @Bort said:

    println "Hello, world!"

    "Print the line 'Hello, World!'?" Verbatim. Later he did say he was picturing paper.

    @Bort said:

    echo "Hello, world!"

    "I presume it would repeat back to you, Hello World, because that is what the word 'echo' means. I'm sure you have some other meaning for it. That might possibly mean copy the file? As opposed to just printing back to me the phrase? File, program, whatever."



  • I remember a math contest I participated in several years during school which was multiple choice, where a correct answer would earn you points, not answering was neutral, and giving a wrong answer actually penalized you. At 5 answers per question though, the odds of guessing weren't too good to begin with.

    http://www.w4kangoeroe.nl/kangoeroe/ - odd, says worldwide in the title but no international website link.


  • area_deu

    I loved that contest.
    I won prices every time!


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.