Huskscript? In my Rosetta Code? It's more likely than you think



  • There is a lot to be said about the usage of functional programming - just because you know FP doesn't mean you should use them at full strength all the time. You wouldn't want to flex your FP muscles in places like FreeCodeCamp or Rosetta Code, right?

    Apparently someone doesn't understand this, because when I was checking how to write varargs function in some ancient language I came across this:

    Whoever wrote the ES6 JS part is clearly on cracks, or more specifically, Haskell crack. Let's marvel at what this person has written to demonstrate varargs in ES6, which should've been simpler than ever:

    let
      fix = // Variant of the applicative order Y combinator
        f => (f => f(f))(g => f((...a) => g(g)(...a))),
      forAll =
        f => 
          fix(
            z => (a,...b) => (
              (a === void 0)
              ||(f(a), z(...b)))),
      printAll = forAll(print);
     
    printAll(0,1,2,3,4,5);
    printAll(6,7,8);
    (f => a => f(...a))(printAll)([9,10,11,12,13,14]);
    //  0
    //  1
    //  2
    //  3
    //  4
    //  5
    //  6
    //  7
    //  8
    //  9
    //  10
    //  11
    //  12
    //  13
    //  14
    

    Okay, what does a fix-point combinator have to do with varargs function, in JS, a non-FP exclusive language? The // Variant of the applicative order Y combinator comment is especially flex-y, just in case you don't know they're writing a golfed version of fix-pont combinator. Obviously it's not demonstrating the basic usage of varargs in ES6 at all. Well, otherwise the writer couldn't flex their Haskell knowledge: see? They even wrote

    Of course, a better version might use Array.prototype.map, but here we have a variant that works on variadic arguments:

    So clearly they know that they're flexing, but went on to flex anyway. On Rosetta Code of all things.

    And, less ambitiously, the second part is even worse!

    (() => {
        'use strict';
     
        // show :: a -> String
        const show = x => JSON.stringify(x, null, 2);
     
        // printAll [any] -> String
        const printAll = (...a) => a.map(show)
            .join('\n');
     
        return printAll(1, 2, 3, 2 + 2, "five", 6);
    })();
    

    Oh hey look, Haskell syntax in the comments! Just in case you don't know the specific brand of crack they're smoking is Haskell. I also like the use of JSON.stringify(x, null, 2), which is just icing on the cake. Whoever wrote it clearly thought varargs is a piece of cake, so they have to add lots of FP crack on it.


    n.b Husk is a Haskell-based golfing language. When you try to write golfed Haskell-like code in JS, clearly the only appropriate name for it is Huskscript.


  • BINNED

    This reminds me of how Wikipedia the "encyclopedia that anyone can edit" seems to inspire people to think they need to upload pictures of specifically their own penises cats as illustrative material for the corresponding articles.



  • @topspin said in Huskscript? In my Rosetta Code? It's more likely than you think:

    This reminds me of how Wikipedia the "encyclopedia that anyone can edit" seems to inspire people to think they need to upload pictures of specifically their own penises cats as illustrative material for the corresponding articles.

    It's the typical grandstanding arms race. "My cat is bigger than yours!" "nou" "nouu"...


  • BINNED

    @_P_
    sorry to disappoint but you don't really need a bigger pussy



  • @_P_ said in Huskscript? In my Rosetta Code? It's more likely than you think:

    You wouldn't want to flex your FP muscles in places like FreeCodeCamp or Rosetta Code, right?

    Sure I would, where else would I flex them?


  • Banned

    @_P_ the best part is that they're using actual variadics multiple times in the code.


  • ♿ (Parody)

    @_P_ said in Huskscript? In my Rosetta Code? It's more likely than you think:

    When you try to write golfed Haskell-like code in JS, clearly the only appropriate name for it is HuskCricketscript.



  • This guy's just coding out his endofunctor



  • This post is deleted!

Log in to reply