Functional vs Array Programming

  Рет қаралды 128,479

code_report

code_report

Күн бұрын

My unofficial Strange Loop 2021 Conference Talk where I compare the functional and array programming paradigms.
Array Languages:
APL: www.dyalog.com/
J: www.jsoftware.com/
BQN: mlochbaum.github.io/BQN/
Functional Languages:
Haskell: www.haskell.org/
Scala: www.scala-lang.org/
ADSP The Podcast: adspthepodcast.com/
ArrayCast: www.arraycast.com/
Programming Languages Virtual Meetup: www.meetup.com/Programming-La...
Functional / BQN Blog Post: mlochbaum.github.io/BQN/doc/f...
Chapters:
0:00 Introduction
0:11 About Me
1:24 5 Favorite Programming Languages
1:48 List of Functional / Array Languages
2:24 Problem Statement
3:15 Problem Examples
4:40 Imperative Solution Walkthrough
6:30 C++ Solution
7:12 Python Solution
7:58 Functional Solution Walkthrough
9:47 Scala Solution
11:20 Haskell Solution
13:23 Combinatory Logic Digression
17:28 S Combinator Explanation
18:34 Understanding the S Combinator in Haskell
20:10 APL Solution
20:48 APL vs Haskell Solution Comparison
22:35 S' Combinator Explanation
23:22 C Combinator Explanation
24:15 SKICW Combinators in Haskell & APL
25:20 Haskell vs APL Language Comparison
26:45 Haskell vs APL vs BQN Language Comparison
27:00 APL vs BQN Solution Comparison
27:50 Functional Programming / BQN Blog Post
28:05 Final Summary
29:47 Outro
Follow me on Github: github.com/codereport
Follow me on Twitter: / code_report
Follow me on LinkedIn: / codereport

Пікірлер: 402
@gardendado1999
@gardendado1999 Жыл бұрын
Dude I'm high as f watching random cs videos and I see we returned to hieroglyphs wtffffffff
@vaap
@vaap Жыл бұрын
I love this so much
@willmcpherson2
@willmcpherson2 Жыл бұрын
bro 💀
@swyveu
@swyveu 7 ай бұрын
420 likes .... coincidence?
@arshamshayan
@arshamshayan 6 ай бұрын
my exact reaction when I saw APL for the first time 😭
@yeicore
@yeicore 2 жыл бұрын
APL is how coding looks like for non-coders
@everyhandletaken
@everyhandletaken 2 жыл бұрын
Looks like emojilang & mindf$ck had a baby & they named it APL. 🤯
@NStripleseven
@NStripleseven Жыл бұрын
Most coding languages look like gibberish to non-coders, APL looks like gibberish to everybody. Equality.
@everyhandletaken
@everyhandletaken Жыл бұрын
@@NStripleseven lol I like that analogy!
@torarinvik4920
@torarinvik4920 Жыл бұрын
This comment is epic, it's so accurate!
@viridianite
@viridianite Жыл бұрын
So are you saying APL programmers are above coders? lol
@telnobynoyator_6183
@telnobynoyator_6183 2 жыл бұрын
what programming looks like to non programmers
@yardez5990
@yardez5990 2 жыл бұрын
APL looks like minecraft enchanting table language
@saidkorseir192
@saidkorseir192 2 жыл бұрын
I am .net developer for 6+ years. I didn't understand anything not a jot.
@TRVQ2
@TRVQ2 Жыл бұрын
@@saidkorseir192 Then just start from Python first ;)
@espana86
@espana86 Жыл бұрын
Doesn't APL look very similar to just Greek?
@halneufmille
@halneufmille 2 жыл бұрын
APL feels like Chinese in that there is a single symbol per concept. The learning curve is steep but it's beautifully rewarding when you get there.
@15shekels
@15shekels 2 жыл бұрын
Me: oh c++ thats pretty verbose but I can somewhat understand it *changes to python* Ah! I really get the idea now, yeah this is fairly intuitive *switches to scalla and haskel* uhhh huh... *digression* im trippin balls dude *switches to APL* WHAT THE F-
@monad_tcp
@monad_tcp 2 жыл бұрын
"WHAT THE F-" F\omega is a programming language too.
@monad_tcp
@monad_tcp 2 жыл бұрын
After APL and Haskell blew your mind. You are read for ...... ..... Forth
@15shekels
@15shekels 4 ай бұрын
@@user-tx4wj7qk4t dawg I wrote this 2 years ago. Recently dabbled with C / Raylib and can confirm what you say is true
@guilhermegigeck5946
@guilhermegigeck5946 2 жыл бұрын
Honestly, from the video you made me prefer Haskell over APL. It really doesn't matter if the code is shorter if you need someone specialized on the language to make sense of it, while on Haskell after you explained the S operator and that was all I needed to get a rough ideia of what the code was doing.
@hongnken
@hongnken 2 жыл бұрын
I totally agree. Haskell nails both readability and simplicity
@batlin
@batlin Жыл бұрын
Many would take that further and justify Scala over Haskell, then Java over Scala, then C over Java, then assembly over C. The question is whether the value you get is worth it in exchange for initial understanding barrier. Personally I'm intrigued enough to try APL and BQN out.
@casperes0912
@casperes0912 Жыл бұрын
@@batlin How on Earth did you get to assembly being more readable than C or Java?
@batlin
@batlin Жыл бұрын
@@casperes0912 I didn't. Please read the thread again.
@smurfo4221
@smurfo4221 Жыл бұрын
APL isn't meant to be read, its a write it once and then recreate it if you need to change it later kind of thing. This is at least what everyone i've been learning from has said. This might seem stupid, but the language is meant to be easily written out so you can focus on the thing that needs to be done instead of how to do it.
@lane1313
@lane1313 2 жыл бұрын
I have an APL book called "APL An Interactive Approach" and you can tell it's old because it asks you to plug your computer into a phone line. Such a weird and obscure language but it was pretty fun to mess around with.
@skratky
@skratky 2 жыл бұрын
Great talk. For reference, this is how you could solve the problem in the Wolfram Language: (nums - FoldList[Min, nums]) // DeleteCases[0] // Prepend[-1] // Max
@telnobynoyator_6183
@telnobynoyator_6183 2 жыл бұрын
Readable AND short ? Looks like a great language to me !
@raianmr2843
@raianmr2843 Жыл бұрын
my normie ass automatically assumed everything after // to be comments, spent a solid 10 secs thinking about where the rest of the logic was
@kDrewAn
@kDrewAn 2 жыл бұрын
Im pretty sure APL is the code Neo sees as the matrix when he gets revived… the moral of the film is we should all take a page from neo’s book and learn APL 😤
@benjaminscherrey1124
@benjaminscherrey1124 2 жыл бұрын
When introducing the Python solution @ 17:12 , replaces clear easy to read semantically meaningful variable names with short abbreviations while stating "...change the variable names to make them more concise which, in my opinion makes them a lot more readble" - realizing, oh yeah his fav language is APL! ;-) haha Also nice job on the combinators intro!
@johannestafelmaier616
@johannestafelmaier616 2 жыл бұрын
It's 7:12
@voxelfusion9894
@voxelfusion9894 2 жыл бұрын
Yeah I was like, this has to be sarcasm, making fun of unreadable code and mystery names. Later I realized he's simply nuts.
@saltrocklamp199
@saltrocklamp199 2 жыл бұрын
Yeah, this is a style that I strongly disagree with. Also, the Python algorithm is a linear scan, while the functional version seems like it might end up making 2 passes over the data, unless I misunderstand how Haskell and friends can optimize code. I would have assumed the Haskell version was just the imperative version translated to recursion.
@austininflorida
@austininflorida 2 жыл бұрын
My least favorite part of programming is figuring out what everyone's abbreviations mean. They are never as obvious to the reader as they are to the writer.
@imadetheuniverse4fun
@imadetheuniverse4fun 2 жыл бұрын
@@austininflorida Also when they abbreviate words by a single letter to make it just that bit shorter. It's like... why? "low" becomes "lo"... just write "low"!
@anthonycousins853
@anthonycousins853 2 жыл бұрын
Thank you so much. This is by far the most accessible intro to combinators and combinatorial logic I've ever seen. I do admit to never making a true effort to seek out understanding of combinators beyond a very quick skim of Wikipedia, but that doesn't change the fact that what little effort I have put in was never rewarded with conceptual clarity. For example, all previous videos I've seen making the claim that they are an easy intro to the topic... well, they failed me. I guess what I'm saying is thank you! So concise and clear and completely useful!
@TimothyJesionowski
@TimothyJesionowski 2 жыл бұрын
I never even knew these existed. I barely understand basic FP tools like map/zip...
@atrus3823
@atrus3823 2 жыл бұрын
Great video! Really interesting. A couple of comments: 1. It seems really redundant to use -1 to signify no solution, since, if you read the problem carefully, nums[i] < nums[j]. This means that nums[j] - nums[i] > 0, if a candidate solution. So, if max of all candidates is 0, there is no solution. This would simplify the Scala especially. 2. I understand that Python was just used as an example language for imperative programming, but it could come off that you were comparing Python and Haskell/Scala's abilities, when Python is capable of solving this in a very functional manner as well. In fact, the implementation can be quite elegant: max(map(sub, nums, accumulate(nums, min))) Though Python does not explicitly have scanLeft or zipWith, Python's map auto zips multiple iterables, and the standard itertools library has accumulate, which is essentially the same as scanLeft. Conveniently, if you don't provide an initial value to accumulate, the first value is just the first item of the iterable (which seems similar to Haskells scanl1). Python's operator library provides the sub function. One other nice thing about this, is that it works entirely with iterators, so there are no intermediate results. If you want to use -1's instead of 0's, I think the most elegant way would just be to use an 'or' operator, since 0 is falsey: max(map(sub, nums, accumulate(nums, min))) or -1
@MrMeszaros
@MrMeszaros 2 жыл бұрын
Thanks - just wanted to say that functional solutions can be written in Python!
@geeshta
@geeshta 2 жыл бұрын
@@a2sbestos768 Also I don't think variable names as "lo" and "e" should be used in Python, as explicit is better. Also I'm a huge fan of type annotations so I'd prefer def maximum_range(nums: List[int]) -> int:
@rikschaaf
@rikschaaf 2 жыл бұрын
@@geeshta It is the trade-off between code readability and code "elegance". Some people like it when there is as little as possible boilerplate and redundant code. Long variable names are therefore a no-no if a shorter one conveys its purpose well enough. Lo for "the lowest number so far" is good enough in this case. I do think that this does increase the size of your function documentation though, because you need to define more specifically what a variable means. Same goes for the "elegant" uses of the combinators to combine multiple statements into one line to not repeat the use of a variable for instance. Sure it saves characters, but you now need to spend more characters in the documentation to help future code refactorers decipher what the piece of code does.
@gloverelaxis
@gloverelaxis Жыл бұрын
this is *infinitely* better code than every example in the video. self-describing and simple
@jumbo_mumbo1441
@jumbo_mumbo1441 Жыл бұрын
You swapped i and j in your first point, just fyi
@stevemcgrath4040
@stevemcgrath4040 2 жыл бұрын
APL (A Programming Language) has been the source of jokes in the programming community for nearly 50 years! I couldn’t readily find good references beyond en.wikipedia.org/wiki/Write-only_language?wprov=sfti1 , but there used to be fun competitions on who could write the shortest and most indecipherable code in APL. More practically, APL started out at a time when programming was still regarded by some as an extension of pure mathematics, so a highly symbolic syntax was not totally out of left field. Memory at the time was also at a premium, likely costing over a dollar a bit, so being able to represent core functionality in a glyph represented by just a few bits had practical benefits.
@FaranAiki
@FaranAiki 2 жыл бұрын
I thought it was, "Array Programming language".
@foxoninetails_
@foxoninetails_ Жыл бұрын
Iverson's decision to keep APL functionality to single glyphs was far less a product of chance or circumstance than of intention. While it may have helped save on memory incidentally, programming was by no means considered "an extension of pure mathematics" in the 60s; these were the days of FORTRAN and COBOL, when programming was still in its infancy but was largely verbose and strictly procedural, and was beginning to be more and more seriously used for day to day business rather than simply mathematics. Even at the time, APL's syntax was very much out of left field to most programmers. It was no mistake or happenstance that he chose notation so dense. Rather, he considered the dense notation of APL to be a feature and selling point in itself, as once you get past the learning curve of understanding the notation, its density shifts into clarity and ease of expression, similar to how exceptionally complex concepts can be expressed in very small amounts of mathematical notation. I highly recommend reading through his paper "Notation as a Tool of Thought" for more insight on why he chose to lean in the direction of the more "mathematical" appearance of APL.
@swikle
@swikle 7 ай бұрын
@@foxoninetails_ That sounds like a reasonable explanation. I would guess that, based on the fact that he wrote that paper, it is the correct one. I may try to track the paper down now. One of the first books I owned was APL/360: An Interactive Approach. In 1972, in high school, the only terminal I had access to was based on the IBM Selectric Typewriter. That was a very successful typewriter for IBM and it had swappable character balls. At the time, I did know Iverson worked for IBM and I had assumed the "weird character" approach was because at IBM Research, they might have been encouraged to help sell Selectric based technology. I don't think the language became as mainstream as IBM might have hoped. However, there are a lot of people my age, those who leaned towards math anyway, who learned that language right after FORTRAN and were quite taken by it. I think APL taught me more about how to think as a programmer than any thing I learned in my high school and college careers. I have run into many people since in the tech world who also fell in love with APL. And I would say, to some extent, it taught me how to think about matrix math in general.
@ianbridges6040
@ianbridges6040 2 жыл бұрын
This is probably one of the, if not the best, computer science video I have ever watched. This helped me expand my perspective on problem solving as a new programmer. Thank you!
@deanroddey2881
@deanroddey2881 2 жыл бұрын
Personally, I'd take the C++ (or a Rust) implementation. It's more obvious what's going on and all of the intermediate values are easily available for evaluation or logging or whatever during debugging. And it's likely better performing, particularly once you get beyond trivial examples. And of course, you can just put the whole thing in a helper if you need the algorithm more than once, and you never even see the guts unless you need to (at which point it's a lot easier to see the guts.) I'd also argue that extremely minimal syntax isn't really an important goal of software. Creating products for people to use is the real purpose of software. One problem in software (as in many pursuits) is that too many people become more about the pursuit itself than about the purpose of the pursuit. Nothing wrong with that in and of itself, but it can become an issue. I think C++ is suffering from this currently. It's too driven by people who are into languages and not enough people who just want to create products for people to use.
@lorenzrosenthal119
@lorenzrosenthal119 2 жыл бұрын
it's all fun and games until you need to reason about side effects and concurrency...
@deanroddey2881
@deanroddey2881 2 жыл бұрын
@@lorenzrosenthal119 Whether a piece of code has side effects isn't a function of the language it's written in. You can of course write plenty of C++ code that is without side effects, in those areas where it's a benefit, but not have to jump through hoops to deal with mutable shared state, which is something that you often really need. Sometimes everyone needs to agree on the state of the state right now.
@mbartelsm
@mbartelsm 2 жыл бұрын
I agree, when programming we are programming for other people, and that usually means that elegant code is probably not what you want to write. Take the haskell S-combinator, it'd probably be just as readable, if not more, to just define an argument and pass that to the function.
@alexanderrowe1042
@alexanderrowe1042 2 жыл бұрын
@@deanroddey2881 it sort of is based on language though. Sure I can write c++ with no side effects but there's not many language level constructs to guarantee it. As a mutable / effectful language by default, the burden is put onto the developers to opt into it, which means i don't really trust any c++ code to do what it says haha. When working in a large code base I have to hope they aren't doing anything funky and have to read the implementation of code more than I would like to. When a language supports it from a more basic level I can KNOW when something is a pure function which saves me a lot of effort / time debugging and digging.
@deanroddey2881
@deanroddey2881 2 жыл бұрын
@@alexanderrowe1042 I would never argue that C++ is SAFE of course. I've spent my life writing a huge amount of C++, so I know that isn't the case. It CAN be safe but it is of course on the writer to do so, and most writers are going to take the easier route in a lot of cases. My own C++ code base, which is 1M+ lines, is as good as it gets, because it was written in as close to optimal conditions as possible. Hardly any serious code base even comes close to enjoying those kinds of circumstances, and that's were C++ gets particularly dangerous. In my case, it's all one writer, and everything is uber-consistent, and nothing was ever hacked into place. In that kind of situation, C++ is awfully nice. And it helps that I don't use the STL, or any other third party code, I have built my own entire world, so it's more like working in C# or Java in a lot of ways, in the sense of being built as a completely unified system from the ground up with a comprehensive runtime library that is all designed to work together.
@bimsherwood7006
@bimsherwood7006 2 жыл бұрын
Is it just me, or is the Scala form the most readable? The briefer the function gets, the harder it is for me to read. Even when I know haskell and not Scala.
@bimsherwood7006
@bimsherwood7006 2 жыл бұрын
Yeah, after thinking about it, I'd use the haskell Let expression to name the lists, just like how you explained the algorithm at the start.
@alexanderhurst1998
@alexanderhurst1998 2 жыл бұрын
I don't know why we are caring so much about how concise the function can get by adding more symbols. Like he mentions how you might not want to spell flip and use parentheses yet the APL solution has symbols that I have no idea how to type. Typing flip() is easier and it's plain English so it's easier for me to read.
@RaukGorth
@RaukGorth 2 жыл бұрын
Yes very. Like when I read "tail" the first thought is "oh, this is going to remove the first element!"
@hoggmann7217
@hoggmann7217 2 жыл бұрын
Haskell was the most readable for me. Scala looked bloated. People that know math tend to go towards concise solutions and languages because symbols make it shorter to write and read. Once you know what the symbol means it's tedious to grok more and more expanded versions of it. That said I'd rather read the Scala than the Python.
@monad_tcp
@monad_tcp 2 жыл бұрын
Its not, F# and Ocaml are better. Actually APL is more readable after you learn the symbols.
@fsharpdev
@fsharpdev Жыл бұрын
IMO dev teams are diverse and code ideally should be readable for everyone. I personally liked Scala and Haskell solutions (although I need to learn combinators to fully understand it, so I'll watch your videos about it). What's nice about this F# solution is that it's clear, concise, and can be run step by step interactively in REPL to see the transformations: let maximumDifference nums = nums |> Seq.scan min System.Int32.MaxValue |> Seq.tail |> Seq.zip nums |> Seq.map (( Seq.filter (() 0) |> Seq.fold max -1
@laughingvampire7555
@laughingvampire7555 Жыл бұрын
APL is also functional programming, the main difference is that arrays are the main data structure while in Lisp the Single Linked List is the main data structure.
@c4tubo
@c4tubo 2 жыл бұрын
APL was the very first programming language that I learned at the age of 8, taught to me by deaf friends. The next was BASIC. Imagine that!
@RedHair651
@RedHair651 7 ай бұрын
Galaxy brain
@zachb1706
@zachb1706 2 жыл бұрын
I was shocked when I first saw the APL version of the gave of life, a game that took me ~100 lines to code in python written in a single line
@gigabek
@gigabek 2 жыл бұрын
Combinatory logic gameplay: Combinatory logic lore: "Somebody I Used To Know remix played over this accelerated video" Thanks for this video, quite interesting introduction to combinatory logic and array programming.
@laurenpinschannels
@laurenpinschannels 2 жыл бұрын
this sounds interesting, tell me more...
@voxelfusion9894
@voxelfusion9894 2 жыл бұрын
One one hand I'm awed at the deep mathematics on display, on the other hand I want to never use it myself. All of these highly formal functional languages are so ridiculously complex and unmaintainable, I can't imagine anyone using them in a serious setting.
@15shekels
@15shekels 2 жыл бұрын
I figured the same. Coming from a python background I cant live without intuitive programming design that kinda makes comments not necessary In the grand scheme of things, all thats important to me is: *can i read it off the bat and come back to it later and remember what this function does and what created that call back?" *is it efficient? Ironically having said this youd probably laugh at me since i mentioned efficient and python in the same comment but i digress, something like python with a little more control over variable instantiation would be nice.
@leftaroundabout
@leftaroundabout 2 жыл бұрын
You may well find Haskell complex, but it's certainly not _unmaintainable_ - in fact, IMO the biggest advantage of Haskell is that its strong type system makes it almost impossible to break code that's worked before, without the compiler detecting the problem. Thus one can confidently change APIs without the risk that some dependency then ends up with bugs in production. And ultra-compact, point-free code is actually rather frowned upon in the Haskell community. This video strongly overstates the similarities in practice to APL.
@pspicer777
@pspicer777 2 жыл бұрын
My moment has finally come! _I used APL before you were a glint in your father's eye_ . 👍. Great video. Enjoy the journey it's everything.
@BeansEnjoyer911
@BeansEnjoyer911 2 жыл бұрын
In my opinion, in imperative languages, branching into loops and conditional blocks really benefit from braces. I agree they add noise, but I feel like it helps sort out what the blocks of code are doing. Which is a main reason I find python infuriating, it's still imperative, but relies on a lot of tabbing to generate structure, which can get annoying to read in large parsing sections of code. For context Haskell is my favorite language, with C# being my professional language
@rikschaaf
@rikschaaf 2 жыл бұрын
Imperative programming is like a recipe. You follow the steps and out comes the result at the end. Functional programming is like an assembly line for your data, where each step computes, recombinates or combines the data, to get to the endproduct. I feel that the recipes of imperative programming are easiest to read and follow, because you can easily digest it step by step and see the intermediate results. If you do simple things like map, filter and reduce and an occasional zip, functional programming can still be very readable for most programmers, but it becomes way more complex once you start using the combinators. And I don't mean that those can't be understood. I mean if you can see at a glance what it does without too much effort, which helps maintainability.
@utof
@utof Жыл бұрын
Well as everything i think one becomes good at doing a thing with practice. After some time u probably will be able to quickly think, read and type with combinators, but the problems arise as soon as you need to show it to someone. Pretty high chance it will take quiiite some time to understand. If it was a thing taught in schools/uni, then probably there would be no problems
@curlyfryactual
@curlyfryactual Жыл бұрын
​@@utof the beauty of industry: you will need to show it to someone as you cannot maintain code forever, and your boss will not pay for that person to sit around learning a new way to think.
@srijanpaul
@srijanpaul 2 жыл бұрын
Great talk as always. The slides were much smoother this time around, loved it.
@ivanivanovich4778
@ivanivanovich4778 2 жыл бұрын
How does changing variable names from clear words to random meaningless syllables make the code more readable
@RaukGorth
@RaukGorth 2 жыл бұрын
It doesnt
@joaquinbarrientoscr
@joaquinbarrientoscr 2 жыл бұрын
Wow, just amazing! You are just the programming channel I was looking for. Thanks for your content, keep it up! Cheers!
@philiphanhurst2655
@philiphanhurst2655 2 жыл бұрын
I think APL deserves a prize for being more esoteric than assembly.
@henriquefinger935
@henriquefinger935 2 жыл бұрын
Assembly isn't esoteric at all.
@charlesthompson9395
@charlesthompson9395 2 жыл бұрын
Assembly is at least remotely useful when it comes to retro games
@FaranAiki
@FaranAiki 2 жыл бұрын
@Charles Thompson, and APL is OP at array manipulating. APL is not esoteric at all, it serves a cool purpose, not like "Brainfsck".
@chouaibsam4381
@chouaibsam4381 2 жыл бұрын
I had a headache
@batner
@batner 2 жыл бұрын
Why you consider asm esoteric?
@deudaux
@deudaux 7 ай бұрын
Just the first video I watched on this channel, and looking at other videos... this is probably the best channel I found over the last ~10 years
@ssfrr
@ssfrr 2 жыл бұрын
it's worth noting that the problem being solved has a real-world interpretation: If the numbers are a time series of prices (like daily prices for a stock), this gives the maximum profit you could make if you bought and sold at the optimal times (assuming you can't short-sell). So if you are evaluating some trading algorithm this gives the upper bound on performance. This is also solved in one of the "Q for mortals" videos.
@ravimaithreyregulagedda2158
@ravimaithreyregulagedda2158 2 жыл бұрын
Man I really really loved this video. You convinced me to look into combinatory logic. I'm gonna check out To Mock a Mockingbird. Thanks for the great video!
@cristian-si1gb
@cristian-si1gb 2 жыл бұрын
This is going to be a good one, I can feel it
@echoptic775
@echoptic775 2 жыл бұрын
Was it?
@LyricWulf
@LyricWulf 2 жыл бұрын
@@echoptic775 I think they are still recovering from the digression
@markwvh
@markwvh 2 жыл бұрын
Your strategy is overly complex, no? maxDiff :: [Int] -> Int maxDiff = snd $ foldl' go (maxBound, -1) where go (lo, diff) x = (min lo n, max diff (x - lo))
@henriquefinger935
@henriquefinger935 2 жыл бұрын
I'm a Haskell beginner, this was my solution: maxDiff [] = -1 maxDiff (a:as) = mD as a mD [] _ = -1 mD (a:as) m = if a > m then max (a-m) (mD as m) else mD as a
@KR-uc9ei
@KR-uc9ei 2 жыл бұрын
clojure solution: (defn maximum-difference [nums] (->> nums (reductions min) (map - nums) (filter pos-int?) (cons -1) (apply max))) i like it better than the skala solution and clojures map fn forgoes the need to zip, which is always nice. But point free solutions like these tend to fall apart when you don't have a consistent placement for argument (notice my use of cons instead of conj). But that can happen in haskell and apl too, if it werent for combinators to save the day. clojure just solves this with more macros which has it's own tradeoffs.
@casperes0912
@casperes0912 Жыл бұрын
What people like this guy often forget, is that code is read a lot more than it's written
@user-sv7fo4ps3k
@user-sv7fo4ps3k 10 ай бұрын
I assume to people who live in APL, it's very readable. Those ten people can probably read this immediately.
@lpi3
@lpi3 6 ай бұрын
From my experience it's not true.
@0LoneTech
@0LoneTech 5 ай бұрын
It's often very fast to get the gist of an expression, but a little slower for me to confirm the exact workings of the chain. In comparison, C syntax is very noisy with redundant terminators, separators, names etc. Haskell is a fairly sweet spot, but forking of data often involves some awkward back and forth parsing.
@user-tx4wj7qk4t
@user-tx4wj7qk4t 3 ай бұрын
Do you say that when you see Chinese and tell them they need to rewrite their language so people who don't speak Chinese can read it?
@garklein8089
@garklein8089 2 жыл бұрын
The parentheses aren't even needed in the APL solution, making a cool looking function with the max reduce at one side and the min scan at the other
@code_report
@code_report 2 жыл бұрын
Sigh :facepalm: I definitely should have noticed that
@harshrathod50
@harshrathod50 2 жыл бұрын
This is the first time I came to know of combinators. Interesting.
@Nellak2011
@Nellak2011 2 жыл бұрын
I'm pretty sure APL was developed by our alien overlords.
@cranknlesdesires
@cranknlesdesires 2 жыл бұрын
Nah, Ken just wanted a version of maths that made sense, like why does summing everything have its own symbol but subbing everything doesn't? Why does min and max have no symbol even though we use often? Why do we need to remember Bedmas/Pedmas, what about if a expression has a Sigma, when do I do that? So Ken made something more consistent, with more symbols and less rules, and it was found that it can be made a programing language easily enough.
@0dWHOHWb0
@0dWHOHWb0 2 жыл бұрын
How do you even produce those characters on your keyboard? Is typing a function call really so taxing that reducing it to a single character is the difference maker? I don't understand how this kind of language can be easier to read/write or reason about.
@ravimaithreyregulagedda2158
@ravimaithreyregulagedda2158 2 жыл бұрын
I think you missed the point. The guy is talking about why he thinks a certain language is amazing in his opinion. He thinks that way because he loves the math and all behind combinatory logic. I agree with you that it might not be practical, but the guy thinks it's cool and he likes the concept and loves that an existing langauge has all this combinatory logic in it. That's why he made this video. At least that's how I understood the video anyway ¯\_(ツ)_/¯
@0dWHOHWb0
@0dWHOHWb0 2 жыл бұрын
@@ravimaithreyregulagedda2158 It's possible, yeah. We're left to guess at the motivations of the author since they weren't clearly stated.
@stevemcgrath4040
@stevemcgrath4040 2 жыл бұрын
@@0dWHOHWb0 Back in the days when APL was cool, you had special keyboards and unique encodings (well before Unicode). So you probably just use a custom keyboard mapping. I don’t remember the count, but there aren’t that many glyphs in APL. Conceptually, it’s most like the broad use of symbols in mathematics in general; you’re writing a mathematical expression, not a story.
@orkhepaj
@orkhepaj 2 жыл бұрын
hipster lang , they dont use this for anything
@jamieg2427
@jamieg2427 2 жыл бұрын
it's not that difficult to have certain key presses produce other characters. vim, for example, makes setting up this type of scheme pretty trivial, but it can be done at a system level very easily on linux and windows. also, J, made in the 90s by the creator of APL, uses ascii characters, so fear not. (:
@allenmaudiln
@allenmaudiln 2 жыл бұрын
I love your podcast! I didn’t realise this was your channel.
@jms019
@jms019 2 жыл бұрын
Thank you. I finally get what combinators are _for_ not having seen it explained in a way I have understood as an engineer until now.
@codebitcookie8053
@codebitcookie8053 2 жыл бұрын
Oooooh a very interesting comparison! Love your channel
@andreiiaz2097
@andreiiaz2097 2 жыл бұрын
I can't wait to see this showdown. 😁 Thanks in advance for making this!
@monad_tcp
@monad_tcp 2 жыл бұрын
I love APL . It helped me so much with Linear Algebra and Calculus.
@Baterodalo
@Baterodalo 2 жыл бұрын
APL is the Doctors handwright of programing
@alexxx4434
@alexxx4434 2 жыл бұрын
Such a great presentation!
@lesfreresdelaquote1176
@lesfreresdelaquote1176 2 жыл бұрын
Thank you, this is the first time I have a good idea of what the S Combinator is all about... Sharing the same argument again, without being forced to mention it twice... Neat...
@red13emerald
@red13emerald 2 жыл бұрын
7:40 100% disagree. Even though I knew what the variables were originally, I got immediately confused by these short variable names. It’s maybe to do with parsing mathematical formulas, which I am super bad at, but I feel like 1-3 word variables are much more readable than 1-3 letter variables. Except for i in a loop, but even there, index, position or location may be more appropriate depending on what you’re actually iterating over.
@saltrocklamp199
@saltrocklamp199 2 жыл бұрын
I have a lot of experience parsing math formulas and I still think the short variable names are worse!
@31redorange08
@31redorange08 2 жыл бұрын
Wasn't this whole video a joke?
@red13emerald
@red13emerald 2 жыл бұрын
@@31redorange08 I… don’t know. Maybe? I guess, yeah, when you think about it like that, it makes sense, but I can also see how people do find beauty in pure languages like this. I just thought that it wasn’t for me?
@RajeshPandianM
@RajeshPandianM 2 жыл бұрын
I wanted to ask this in the last video. Did you create a logo for APL? If so, this looks cool! 😁😁
@walrustrent2001
@walrustrent2001 Жыл бұрын
I think the very idea that only collections (aka arrays) of things should exist is brilliant, kudos to APL to introduce that.
@jtetrfs5367
@jtetrfs5367 2 жыл бұрын
Excellent production!
@oraqlle
@oraqlle 2 жыл бұрын
What's your thoughts on the C++ standard trying to becoming more expressive like the inclusion of the ranges-v3 and I've seen a proposal for C++23 for a new composition operator for I think regular (imperative) functions as well as the range, view and lambda functions. I believe the proposed operator was operator |> (x, f(y)) where f is a function and y is its input and x is a value or function that is passed to f through y. I was curious on your thoughts. Awesome video though.
@vivekkaushik9508
@vivekkaushik9508 2 жыл бұрын
I hardly understand 5% of what's going on here but I feel amazed and quite smart after watching these vids. LMFAO. Seriously the world of computing is mind blowing. The so called "developers" like me don't even know 1% on what goes behind the scenes when we call an in-built function or use any tooling like Git or SDKs etc. Thanks mate for keep making these vids. Hope you're keeping backups we don't know when WW3 ends everything.
@MultiJaxk
@MultiJaxk 2 жыл бұрын
What's your opinion on J programming Language vs APL? honestly I've been giving both a bit of review, and seem to like J language more. What would you say - which one is "more powerful", if you could/can compare them?
@taylors1545
@taylors1545 2 жыл бұрын
Anyone ever open a door out of curiosity and instantly regret it? Time for another mug of coffee...
@ShadyE
@ShadyE 2 жыл бұрын
I wonder if Clojure's macros can be used to introduce combinators 🤔
@henriquefinger935
@henriquefinger935 2 жыл бұрын
Before the functional language section I tried to solve the problem with Haskell myself. What surprised me is that my solution was completely different from yours. I only used recursion and ifs, no fancy functions like scan, map, filter, reduce and combinators, but my code is still O(n). It made me wonder which is faster for larger input arrays, I might check it out later.
@guptadagger896
@guptadagger896 Жыл бұрын
Scan was new to me, but map and folds should be very standard haskell toolset
@amj864
@amj864 2 жыл бұрын
Would you do a Julia over view? It looks like a jack of all trades and master of few.
@imadetheuniverse4fun
@imadetheuniverse4fun 2 жыл бұрын
What are the pros and cons of writing the algorithm in one paradigm vs the other? For example the pros and cons of the Haskel implementation vs the Python one? For context, Python is my main language but I'm kind of interesting in learning Haskel.
@joaoholanda3021
@joaoholanda3021 2 ай бұрын
Honestly I am far from understanding it but congratulations for the great presentation and thank you for taking the time to explain it. There's a lot I still have to learn tô fully appreciate it.
@wowzers1237____
@wowzers1237____ 2 жыл бұрын
If BQN also had all the type theory stuff Haskell does, I'd be sold. Without it, although the glyph notation is cool, it's just a limited version of Haskell not worth learning (imo) - just learn Haskell at that point. Or I guess I can ask: Other than the fact that it's more succinct on account of the glyphs, what does BQN offer that Haskell doesn't?
@0LoneTech
@0LoneTech 5 ай бұрын
It's not just the glyphs, but also the syntax and chosen data types and polymorphisms. For instance, CBQN will happily build byte arrays rather than Double arrays to improve memory access patterns, simply because the data fits. When they advertise context free syntax (really, only local context), it's to assist both human and automatic readers. It really isn't a version of Haskell. If anything, it's a version of APL, and the array oriented programming is a useful paradigm to learn, which you could translate to some degree into Haskell Massiv. It does bug me that people keep comparing Haskell lists to arrays. There are arrays even in standard Haskell (Data.Array), though not in base.
@robertpeszek6892
@robertpeszek6892 2 жыл бұрын
Very nice presentation!
@pauhull
@pauhull 2 жыл бұрын
imagine you have to check a pull request and see this: 20:12
@mlliarm
@mlliarm 2 жыл бұрын
Smullyan's bird book will arrive most likely on 2021-12-18. I'd ordered it well before I saw this video. I'm happy to see that you recommend it too :D!
@carstenrasmussen1159
@carstenrasmussen1159 2 жыл бұрын
I like your run through. Very good example and good work. Personally I like languages which are multi paradime. I our team we use D and try get my colleagues to use other part of the D language. Specially the OOP or OOOP (Over Object Oriented Programing)
@HOWTO-sf6sy
@HOWTO-sf6sy 2 жыл бұрын
Waiting⏳also your sicp course is insane
@otmanm4095
@otmanm4095 2 жыл бұрын
You broke my brain ! Great vidéo ! Subed'
@ninguhosaptot
@ninguhosaptot 2 жыл бұрын
Please could you comment how do you do those smooth text code transtions? Thanks in advance.
@korigamik
@korigamik Жыл бұрын
Your videos are cool! Can I ask what you use to create these amazing slides and animations?
@code_report
@code_report Жыл бұрын
I have a tutorial here: kzbin.info/www/bejne/jJmWqmSbocZgldU
@hebozhe
@hebozhe 16 күн бұрын
Smullyan and Priest write some of the most accessible logic books. I don't study much in this area of logic, but I'd definitely pick through the Smullyan text if I wanted a quick comprehensible dive. Good recommendation.
@HenrikMyrhaug
@HenrikMyrhaug 2 жыл бұрын
About the example problem: I believe it might be faster to store two variables of the highest number and highest difference, and instead of comparing the difference between the min and the current number to the current biggest difference on every single step, we just compare the current number to the highest number. Each time we find a new min, we compare the highest difference to the different between the current max and min, and store the largest of those as the largest difference, then set the min and max to the new min we found. So instead of doing a subtraction for every element in the array, we only do a subtraction each time we find a new minimum. I have no idea how fast variables can be accessed and stored, so I don't know wether the increased number of variables used increases compute times more than the reduction from fewer subtractions.
@GamerMrScorpion
@GamerMrScorpion 2 жыл бұрын
It's too esoteric to me to be honest haha, but it seems really cool to know how to program in a language like this. And I have 2 questions about Array Programming (or APL): 1 - To code in APL you need a specif IDE? because I don't even know if it's possible to type some of the characters that I saw. 2 - And what kind of problems this type of language is target for? like, in which scenario I would choose Array programming instead a normal approach (like C++)?
@deidyomega
@deidyomega 2 жыл бұрын
1) You can do it with plugins + dyalog in vscode. 2) I have zero idea... why you'd ever use it
@mlliarm
@mlliarm 2 жыл бұрын
1) Dyalog APL has a nice built-in REPL with all the character set, and also they have the RIDE IDE which is nice too. 2) In the past APL has been used for teaching maths, and for computational physics. There isn't a hell of a lot of material for the second part, but I can share a 70pg report from the 80s that does some serious physics calculations (Newtonian gravity, Einsteinian gravity, Schrödinger equation, Feynman path integrals) I've found. If you've got a problem that can be modelled using matrices (linear algebra), then APL and J are perfect for it. Also J seems much more equiped and powerful for anything related to mathematics and data. I hope modern APLs will catch up.
@thinker2273
@thinker2273 2 жыл бұрын
So APL is what people refer to as a write-only language
@howuhh8960
@howuhh8960 2 жыл бұрын
This is definitely really cool. But for me there is always a question: how to get things done on such languages? What's the purpose? How difficult it would be to write for example autodiff library on APL? Or train ML model (or GPT-3 for example)? process tabular data from csv? scientific algo, which should be as efficient as possible?
@LittleLily_
@LittleLily_ 2 жыл бұрын
Processing and extracting data from csv's is just about the perfect use for functional and array languages. It excels in things where the input is simple to quantify and the result can be expressed as a series of transformations on that input, so reducing a set of rows and columns into some meaningful value you want to extract from it would look much simpler than an imperative solution.
@DrGreenGiant
@DrGreenGiant 2 жыл бұрын
So what you're saying is that some languages have more useful (for this problem) standard library functions than others. So the comparison is between standard libraries, not languages. Still a valid discussion but you're mixing syntax Vs library
@mbartelsm
@mbartelsm 2 жыл бұрын
While that is true for Haskell vs Scala, it is not true for Haskell vs APL, as both languages have very distinct ways of laying out the code.
@mikivanousek1030
@mikivanousek1030 Жыл бұрын
Did you use Manim to create the slides? It looks great.
@bzboii
@bzboii Жыл бұрын
20:35 Twin Algorithms secret reference (and 21:58) could have sniped his conference talk while he waited to give it in person
@thinker2273
@thinker2273 Жыл бұрын
I am convinced this guy is insane. His main argument for APL and related languages is that... they use less symbols? Like... what? There is no world in which that is a worthwhile argument for or against any language. Being able to express a function in terms of a single obscure unicode character as opposed to four standard ASCII characters is not an inherent benefit. Not to mention the fact that both Haskell and APL have the same issue when it comes to readability and attitude towards newcomers to each respective language - they both have an unbelievably academic and elitist community which favors mathematical names and concepts over more readily understood equivalents. You can express the S-combinator both in terms of an abstract mathematical concept, or in terms of a simple C-like function signature, and I hazard a guess that the C-like function will be a lot more readable and understandable to a lot more individuals. However, I will agree that there are tasks that languages like Haskell and APL excel at, particularly related to data processing.
@tubeincompetence
@tubeincompetence 2 жыл бұрын
Well. This video made me happy to stay with C++ I guess. :D Or I guess I just won't go for APL.
@madsteeez
@madsteeez 2 жыл бұрын
MATLAB: res = max(nums (2:end)-nums(1:end-1)) If all(res
@benjidaniel5595
@benjidaniel5595 2 жыл бұрын
Elegance !== Legibility
@peerhenry
@peerhenry 2 жыл бұрын
The S combinator explained at 17:32 reminds me of functions as monads: you can chain a binary function x onto a unary function y, so in Haskell it would be something like y >>= x. I believe the same is achieved by treating functions as applicatives with x y (solution of this video).
@explosionspin3422
@explosionspin3422 2 жыл бұрын
You probably already treat functions as monads. That's what Reader is. Reader a b is pretty much the same as a -> b, under the hood
@diegofloreschavez8420
@diegofloreschavez8420 2 жыл бұрын
You can do it one-liner in Python like this: def solve(*args: int) -> int: return max(args[min(args):]) - min(args) if min(args) != args[-1] else -1 But I think it would be better if you store "min(args)" first in a variable.
@rjameslower
@rjameslower 2 жыл бұрын
What do you think about GNU APL for a beginner?
@loutragetadk453
@loutragetadk453 2 жыл бұрын
I would like to learn more about this combinatory logic stuff.
@reda29100
@reda29100 2 жыл бұрын
5:00 doesn't it make more sense to assume the max_dif to be n[1]-n[0] if positive, otherwise -1, such that .we increase the difference as we find a larger one, instead of assuming it to be MAX_INT?
@jongeduard
@jongeduard Жыл бұрын
Hi, personally many of these languages are not my cup of tea. APL cannot even be typed on a normal keyboard. But I liked to see what I could do in C# here. I am both able to go the imperative way as well al the functional way which is called LINQ. I had to write the ScanLeft part myself, of which my yield return version turned out to be the nicest, because in that way you still benefit from Linq it's lazy execution efficiency. But the rest was quite easy. For Map you use Select and for Filter you use Where. The nicest thing is that Zip is available as well and it accepts and extra input array as direct input, so that I basically get something simular to that S combinator solution from Haskell, even though the code looks more like the Scala code in the video.
@XetXetable
@XetXetable 2 жыл бұрын
I come from a more Haskelly background and eventually gave up on array based programming because I appreciated different things. I never found point-free programming particularly elegant. It's a more restrictive, less efficient version of interaction combinators (combinators whose abstract syntax is a rooted graph rather than a tree). Ordinary lambda calculus is closer to such things than Curry-style combinators and I don't sympathize with the perspective which sees combinators as more elegant than pure lambda expressions. Without that perspective, there's not a lot to appreciate in the current batch of array based languages. I don't want all my data to be arrays, I would rather all my data be functions. Ordinary combinator calculi give you that at least, but array based languages don't.
@brendanhansknecht4650
@brendanhansknecht4650 2 жыл бұрын
It would be amazing if you did BQN or APL tutorials.
@bjk837
@bjk837 Жыл бұрын
I would love to know how you manage your time. Would love to start doing more outside of work, but I you’re like 10X and I’m struggling
@CostaKazistov
@CostaKazistov 2 жыл бұрын
Audio is distorted again. Reduce input volume by 10-15% to alleviate the issue.
@code_report
@code_report 2 жыл бұрын
Yea, I thought I had done the adjustment prior to recording but apparently something got reset.
@alpers.2123
@alpers.2123 2 жыл бұрын
11:00 Scala code, python equivalent: max(-1,*(n-m for m,n in zip(list(reduce(lambda x,y: x+[min(y,x[-1])], nums, [sys.maxsize]))[1:], nums) if n-m)) 19:30 haskell code, python equivalent (no INT_MAX, yet python doesnt have S combinator, so this is best I can): max(-1,*(n-m for m,n in zip(reduce(lambda x,y: x+[min(y,x[-1])], nums[1:], nums[0:1]), nums) if n-m)) Update: Just saw atrus' comment. here is pythonic way: max(map(sub, nums, accumulate(nums, min))) or -1
@Colaholiker
@Colaholiker 2 жыл бұрын
That is probably what Klingons use to program. Working in the embedded world (C, Assembler) with some tool programming in Python, C# or Java and some "field trips" into web backends in PHP, it really makes me wonder why someone would need or even enjoy that (no offense) and where that is used outside of academic contexts.
@asteriskman
@asteriskman 2 жыл бұрын
"The expressivity of the single glyphs"? oh yea, totally sold me...I'm switching to APL, where do I buy a keyboard with all these expressive symbols?
@user-sv7fo4ps3k
@user-sv7fo4ps3k 10 ай бұрын
This video has convinced me to drop out of my CS degree and just drive an Uber.
@amanbolat
@amanbolat 2 жыл бұрын
So, how to open a file using APL?
@shmendusel
@shmendusel 7 ай бұрын
Are functional and array orthogonal paradigms? Could you theoretically have a programming language that is both functional and array based?
@walrustrent2001
@walrustrent2001 Жыл бұрын
Data-oriented algorithms should use reverse notation so that the reading order matches the application of functions. Elm has really smart notations that lead to easier reading than Haskell, since it provides operators for both function composition and function application in both directions) Namely |> and > and ( zipWith (-) scanl1 min ) |> filter(/= 0) |> foldl max (-1) Of course you loose the pointfree notation but I think it is largely worth it
@0LoneTech
@0LoneTech 3 ай бұрын
What do you mean about losing point free notation? x is the only point in your example, so each operation is written point free. Just change "maxDiff x = x |> " with "maxDiff = " and |> with >>, and you're fully point free. |> is also used in Futhark, and internally in GHC, and is named & in Data.Function. Protolude and Relude both expose & by default.
@rmschindler144
@rmschindler144 7 ай бұрын
Wow, APL and BQN are gorgeous.
@jacoblockwood4034
@jacoblockwood4034 2 ай бұрын
Try them out! They look intimidating but you can learn array programming concepts pretty quickly and get the specifics of each language as you learn. Also try Uiua, which approaches array programming using a stack-based flow (think Forth).
APL vs BQN vs J vs Q vs NumPy vs Julia vs R
42:44
code_report
Рет қаралды 28 М.
The Absolute Best Intro to Monads For Software Engineers
15:12
Studying With Alex
Рет қаралды 582 М.
WHY THROW CHIPS IN THE TRASH?🤪
00:18
JULI_PROETO
Рет қаралды 3,9 МЛН
ELE QUEBROU A TAÇA DE FUTEBOL
00:45
Matheus Kriwat
Рет қаралды 33 МЛН
1 Problem, 24 Programming Languages
19:29
code_report
Рет қаралды 372 М.
The purest coding style, where bugs are near impossible
10:25
Coderized
Рет қаралды 876 М.
Object Oriented Programming vs Functional Programming
18:55
Continuous Delivery
Рет қаралды 745 М.
The Uiua Programming Language Caught Me By Surprise
12:24
Code to the Moon
Рет қаралды 49 М.
APL + Game of Life = ❤️
14:46
code_report
Рет қаралды 34 М.
Dear Functional Bros
16:50
CodeAesthetic
Рет қаралды 454 М.
Why Isn't Functional Programming the Norm? - Richard Feldman
46:09
The Dream Programming Language? Lobster
20:55
Code to the Moon
Рет қаралды 142 М.
Faster than Rust and C++: the PERFECT hash table
33:52
strager
Рет қаралды 514 М.
Iphone or nokia
0:15
rishton vines😇
Рет қаралды 1,2 МЛН
iPhone 15 Unboxing Paper diy
0:57
Cute Fay
Рет қаралды 2,2 МЛН