I ❤ BQN and Haskell

Sdílet
Vložit
  • čas přidán 27. 06. 2024
  • LeetCode Problem: leetcode.com/contest/weekly-c...
    BQNPAD: bqnpad.mechanize.systems/
    BQN Solution: github.com/codereport/LeetCod...
    Haskell Solution: github.com/codereport/LeetCod...
    Chapters:
    0:00 Intro
    2:16 BQN Solution
    5:59 Haskell Solution
    10:04 Solution Comparison
    11:50 Outro
    Follow me on GitHub: github.com/codereport
    Follow me on Twitter: / code_report
    Follow me on LinkedIn: / codereport

Komentáře • 86

  • @ponirvea
    @ponirvea Před rokem +12

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

  • @perekman3570
    @perekman3570 Před rokem +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 Před rokem +21

      I'd settle for a useful commandline tool.

    • @derelbenkoenig
      @derelbenkoenig Před rokem +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 Před rokem +3

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

    • @keldwikchaldain9545
      @keldwikchaldain9545 Před 11 měsíci +3

      CBQN has some basic C bindings available.

  • @simulatrix
    @simulatrix Před rokem +4

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

  • @noomade
    @noomade Před rokem +5

    ❤❤ Haskell ❤❤

  • @s90210h
    @s90210h Před rokem +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.

  • @jasenq6986
    @jasenq6986 Před rokem

    you are a great explainer

  • @AvrDusk
    @AvrDusk Před rokem +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  Před rokem +6

      That video implicitly exists already inside this one: czcams.com/video/8ynsN4nJxzU/video.html and also this one: czcams.com/video/UogkQ67d0nY/video.html

  • @nel_tu_
    @nel_tu_ Před rokem +9

    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 Před rokem +1

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

    • @user-tx4wj7qk4t
      @user-tx4wj7qk4t Před 3 měsíci

      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

  • @arraymac227
    @arraymac227 Před 8 měsíci

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

  • @jpbastyr
    @jpbastyr Před rokem

    Beautiful

  • @w-mcode6520
    @w-mcode6520 Před 11 měsíci +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
    ```

  • @joaovitorprudente1976
    @joaovitorprudente1976 Před rokem +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?

  • @moumnalmunawy1806
    @moumnalmunawy1806 Před rokem +3

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

  • @Vexxel256
    @Vexxel256 Před rokem

    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  Před rokem +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/

  • @YOOOOOOOOOOOOOOOOOOOOOOOOOOOO

    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  Před rokem +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 Před rokem +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

  • @MiiaoTheFC
    @MiiaoTheFC Před rokem +2

    Would be nice to see C++ and Rust solutions

    • @code_report
      @code_report  Před rokem +5

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

  • @lesfreresdelaquote1176
    @lesfreresdelaquote1176 Před 8 měsíci

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

  • @Al-.-ex
    @Al-.-ex Před rokem

    Cool

  • @rubenverg
    @rubenverg Před rokem +3

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

    • @code_report
      @code_report  Před rokem +1

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

    • @kilianvounckx9904
      @kilianvounckx9904 Před rokem +1

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

  • @professornumbskull5555
    @professornumbskull5555 Před rokem +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

  • @NilesMontblair
    @NilesMontblair Před rokem +5

    has BQN replaced APL as your favorite language?

  • @alpaslaneldemir6904
    @alpaslaneldemir6904 Před rokem

    Which city which conference ? If its close I might attend

    • @code_report
      @code_report  Před rokem

      LambdaDays in Krakow: www.lambdadays.org/lambdadays2023

  • @SimGunther
    @SimGunther Před rokem +5

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

  • @derelbenkoenig
    @derelbenkoenig Před rokem

    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  Před rokem +1

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

    • @derelbenkoenig
      @derelbenkoenig Před rokem

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

  • @NikolajLepka
    @NikolajLepka Před rokem +1

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

    • @code_report
      @code_report  Před rokem +3

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

  • @donciclon
    @donciclon Před 7 měsíci

    lol @ 3 glyphs being 'overly verbose'🤣

  • @RishabhRD
    @RishabhRD Před rokem +1

    I got rank 379 in this contest

  • @c4tubo
    @c4tubo Před rokem

    BQN FTW

  • @briannormant3622
    @briannormant3622 Před rokem +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 Před rokem +3

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

    • @briannormant3622
      @briannormant3622 Před rokem +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 Před rokem +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 Před rokem +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.

  • @vaaaaaas
    @vaaaaaas Před rokem

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

  • @crides0
    @crides0 Před rokem

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

  • @lazboi5686
    @lazboi5686 Před rokem

    what

  • @jaoarsntYdlahwfp
    @jaoarsntYdlahwfp Před rokem +2

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

  • @mskiptr
    @mskiptr Před rokem

    [ abs (l - r) | l

  • @noomade
    @noomade Před rokem +2

    what do you think of?
    leftRightDifference = (zipWith ((abs .) . (-)) . init . scanl (+) 0) (tail . scanr (+) 0)
    also, _"Haksell FOURTH fav language"_ ??? what happened ???
    😢

    • @code_report
      @code_report  Před rokem +2

      1. BQN
      2. APL
      3. Clojure
      4. Haskell
      I toggle between Clojure and Haskell but I find Clojure more useful in practice.

    • @noomade
      @noomade Před rokem

      @@code_report Hearing you choose Clojure over Haskell hurts my soul 😛
      Looking forward to your next video!

    • @WilcoVerhoef
      @WilcoVerhoef Před rokem

      I think you meant instead of . before init. Also, you can remove 2 sets of parenthesis 🙌

    • @noomade
      @noomade Před rokem

      ​@@WilcoVerhoef no.. i meant (.) .. My code works, I was just asking what he thinks of it.
      (abs .) . (-)
      is the point free version of
      \x y -> abs $ x - y
      but sure or fmap for functions (->) is indeed the same as composition or (.)
      f g = f . g
      so you could write
      (abs ) (-)
      but I think you would have to be some sort of masochist (and sadist) to write instead of . 😃

    • @WilcoVerhoef
      @WilcoVerhoef Před rokem

      @@noomade You're right, both (.) and () works. Weird.

  • @samuelfigueroa-lazu9093
    @samuelfigueroa-lazu9093 Před rokem +1

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

    • @kotkis
      @kotkis Před 11 měsíci

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