I ❤ BQN and Haskell

Поділитися
Вставка
  • Опубліковано 19 вер 2024

КОМЕНТАРІ • 77

  • @ponirvea
    @ponirvea Рік тому +13

    liftA2 in Haskell (in Control.Applicative module) is a builtin phi combinator

  • @perekman3570
    @perekman3570 Рік тому +114

    Enough with the trivial examples! Now let's see a 3D game engine in BQN. Can you do it in 25 lines of code or less?

    • @andrewdunbar828
      @andrewdunbar828 Рік тому +21

      I'd settle for a useful commandline tool.

    • @derelbenkoenig
      @derelbenkoenig Рік тому +3

      If I had to guess, the part that computes game state probably could be, if you omit the part that does I/O (controls, graphics, audio)

    • @VojtaJavora
      @VojtaJavora Рік тому +3

      @@derelbenkoenig so we just need like C bindings and we are ready to go

    • @keldwikchaldain9545
      @keldwikchaldain9545 Рік тому +3

      CBQN has some basic C bindings available.

  • @simulatrix
    @simulatrix Рік тому +4

    I’ve been working on an ASCII-based array language called Noda. Here’s how I’d solve it:
    *abs(>>nums(+) - > and

  • @s90210h
    @s90210h Рік тому +3

    I love these videos where there are multiple languages. You get to see what is kinda the same, and what really has to be different. If it was just one language I would get it less. I think I learn a lot from seeing the difference at work to make sense of both.

  • @nel_tu_
    @nel_tu_ Рік тому +10

    your haskell function looks very clean. it uses an extra function declaration and a (.:) operator import, however. here's my attempt at solving with just the haskell prelude. :]
    leftRightDifference = zipWith ((abs .). (-)) . (tail . scanr (+) 0) (init . scanl (+) 0)

    • @derelbenkoenig
      @derelbenkoenig Рік тому +1

      Was hoping to see the applicative instance of reader (S combinator) come up! Nice

    • @AndreiGeorgescu-j9p
      @AndreiGeorgescu-j9p 6 місяців тому

      That's ugly... Why in the world would you be against using things outside of the prelude? You know the prelude is universally considered terrible right? People are so weird

  • @AvrDusk
    @AvrDusk Рік тому +10

    I love it. Can you make a video comparing the differences between BQN and APL? They seem quite similar, but I wonder why they say BQN is better

    • @code_report
      @code_report  Рік тому +6

      That video implicitly exists already inside this one: ua-cam.com/video/8ynsN4nJxzU/v-deo.html and also this one: ua-cam.com/video/UogkQ67d0nY/v-deo.html

  • @w-mcode6520
    @w-mcode6520 Рік тому +1

    Instead of defining the `phi` combinator yourself, you can also look at the `Control.Arrow` (and `Control.Category`) module, which gives rise to the following Haskell solution:
    ```
    ((scanl (+) 0 >>> init) &&& (scanr (+) 0 >>> tail)) >>> uncurry (zipWith (-)) >>> map abs
    ```

  • @arraymac227
    @arraymac227 11 місяців тому

    That BQN had shift primitives and the Under operator did help. Something for my SugarBQN namespace.

  • @joaovitorprudente1976
    @joaovitorprudente1976 Рік тому +3

    When I'm doing some hard leet code problems, I struggle to find a functional solution, it seems that those problems are created in a way to be solved with dynamic programming. Can you do a video solving some problems tagged hard on leet code or any other site using the functional paradigm?

  • @lesfreresdelaquote1176
    @lesfreresdelaquote1176 11 місяців тому

    Hello, this is very interesting. I have been using a Lisp (LispE by Naver) that provides some APL-like instructions and I came up with the following solution:
    (zipwith (\(x y) (fabs (- x y))) (cons 0 (pop (\\ '+ r))) (consb (cdr (reverse (-\\ '+ r) )) 0))
    \\ and -\\ are the scan and back-scan operators and '\' introduces a lambda function... Very similar to your own solutions...

  • @moumnalmunawy1806
    @moumnalmunawy1806 Рік тому +3

    Can you please add common lisp sbcl to the problems videos solutions

  • @YOOOOOOOOOOOOOOOOOOOOOOOOOOOO
    @YOOOOOOOOOOOOOOOOOOOOOOOOOOOO Рік тому +6

    Do you think that languages like BQN and APL should be used in the making of commercial products or just as a fun exercise?

    • @code_report
      @code_report  Рік тому +3

      I think they are great for both. BQN is a very young language but there are already a bunch of companies that use APL in production: github.com/interregna/arraylanguage-companies

    • @derelbenkoenig
      @derelbenkoenig Рік тому +5

      @@code_report I always get thrown off how many of the companies doing fancy code stuff are in finance, I guess it makes sense since finance companies are likely hiring mathematicians and not just regular software developers

  • @NilesMontblair
    @NilesMontblair Рік тому +5

    has BQN replaced APL as your favorite language?

  • @SimGunther
    @SimGunther Рік тому +5

    Can we get maintainable code in BQN? I'm talking a project with a shelf life of more than 6-9 months.

  • @jasenq6986
    @jasenq6986 Рік тому

    you are a great explainer

  • @MiiaoTheFC
    @MiiaoTheFC Рік тому +2

    Would be nice to see C++ and Rust solutions

    • @code_report
      @code_report  Рік тому +5

      Here is a Rust solution using a array library in Rust (but unfortunately it's not public atm): pastebin.pl/view/5caf93b6

  • @professornumbskull5555
    @professornumbskull5555 Рік тому +4

    The rust version should be,
    nums
    .iter()
    .copied()
    .zip(nums
    .iter()
    .rev()
    .copied())
    .scan((0, 0), |acc, (l_ele, r_ele) {
    let ret_val = *acc;
    *acc = (acc.0 + l_ele, acc.1 +r_ele);
    ret_val
    }).map(|(a, b)| a - b)
    .map(i32::abs)
    .collect()
    A lot more verbose but that's because it's a bit different approach

  • @rubenverg
    @rubenverg Рік тому +3

    I would assume Ctrl+L clears the screen in GHCi. Also yeah structural Under is so cool

    • @code_report
      @code_report  Рік тому +1

      Thanks! I think knew that at one point but forgot. And agree, under is awesome!

    • @kilianvounckx9904
      @kilianvounckx9904 Рік тому +1

      When you type :! In ghci you can do shell commands. So :!clear will clear the screen

  • @jpbastyr
    @jpbastyr Рік тому

    Beautiful

  • @jaoarsntYdlahwfp
    @jaoarsntYdlahwfp Рік тому +2

    Control.Arrow might come handy with uncurry
    (&&&) :: (a -> b) -> (a -> c) -> (a -> (b,c))

    • @ponirvea
      @ponirvea Рік тому +1

      `uncurry` is in the Prelude i think

    • @jaoarsntYdlahwfp
      @jaoarsntYdlahwfp Рік тому

      @@ponirvea yes (&&&) is not however

  • @Vexxel256
    @Vexxel256 Рік тому

    How do you guys program in APL? Do you have a custom keyboard that contains all apl symbols? Do you just have a tab open with ascii tables?

    • @code_report
      @code_report  Рік тому +1

      Most editors you type ` (backtick) and then a key. And you very quickly memorize the symbols. `i is iota. You can try here: tryapl.org/

  • @vaaaaaas
    @vaaaaaas Рік тому

    Why use x rated videos when you can read BQN solutions?

  • @NikolajLepka
    @NikolajLepka Рік тому +1

    didn't take you long to switch alleigence away from APL :P

    • @code_report
      @code_report  Рік тому +3

      haha, APL is still my second favorite languages. BQN has more combinators and sort primitives though 😂

  • @derelbenkoenig
    @derelbenkoenig Рік тому

    I thought the B combinator was
    B f g x y = f x (g y)
    Are there different naming schemes for them?

    • @code_report
      @code_report  Рік тому +1

      No, that is the D combinator. See here: combinatorylogic.com/table.html

    • @derelbenkoenig
      @derelbenkoenig Рік тому

      @@code_report Oh, yeah. I was thinking of B1 the Blackbird, but I was also wrong there too

  • @briannormant3622
    @briannormant3622 Рік тому +3

    Yeah that's quite cool. But i still prefer the readablity and simplicity of plain C:
    /*Caller free the result*/
    int *solve(const int *array, size_t size) {
    int *result = malloc(size * sizeof(int));
    int *lsum = calloc(size, sizeof(int));
    int *rsum = calloc(size, sizeof(int));
    for (size_t i = 1; i < size; i++) {
    lsum[i] = lsum[i - 1] + array[i - 1];
    rsum[size - i - 1] = rsum[size - i] + array[size - i];
    }
    for (size_t i = 0; i < size; i++)
    result[i] = abs(lsum[i] - rsum[i]);
    free(lsum);
    free(rsum);
    return result;
    }
    No need to know about any weird concept or some obsure std feature. plain, readable procedural code.

    • @computer-love
      @computer-love Рік тому +3

      one person's "weird concept" is another person's "intuitive pattern"

    • @briannormant3622
      @briannormant3622 Рік тому +3

      @@computer-love I didn't say it wasn't intuitive. I mean't that if you need to use the specific language to understand what does the symbols actually mean and implies.
      The power (IMO) of procedural is that you can follow the execution as it happen. This lead to more obvious and easy to understand code. much cleaner than APL or BQN
      (no, having a bunch of cryptic characters isn't by any mean clear).
      If you learned any language of the C family (java, c++,... and any language which support procedural pattern) you can easily reason and understand what the code actually mean. In small, easy problem like this one both are good, but i have my doubt about the readability of a big BQN project.
      Don't get me wrong, i really some feature of functional language (i love the Maybe / Error / Option monad) I just think using every feature of the language makes code less pretty and easy to follow.

    • @abcxyz5806
      @abcxyz5806 Рік тому +1

      Haha this is the other extreme :) I also don't know BQN, but I have played around with some haskell in Uni. I really liked these list operations like fold, map, filter. I think for me the most readable approach would be something like Python Numpy or C# Linq, which is from my understanding close to the haskell solution

    • @jamieg2427
      @jamieg2427 Рік тому +1

      the only reason that feels simple is because we're used to C. i tutor and the concepts in your code are not remotely simple for most students.
      the most popular languages derive from procedural or C style programming, so of course that's what you're comfortable reading. as for following the execution, again, that's a function of familiarity with the language. one can follow the BQN code just fine, not to mention taking it apart piece by piece to watch literal data mutation is trivial.

  • @alpaslaneldemir6904
    @alpaslaneldemir6904 Рік тому

    Which city which conference ? If its close I might attend

    • @code_report
      @code_report  Рік тому

      LambdaDays in Krakow: www.lambdadays.org/lambdadays2023

  • @Al-.-ex
    @Al-.-ex Рік тому

    Cool

  • @donciclon
    @donciclon 10 місяців тому

    lol @ 3 glyphs being 'overly verbose'🤣

  • @mskiptr
    @mskiptr Рік тому

    [ abs (l - r) | l

  • @c4tubo
    @c4tubo Рік тому

    BQN FTW

  • @RishabhRD
    @RishabhRD Рік тому +1

    I got rank 379 in this contest

  • @crides0
    @crides0 Рік тому

    crude ngn/k solution (as a function) before watching: t:{a:(+\x)-|+\|x;a*1 -1a

  • @lazboi5686
    @lazboi5686 Рік тому

    what

  • @samuelfigueroa-lazu9093
    @samuelfigueroa-lazu9093 Рік тому +1

    Love it! A great video to pause and ponder. This was my attempt in BQN +`∘»{|𝔽-𝔽⌾⌽}

    • @kotkis
      @kotkis Рік тому

      In fact it's enough to do: |+`⌾⌽-+` The shifts are not needed!