Let's Talk About Functional Programming

  Рет қаралды 75,947

Tsoding Daily

Tsoding Daily

Күн бұрын

Пікірлер: 122
@Lars-ce4rd
@Lars-ce4rd 8 ай бұрын
tsoding: "Let's see if I remember any OCaml from 8 years ago" *proceeds explaining me all the syntax of OCaml*
@aradarbel4579
@aradarbel4579 3 жыл бұрын
Nice! I've wanted to learn OCaml for a long time now, this is the perfect opportunity to follow along (however slowly) and get some problems solved :D
@_vsnwprintf_s_l
@_vsnwprintf_s_l 3 жыл бұрын
Lisp's main feature is homoiconicity, that being that all code is also data, and therefore lisp has incredibly powerful macros that look just as nice as regular code. I don't know of anything in Python that can achieve anything close to this. The rest of that sentiment was good but I think that's not a good comparison.
@dwightk.schrute8696
@dwightk.schrute8696 3 жыл бұрын
the problem is that "regular code" in Lisp looks like garbage anyway, hard to screw that up even more than it is
@huistelefoon5375
@huistelefoon5375 Жыл бұрын
​@@dwightk.schrute8696what makes you say that?
@dwightk.schrute8696
@dwightk.schrute8696 Жыл бұрын
@@huistelefoon5375 )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) ^^ half of your lisp code
@angelcaru
@angelcaru 10 ай бұрын
(what (makes (you (say (that))))) @@huistelefoon5375
@insertoyouroemail
@insertoyouroemail 7 ай бұрын
@@dwightk.schrute8696 I don't think Lisp code looks like garbage.
@MrPetzold123
@MrPetzold123 Жыл бұрын
You are an exceptionally good teacher, you actually got me to understand tail call optimization 🤩
@jonathanschmider8446
@jonathanschmider8446 3 жыл бұрын
Maybe the weird Clang behaviour is because of undefined behaviour? If the function loops infinitely, it causes integer overflow, which is UB. Since the function always loops infinitely, calling it always invokes UB. In case of UB, the compiler can do whatever it wants, and it decided it wants to print garbage.
@dnkreative
@dnkreative Жыл бұрын
Weird clang behavior is because of they completely lost sense while chasing mythical "optimization". This just shows that compiler produces incorrect program. There are many other cases with it (and probably GCC) which even Linus commented.
@iuppiterzeus9663
@iuppiterzeus9663 Жыл бұрын
not a bad argument
@digitalspecter
@digitalspecter 3 жыл бұрын
Well, yeah, syntax is mostly inconsequential. However, I think with Lisp you're also seeing pretty much the AST which is very handy when writing macros. They can can do whatever manipulations to data/code and spit out code and with Lisp's syntax it's easier to see the structure you're manipulating / trying to achieve. Also Lisp's object model is nicer than Python's (multiple dispatch etc). Also, debugging/modifying a running program is sometimes really nice :) My main objection against Lisp is that it isn't statically typed so the compiler doesn't help me as much as I would like to :)
@ribosomerocker
@ribosomerocker 3 жыл бұрын
Some lisps are statically typed
@digitalspecter
@digitalspecter 3 жыл бұрын
@@ribosomerocker Yup, I meant Common Lisp. I've been following a language called Carp which is quite interesting statically typed compiled language with Rust-inspired memory management.. but it's still quite early in the develpoment.
@apestogetherstrong341
@apestogetherstrong341 Жыл бұрын
Well, static typing would require a static language. Lisp is dynamic. However, with just a few (DECLARE (TYPE ...)) forms, the compiler will not only warn you, but actually refuse to compile when it'll see type conflicts of variables. Common Lisp doesn't lack strict type enforcement, it's just optional.
@insertoyouroemail
@insertoyouroemail Жыл бұрын
When you have the program running, static analysis is not as important. You're running your code and getting instant feedback anyway. But yeah, sometimes types are nice anyway.
@alexanderkhodos
@alexanderkhodos 3 жыл бұрын
This video also captures a good part of explanations and recipes from HtDP, which even more agrees with Tsoding's rant on syntax/semantics
@rodelias9378
@rodelias9378 3 жыл бұрын
Really good one! Thanks a lot and keep doing more stuff like this one please.
@lightningx10
@lightningx10 3 жыл бұрын
Loved Haskell, functional programming truly requires you to think outside of the box
@leo848
@leo848 3 жыл бұрын
Would you think of that as a good thing? I think a language should be as straightforward as possible and not require you to "think outside the box".
@ja31ya
@ja31ya 3 жыл бұрын
@@leo848 I guess it depends if thinking outside the box results in more elegant code, or over-engineering...
@avananana
@avananana 3 жыл бұрын
@@leo848 I'd argue it's a good thing, but it has its downsides, the obvious one being that it's not super straight-forward of what to do of course. But the upsides of it is that it forces you to really know what you're doing, which inevitably leads to better and cleaner code if you take coding seriously. There are so many python libraries and projects out there which's source code is pure nonsense because it's so poorly written that it's not even funny as a joke.
@CaptainWumbo
@CaptainWumbo 3 жыл бұрын
it's very useful for solving certain kinds of problems. For me I found that once you start trying to do optimizations to improve performance, you can find yourself bending over backward. Caching is really hard, for example.
@superscatboy
@superscatboy 2 жыл бұрын
I want to make a C compiler that makes you solve a cryptic riddle before it compiles anything. That way I could advertise C as being a language that makes you think outside the box.
@RicardoValero95
@RicardoValero95 3 жыл бұрын
This man should do APL
@leastexpected3115
@leastexpected3115 3 жыл бұрын
oh, he will love it
@BigBeesNase
@BigBeesNase 3 жыл бұрын
After using APL: This man and its viewers looses their sanity.
@digitalspecter
@digitalspecter 3 жыл бұрын
@@rallokkcaz well, you can use FFI to call C-functions.. (at least BQN can). Shouldn't be too hard to open sockets :)
@stintaa
@stintaa Жыл бұрын
ew apl
@flleaf
@flleaf 2 жыл бұрын
38:20 tsoding is probably on thousands levels of irony
@blackbeard3449
@blackbeard3449 5 ай бұрын
1:24:40 clang is so good it calculated the value of infinity!
@trabelsiadam3149
@trabelsiadam3149 2 жыл бұрын
Need to make a video on how you use the terminal this way 🤤 which multiplexer?.. The hole setup
@demolazer
@demolazer 8 ай бұрын
The best explanation of recursion on the internet.
@markblacket8900
@markblacket8900 2 жыл бұрын
the thing with tuples without parentheses is also applicable to python in some cases, so yeah, basically the same language
@paulzupan3732
@paulzupan3732 Жыл бұрын
An interesting thought about the 'rec' keyword in OCaml and why you need to add it to the beginning of recursive function definitions: I know that in some functional languages, especially Haskell, the compiled binary of the program includes a runtime which is basically just a lambda calculus interpreter. In the lambda calculus, you can't actually bind functions to names, so that means that before you evaluate an expression, every name needs to be replaced with its corresponding definition before evaluation can begin. There arises a problem when you try to do this with a recursive definition, however, since every time you replace the name of the recursive function with its body, you end up with another copy of it which then needs to be replaced again, etc. There is a way to get around it using the Y combinator, but the recursive function needs to take another argument which would stand in for the recursive call in its body. In short, the rec keyword may be syntactic sugar for that process. Just a thought though.
@enderger5308
@enderger5308 2 жыл бұрын
8:30 - The bike shed will be HOT PINK
@alexloktionoff6833
@alexloktionoff6833 Жыл бұрын
By what OCaml is better than Rust? generics, matching, optional... I see only a more weird syntax of OCaml.
@stanle1101
@stanle1101 3 жыл бұрын
Hey nice video, just a note on the stack-pushing behavior of a function call, the first couples of arguments are passed into registers first (regular for int, xmm for float etc.) and if you have extra it'll be pushed onto the stack. In your case I don't think the int x will show up on stack, it'll be passed using the %rcx register :) (the return is given in a register also so no stack space needed) So in the end this recursion will just show up on the stack as a bunch of ret addresses, with optimization as you said I guess it'll just be one single ret on the stack. Actually a lot more efficient isn't it?
@casey206969
@casey206969 Жыл бұрын
Funny thing, fairly recently linux added the option to disable #! or make it a module . So in addition to a system that probably won't boot, your ocamlc programs won't run.
@frechjo
@frechjo 3 жыл бұрын
I found this funny > Complains about people who care about syntax, because it's superficial and not important at all in a language. > Obviously frustrated with the syntactic choices in OCaml for comments, lists and tuples. ;P Who doesn't care at least a little about syntax? It is the interface between the semantics and our reading eyes. It should be as transparent as possible; if you can't avoid thinking about it, it's maybe bad in some way (after you have learned it, of course). A couple things about tail call optimizations (TCO) that were not mentioned in the video: Tail calls can be optimized also across functions, not only in self recursive ones. In f(x)=g(x) the call to g is in tail position, so it can be optimized in the same way (the stack frame for f is not needed when g returns). Another thing is that TCO can be a problem for analyzing a stack trace, something to take into account. It eliminates part of the stack context, so when you are trying to understand a bug (after the fact), you might not know how you effectively got there. BTW, I think mrbotka being a bot is no excuse for it being impolite. Shame on it >:(
@TsodingDaily
@TsodingDaily 3 жыл бұрын
I usually ignore majority of the comments, but your take regarding my position on the syntax was just beyond imagination stupid so I had to answer. > Complains about people who care **ONLY** about syntax I'm not saying that there are no problems with syntaxes. My frustration is the people who keep discussing only syntax despite having way more important problems (a.k.a. bikeshedding).
@frechjo
@frechjo 3 жыл бұрын
@@TsodingDaily Look, I had no bad intentions with my comment. If it reads like I'm trying to make fun or something, I apologize. I think your point about people bike-shedding syntax is sufficiently clear, don't worry (if not from this, at least from other videos for sure). I was just putting together two things that you said, because the *contrast* made it funny (which is probably a matter of perspective).
@TsodingDaily
@TsodingDaily 3 жыл бұрын
@@frechjo Oh, I see! It's hard for me to read the intentions through the text! I'm sorry for my reaction as well. No offense taken either.
@Gornius
@Gornius 3 жыл бұрын
What's this colorscheme? It's beautiful!
@pushqrdx
@pushqrdx 3 жыл бұрын
gruber-darker
@semninrussia
@semninrussia 3 жыл бұрын
@@pushqrdx thank you!
@jpr8124
@jpr8124 3 жыл бұрын
A good soul who would suggest an OCaml solution to problem 99?
@andreffrosa
@andreffrosa 3 ай бұрын
What do you use tmux for? How can it be useful for programming?
@hendrikd2113
@hendrikd2113 3 жыл бұрын
since every list you tested the length functions with was incrementing from 1, the best solution would have been to just reuse the last-element function. Less bloat!
@anilraghu8687
@anilraghu8687 Жыл бұрын
Understood the tail call on first reading .😀😃
@AdamSchelenbergCom
@AdamSchelenbergCom 2 жыл бұрын
Nice clarification on tuples. I was wondering about the semicolon.
@antferdom
@antferdom 3 жыл бұрын
Any thoguths on Coq?
@aucusticguitar8069
@aucusticguitar8069 5 ай бұрын
Some libraries in OCaml utilize the OOP functionality to manage the state of UI widgets. I've used Lamda-term for TUI projects and it is far easier to use their widget classes than defining your own draw functions for each widget especially for interacting with them later. Both work fine though so it's just personal preference. Probably just skill issues on my part tbh
@benjaminscherrey1124
@benjaminscherrey1124 3 жыл бұрын
I can't find the Tsoding discord channel for some reason. Anyone got an invite link?
@AdamWong
@AdamWong 3 жыл бұрын
My best friend works for Jane street and I work @ another one of the market makers. Lemme assure you that you are smart enough to work work at these companies. I think you just don’t want to cause it doesn’t appeal to your creativity 😏
@stas4112
@stas4112 2 жыл бұрын
came looking for this comment, if this guy is "too dumb" to work somewhere we are all fucked haha
@stas4112
@stas4112 2 жыл бұрын
btw, amazing channel!
@AdamWong
@AdamWong 2 жыл бұрын
@@stas4112 thank you!
@Lars-ce4rd
@Lars-ce4rd 8 ай бұрын
Pretty sure he was joking. Just a weird flex
@apestogetherstrong341
@apestogetherstrong341 Жыл бұрын
Baseless claim that Common Lisp has the same semantics as Python.
@9SMTM6
@9SMTM6 3 жыл бұрын
37:30 Yeah, at this point it's clear to me I do not like OCAML. It started to annoy me with the already flipped relation with option, where the type was 'a option and the value Some x, and continued with the traditional parameter definition with Haskell style argument passing, but now this shit with tuples and their types. Dont get me wrong, while it's slightly annoying, I tend not to be a person that dislikes a language when it's just different. But there's different but of equal sense, like the way you pass arguments in HASKELL, and there's nonsensical different. And, at least from what I see, Ocaml chose the nonsensical route. Why would you break the Symmetry between so many elements of the language apparently by purpose? At least at this point I can't see a legitimate reason to do that shit. EDIT: Oh, and I could not agree less with you on your comment about Rust. Rust HAS A REASON to be different. Maybe I'm not fair to Ocaml, I'm open for proper explanations, but I do not see it right now. EDIT 2: Watching on I see I was wrong about the parameter/argument symmetry break. But continuing to watch Ive yet to see a good reason to end statements with TWO semicolons. Also, how could I forget about that, the head :: rest match, when matching just one element uses [x] and empty [].
@csbnikhil
@csbnikhil 3 жыл бұрын
You can match a one element list with x::[]. And I think the two semi colons are because of it supporting Imperative Programming, where you separate the statements by a single semicolon. Yes, there is a single semi colon in OCaml, and has a different meaning than the double semi colon. You don’t actually need the double semi colons in you source. They’re there to just make the interpreter happy, afaik. And the standards discourage the use of them.
@YoTengoUnLCD
@YoTengoUnLCD 3 жыл бұрын
Ugh, the pattern matching you mentioned works exactly like it does in Haskell, which you supposedly like.
@nitair7808
@nitair7808 3 жыл бұрын
Why I was thinking he was talking about Apache Camel :D
@Rene-tu3fc
@Rene-tu3fc 3 жыл бұрын
Golang is fast and newbie friendly! though it doesn't have generics, unnullable pointers and lots of useful modern features. But I think sometimes it's easier to read (and code) 50 lines of if/elses than 10 lines of flatmaps juggling monad transformers and converting between different types
@sindavmi
@sindavmi 3 жыл бұрын
also, converting between different types? I dont think you really wanna do that in languages like haskell
@romankocherezhchenko34
@romankocherezhchenko34 3 жыл бұрын
I dont think so, Golang maybe is fast, but not newbie friendly, i bet
@john.dough.
@john.dough. 3 жыл бұрын
It got generics! (finally)
@vladlu6362
@vladlu6362 2 жыл бұрын
@@john.dough. sorry for the 8th month too late reply, but "generics" in go is an half-assed implementation of Rust's traits in order to get an half-assed generic interface for functions.
@NathanHedglin
@NathanHedglin 2 жыл бұрын
@@vladlu6362 two half asses make a whole ass 😂
@generix1240
@generix1240 2 жыл бұрын
Tsoding : A beginner friendly and fast language doesn't exist. Meanwhile Go :
@marcossidoruk8033
@marcossidoruk8033 3 ай бұрын
Not being very very very very slow doesn't make you fast. Go is not fast.
@Mladjooo
@Mladjooo 2 жыл бұрын
Has anybody else noticed "Porn folder" at the bottom of his edtior xd
@dmitrypetrov6557
@dmitrypetrov6557 3 жыл бұрын
Why are you explicitly specifying types? Why not left that stuff to the compiler?
@ujjawalsinha8968
@ujjawalsinha8968 3 жыл бұрын
Non linear curve of difficulty :)
@-aexc-
@-aexc- 5 ай бұрын
holy shit thank u for rlwrap
@mohnishkumar6847
@mohnishkumar6847 3 жыл бұрын
Name of editor?
@kraftwerk28
@kraftwerk28 3 жыл бұрын
-vscode- Emacs
@ino3809
@ino3809 3 жыл бұрын
Clion
@ea_naseer
@ea_naseer 2 жыл бұрын
vim or neovim
@paulzupan3732
@paulzupan3732 Жыл бұрын
It's emacs
@sukaisnaini1843
@sukaisnaini1843 3 ай бұрын
hmm afaik, .run file in linux also had shebang with byte-code content. cmiiw
@wantharry
@wantharry 3 жыл бұрын
Hey Buddy, please include screen key , will be helpful as you type commands
@berndeckenfels
@berndeckenfels 6 ай бұрын
Unshar does that shebang trick, but I think with base64
@reisaki18
@reisaki18 3 жыл бұрын
APL/DYALOG review
@lhpaoletti
@lhpaoletti 10 ай бұрын
I never know if Alexey messes up the pronunciation of "raise" on purpose or not, and at this point, I'm too afraid to ask XD
@Narblo
@Narblo 3 жыл бұрын
Wait a second. So how old is he???
@pushqrdx
@pushqrdx 3 жыл бұрын
i believe he's 69
@zavier3644
@zavier3644 3 жыл бұрын
Either 23 or 54
@Narblo
@Narblo 3 жыл бұрын
@@pushqrdx Nice
@0ia
@0ia Жыл бұрын
32
@stokedfool
@stokedfool Жыл бұрын
"Common Lisp is straight up Python with s-expressions". hot take
@adicide9070
@adicide9070 10 ай бұрын
ocaml is a beast.
@ammarhoussenbay1844
@ammarhoussenbay1844 3 жыл бұрын
Thank you so much you save my exams. 🙂🙏🙏
@mooncorizer290
@mooncorizer290 7 ай бұрын
Bytecode exists in js
@blt_r
@blt_r 3 жыл бұрын
Can someone explain to me why all of these are basically O(N) solutions of O(1) problems. I get it that optimization is not the main thing here, but if you can do something in constant time why iterate over whole thing? And if performance really doesn't matter at all, why are you trying to make code more performant using tail recursion by sacrificing readability with that function inside a function? Why we can't just do something like this to get last element of the list: match List.length xs with | 0 -> None | n -> Some (List.nth xs (n-1)) knowing lists length and indexing in constant time are very basic things, why someone would even try to solve problems without them?
@TsodingDaily
@TsodingDaily 3 жыл бұрын
But List.nth is also O(n) github.com/ocaml/ocaml/blob/7997b65fdc87909e83f497da866763174699936e/stdlib/list.ml#L37-L43
@blt_r
@blt_r 3 жыл бұрын
@@TsodingDaily oh, so these lists are linked lists. Therefore you can take head and tail so easily. Now that's makes a lot of sense
@caiodavi9829
@caiodavi9829 Жыл бұрын
51:20 i am LOLing 😂😂😂
@simonfarre4907
@simonfarre4907 3 жыл бұрын
She bangs are used by all languages that can produce scripts, interpreted or compiled. Python does it, Kotlin does it, D does it. The she bang is just telling the shell what to run it with.
@patryk_49
@patryk_49 3 жыл бұрын
Here's the algorithm for solving problems with tail recursion: step 1: solve the problem using for loop step 2: transform the for loop into recursive function.
@patryk_49
@patryk_49 3 жыл бұрын
@Mohammed Shahid Tail recursion is when the recursive call is the last instruction of the recursive function.
@monad_tcp
@monad_tcp Жыл бұрын
I have 99 problems but OCaml aint one
@majam1n
@majam1n Жыл бұрын
Ocamlator
@UncleJacki
@UncleJacki 3 жыл бұрын
acm t-shirt!
@neuzen
@neuzen 3 жыл бұрын
стопэ, ты может скалу ещё не уважаешь?
@Pompomatic
@Pompomatic 7 ай бұрын
mrbotka not obviously a bot lmao
@matthijshebly
@matthijshebly 9 ай бұрын
Everyone is pinkt
@anilraghu8687
@anilraghu8687 Жыл бұрын
Now Tsording stopped using fucking, crap etc.
@bursthooverbag10
@bursthooverbag10 Жыл бұрын
99 problems but Haskel aint one
@lanceang795
@lanceang795 3 жыл бұрын
Second
@Colaholiker
@Colaholiker 3 ай бұрын
I just don't get it. I have been programming in C/C++ for close to 20 years, before that in Pascal, Delphi, Java... but I never understood why anyone voluntarily goes through the migrain-inducing ordeal of functional programming. It just seems so far away from anything real-world...To me, it just seems like a totally wrong and unintuitive attempt to solve problems you otherwise wouldn't have.
@Dziaji
@Dziaji 3 жыл бұрын
You did a great job explaining this language. I have never seen it before. Unfortunately, it is the biggest piece of crap I have ever seen. Why would anyone use this when we have the programming masterpiece that is C++ and the high-level, convenient language that is python??
@marcossidoruk8033
@marcossidoruk8033 3 ай бұрын
Calling C++ (the most horrifyingly garbage language ever deviced) a programming masterpiece is wild.
@Dziaji
@Dziaji 3 ай бұрын
@@marcossidoruk8033 you apparently just don't understand modern c++ and are confusing it with C plus classes.
@greob
@greob 3 жыл бұрын
Super interesting once again!
Functional vs Array Programming
30:40
code_report
Рет қаралды 133 М.
Haskell for JavaScript programmers
16:51
Tsoding
Рет қаралды 59 М.
УЛИЧНЫЕ МУЗЫКАНТЫ В СОЧИ 🤘🏻
0:33
РОК ЗАВОД
Рет қаралды 7 МЛН
🎈🎈🎈😲 #tiktok #shorts
0:28
Byungari 병아리언니
Рет қаралды 4,5 МЛН
Война Семей - ВСЕ СЕРИИ, 1 сезон (серии 1-20)
7:40:31
Семейные Сериалы
Рет қаралды 1,6 МЛН
I implemented Goto in OCaml
38:41
Tsoding Daily
Рет қаралды 42 М.
Python laid waste to my C++!
17:18
Sheafification of G
Рет қаралды 160 М.
I regret doing this... (Tsoding Q&A Stream)
1:20:07
Tsoding Daily
Рет қаралды 88 М.
Richard Feldman, "The Functional Purity Inference Plan"
1:25:39
Houston FPUG
Рет қаралды 4,2 М.
The Dome Paradox: A Loophole in Newton's Laws
22:59
Up and Atom
Рет қаралды 431 М.
Paid Zig Stream
3:20:37
Tsoding Daily
Рет қаралды 102 М.
Why Isn't Functional Programming the Norm? - Richard Feldman
46:09
Keynote: Advent of Code, Behind the Scenes - Eric Wastl
46:01
Creating a window - Software from Scratch
1:04:12
Muukid
Рет қаралды 169 М.
The purest coding style, where bugs are near impossible
10:25
Coderized
Рет қаралды 1 МЛН
УЛИЧНЫЕ МУЗЫКАНТЫ В СОЧИ 🤘🏻
0:33
РОК ЗАВОД
Рет қаралды 7 МЛН