You want to learn Haskell. This is why.

  Рет қаралды 113,198

peppidesu

peppidesu

Күн бұрын

If you want to see more of this content, leave a like!
This is an introduction to an upcoming tutorial series about programming in haskell. A lot of people complain about haskell being complicated and unintuitive, and although it definitely has its flaws, it forces you into thinking about code in a entirely different way.
==============================================
Discord server: / discord
Twitch: / peppidesu
Patreon: patreon.com/us...
Fonts used:
- Presentation: Comfortaa, Lexend Deca
- Code: Iosevka SSO7
Color theme: Ayu Mirage
Tools used: MS PowerPoint, Adobe Premiere Pro, Visual Studio Code
#haskell #functionalprogramming #tutorial

Пікірлер: 385
@crr0ww
@crr0ww Жыл бұрын
I'M YOUR BIGGEST FAN, PEPPI! AMAZING WORK
@peppidesu
@peppidesu Жыл бұрын
tysm
@Gh0_-st
@Gh0_-st Жыл бұрын
yo crow! im your biggest fan!!
@mr.leader8413
@mr.leader8413 Жыл бұрын
Ay Yoo🗿
@dogeplayz.
@dogeplayz. Жыл бұрын
im your biggest fan!
@AGENT_V-252
@AGENT_V-252 Жыл бұрын
Yooo boy crow is here!
@RaukGorth
@RaukGorth Жыл бұрын
Yes, "ClosestPoint Point Point Point" makes perfect sense when you read it.
@ShadoFXPerino
@ShadoFXPerino Жыл бұрын
The first one is the name of the function, the second one is the input for the target Point, the third one is an input for the array of points to search through, and the last one is the output Point.
@chaddaifouche536
@chaddaifouche536 Жыл бұрын
If you have a maths background, it does (no need for it to be in-depth, high school should be enough) since "a -> b" is literally how you write the type of a function that goes from set a to set b. So here you have a function that takes a Point and a list of points [Point] and return a Point. The fact it's not written (Point, [Point]) -> Point is more surprising but there's a good reason for that, currified functions are more flexible and the standard way to write functions in Haskell.
@nomoredarts8918
@nomoredarts8918 Жыл бұрын
It has
@kasvith
@kasvith Жыл бұрын
it makes sense
@callyral
@callyral 10 ай бұрын
i'm guessing the first one's the function name, the last one is the output type, and the ones in between are the argument types?
@Soul-Burn
@Soul-Burn Жыл бұрын
Python: def closest_point(points: Iterable[Point], target: Point) -> Point: return min(points, key=lambda p: distance(p, target))
@pranaypallavtripathi2460
@pranaypallavtripathi2460 Жыл бұрын
I was actually going through comments to see if anyone has responded with a short python code or not so that I can. Nice job 👍 sometimes it's important to shut the naysayers
@dalannar
@dalannar Жыл бұрын
'return min(distance(point, target) for point in points)' Is both more intuitive since it doesn't have a lambda expression in there, as well as slightly more performance. At least in my testing environment. Edit: realise it's not returning the point but rather the distance, so the original is actually what you want.
@backfire10z29
@backfire10z29 Жыл бұрын
Assuming target isn’t in points*
@Baile_an_Locha
@Baile_an_Locha Жыл бұрын
Nice. Amazing how similar this Python version is to the C++ version I shared.
@luck3949
@luck3949 Жыл бұрын
I did the same in python before looking at Haskell solution.
@titan5064
@titan5064 Жыл бұрын
I got into FP through ocaml which is well, different, but this point really is solid. It may look daunting at first, but once you learn how to use these languages you'll be able to write some of the prettiest code in your life and that's not an exaggeration, it's like you're coding in cursive
@tenthlegionstudios1343
@tenthlegionstudios1343 Жыл бұрын
Great video. I went on a journey to learn haskell, attempting to learn category theory, monads, etc... I understand most of these concepts shallowly, but the biggest thing that came out of learning haskell was becoming better at FP in other languages. It has helped a lot with Generics, using/writing functors and monads in other languages, and just understanding programming at a deeper level. You learn the value of immutability, and you can see where to use it more clearly. My only warning for those who learn is to not get to wrapped up in category theory and type theory. You can get more practical value without going deep into these. Unless you want to. Then go ahead!
@eslof
@eslof Жыл бұрын
"But if you read it out loud.. " Closest point point point point closest point
@vanshavbhalla6210
@vanshavbhalla6210 Жыл бұрын
You have successfully convinced me to give it a try. Waiting for the series now. Great quality btw!
@peppidesu
@peppidesu Жыл бұрын
Thats great to hear, tysm
@Laeshen
@Laeshen Жыл бұрын
I've been interested in Haskell for a while now but never really felt motivated to learn it. This just inspired me to start trying.
@69k_gold
@69k_gold Жыл бұрын
Haskell programmers will say anything to convince others so they can justify their time spent learning it and regretting
@gobdovan
@gobdovan Жыл бұрын
Good video, but that ternseness you can achieve in Python too. Here's a one-liner: min_value = min(points, key=lambda point: (point.x-target.x)**2 + (point.y-target.y)**2)
@jplayer073
@jplayer073 6 ай бұрын
The point isn't that you can't do it in other languages. It's that it forces you to rethink how to design and implement solutions. Learning Haskell has had a huge impact on how I write Python and Java code.
@gobdovan
@gobdovan 6 ай бұрын
​@@jplayer073yeah, you're right, I just realised I missed the last few seconds of the video where he shows the Python code.
@madghostek3026
@madghostek3026 Жыл бұрын
After learning Haskell, Python is no longer the same, I see functools library and go "ooo shiny", and it is actually faster than hand made loops 🤯
@CaptainWumbo
@CaptainWumbo Жыл бұрын
it means the for loop is implemented as an iterator, which is really slow. Sometimes you can observe similar problems in js where the JIT transforms slow functional code into something faster or can take advantage of a func written in C, but can't make the same assumptions about your for loop. If try the same thing in C the result is very different, for loops are strictly better.
@vaolin1703
@vaolin1703 2 ай бұрын
It‘s slower than comprehensions though.
@madghostek3026
@madghostek3026 2 ай бұрын
@@vaolin1703 Yeah true, when I can do something with comprehension or generator then it will be a better idea
@marcs9451
@marcs9451 Жыл бұрын
One reason I really don't like pure FP is the reluctance to use real iterators and rely too much on recursion, and most of these languages dont even guarantee tail-call optimization. There are plenty of good lessons to be learned from a state minimizing approach such as FP. But the moment your program needs performance or even handle more input without some heavy runtime help, all the functional elegance flies out the window. OSes and even the FP languages compilers/runtimes are procedural imperative for a reason, it's fast, computers are inherently stateful and sequential and no amount of category theory can change the hard reality of the CPU.
@nieczerwony
@nieczerwony Жыл бұрын
It feels weird as vast majority of hardware are in fact imperative, so using imperative programming is more natural. You can learn FP as paradigm sure, but equally good you can also learn programming in logic. This will not change the fact that imperative programming will remain main type for long time.
@vitalyl1327
@vitalyl1327 Жыл бұрын
what pure functional language does not guarantee TCO? I'm not aware of a single one with such a fatal flaw. As for hardware being stateful - do you realise that most of your very stateful imperative code goes through a stage where it's represented as functional, and often, purely functional, when it's compiled with any modern SSA-based compiler?
@ring0744
@ring0744 Жыл бұрын
@@vitalyl1327 And what does that have to do with anything he said? Who cares how the op codes were generated? It doesn't change anything about the actual program, if the compiler follows standards.
@vitalyl1327
@vitalyl1327 Жыл бұрын
@@ring0744 specially for you, I'll explain it again, slowly: SSA is a purely functional representation, as long as geps, loads and stores are eliminated (and they are for a very significant proportion of your typical code, that's what SSA is for, after all). No idea what "opcodes" you're talking about, and why did you think it's even remotely relevant to mention some "standards". Apparently you're very much out of your depth in this discussion. So, again, for you to try to follow the logic: imperative languages are being compiled via a purely functional stage. This fact contradicts the OP claim that purely functional code is somehow alien to the actual hardware and cannot be compiled into an efficient machine code - the truth is quite the opposite, you must first translate your imperative code into functional in order to compile it into a better machine code. Therefore, if you start with functional and skip the initial imperative representation altogether, you're not losing much. Is it easier to follow, or you need even more detailed explanation?
@nieczerwony
@nieczerwony Жыл бұрын
@@vitalyl1327 Doesn't matter what compiler you are talking about. At the end machine code is purely imperative language and all compiler does is just change higher level of abstraction to imperative machine code. In ideal "purely" functional language side effect should not exists. In fact in most higher level languages function are causing side effects (like communication with OS for that sake). Example here would be printf function in C in fact return number of characters "printed", but exact operation of "printing" these characters to screen is in fact side effect. In lower level stuff function are causing a lot of side effects. In assembler practically you have only side effects and there is no other means of performing calculations. Well you have hidden side effects, like modification to processor state flag, but this is still side effect. From hardware perspective computer is imperative. State = memory content and instructions = commands building machine code.
@alxjones
@alxjones Жыл бұрын
You can just learn functional programming in the language that you like, assuming it supports it well enough. Learning Haskell might actually ruin you, because there's a lot of reasons you won't actually use Haskell, but you will miss the type system when you go back to any other language.
@peppidesu
@peppidesu Жыл бұрын
true, but that might also inspire people to come up with approaches to mimic the type system, or even create new languages.
@amigalemming
@amigalemming 3 ай бұрын
@@peppidesu It's crazy that people invent more and more uncommon languages because they find Haskell too uncommon.
@QuotePilgrim
@QuotePilgrim 5 ай бұрын
Bro I have been coding in Python since highschool and it took me a while to understand that example at the end of the video.
@bloom945
@bloom945 Жыл бұрын
Cool. I don't know any Haskell and thought monads seemed intimidating, but really after watching a video by Studying With Alex it wasn't that hard to understand, at least practically. I'm sure it's a nightmare theoretically though. Also as a C# user I want to give my two cents: points.MinBy(point => Distance(point, target))
@manolol1119
@manolol1119 Жыл бұрын
It definitely sounds like an interesting language. I'm really looking forward to the next videos. 😄 Great work!
@GabrielsEpicLifeofGoals
@GabrielsEpicLifeofGoals Жыл бұрын
God bless all that is reading this. Thank you for the explanation!
@S3Kglitches
@S3Kglitches 8 ай бұрын
Haskell is like driving a jet fighter on the road. It's cool and advanced af but its practical usage is low.
@zwanzikahatzel9296
@zwanzikahatzel9296 Жыл бұрын
or just min(map(distance_function, points))
@siavava
@siavava Жыл бұрын
would find the minimum distance (value), not the point that produces that distance.
@RoboDragonJediKnight
@RoboDragonJediKnight Жыл бұрын
I appreciate the FP content. Never used haskell but I use a lot of the functional capabilities provided by ES6+ JS. Great video!
@draakisback
@draakisback Жыл бұрын
I love functional programming but Haskell is such a messy language to me. I do know category theory and I have used dependent types in systems like Idris and Coq (more recently f*). My favorite functional language right now is probably Ocaml, elixir or scheme. Haskell really needs the Scala 3 treatment in my opinion where they clean up some of the conventions. If you look at elm which has a very haskell-like syntax, it's a very clean language but Haskell on the other hand gets very messy because of some of the rules that it has to follow. Scala 3, removed a lot of parentheses and brackets allowing the language to be much more readable. They also added some really cool features to make the language more functional in a lot of contexts.
@cnstntn32
@cnstntn32 Жыл бұрын
Can't wait for the following videos. I'm sure they will get lot of views and subs in the long run.
@greyrabbit2157
@greyrabbit2157 Жыл бұрын
WE GETTING OUT OF THE BOOTCAMP WITH THIS ONE 🔥🔥🔥🔥🔥🔥🔥
@bmehder
@bmehder Жыл бұрын
I hope you launch this series soon. I am looking forward to it.
@adsick_ua
@adsick_ua Жыл бұрын
I'd recommend looking at Julia as well
@peppidesu
@peppidesu Жыл бұрын
I have Julia on my "cool stuff to check out" list!
@neetdemon
@neetdemon Жыл бұрын
Very pleasing to watch. I'm currently learning Zig rn but always down to learn Haskell. Subscribed.
@bdnugget
@bdnugget Жыл бұрын
based zigger
@EightOneGulf
@EightOneGulf Жыл бұрын
If you're using C#, linq is quite powerful with these kind of problems as well. Points.OrderBy(p => Distance(p,target)).First(); This should give you the same result, and in my opinion is very readable as well
@ShadoFXPerino
@ShadoFXPerino Жыл бұрын
.NET 6+ supports MinBy natively, which avoids allocating a new data structure to store off the sorted list.
@EightOneGulf
@EightOneGulf Жыл бұрын
@@ShadoFXPerino nice, thanks. Even better 😁
@null321
@null321 Жыл бұрын
@@EightOneGulf var closestPoint = points.MinBy(p => Distance(p, target));
@sunofabeach9424
@sunofabeach9424 10 ай бұрын
So, after months of coding in Haskell, I can confirm that it have changed my mind. Months ago, I didn't think about Haskell at all and now I think that it fuсking suсks
@coolbrotherf127
@coolbrotherf127 Жыл бұрын
Haskell breaks my brain. I've been programming on OOP languages for over 10 years now and it's very hard to rethink how I fundamentally approach a logical problem.
@douglaswolfen7820
@douglaswolfen7820 Жыл бұрын
I got into Haskell for a little while, and have always meant to come back and learn more. This looks like it could be the start of a really fun series
@vikingthedude
@vikingthedude Жыл бұрын
I will subscribe with the hope that you will upload many videos in the future
@MyriadColorsCM
@MyriadColorsCM Жыл бұрын
I hope you do this series, functional programming feels absolutely alien to me, I tried Ocaml and even though it felt more intuitive than something like Lisp, it was still very weird. Good luck and keep up the good work.
@IqweoR
@IqweoR Жыл бұрын
I want this to become a series. Please, go ahead
@alex.laslau
@alex.laslau Жыл бұрын
Wow this is so cool haha! As a game dev using C# and Unity, Haskell seems pretty scary haha. But maybe I'll give it a shot!
@ShadoFXPerino
@ShadoFXPerino Жыл бұрын
Note the caveat at the beginning dismissing the need for good performance. Functional languages don't have good performance and aren't a good choice for game development. That said, C# is multi-paradigm, and its functional equivalent to the Haskell code would use System.Linq and look something like: (Point target,Point[] rest)=>rest.MinBy(x=>distance(x,target));
@alex.laslau
@alex.laslau Жыл бұрын
@@ShadoFXPerino Wow, thanks for this! But how come functional languages are performing worse than OOP? Isn't the point of OOP to just make coding easier to understand by sorting it in classes and instantiations, but also making it a bit less performant?
@ShadoFXPerino
@ShadoFXPerino Жыл бұрын
​@@alex.laslau Someone could eventually make a pure functional language which has good performance, but the functional paradigm makes a lot of demands of a system. Immutability means you can't directly change data, you can only create a new copy with some things changed. OOP only requires that relevant class data be kept together. C# is multi-paradigm, so it can use whatever paradigm gives it the speed it needs, or the organization it wants.
@Noobificado
@Noobificado Жыл бұрын
Very interested in what is to come. Since I am already a software developer 5 to 9, having good video resorces is great, since i don't have that much time and energy to focus after work.
@RoyaltyInTraining.
@RoyaltyInTraining. 5 ай бұрын
I instantly fell in love with Rust after learning how to write it in a functional-like way. Now I really want to learn more.
@williamragstad
@williamragstad Жыл бұрын
This stuff is gold! I hope you make more vids like this or similar topics!
@peppidesu
@peppidesu Жыл бұрын
tyyyyy
@thelonerat9557
@thelonerat9557 Жыл бұрын
Looks promising, I'm subscribed and waiting for it dude!
@krazyolie
@krazyolie 3 ай бұрын
I learned haskell in first year CS.. Whilst completely impractical it was a good way to look at some things.
@watynecc3309
@watynecc3309 Жыл бұрын
GOATED CHANNEL thanks youtube recommandation
@beaverbuoy3011
@beaverbuoy3011 Жыл бұрын
awesome!
@korigamik
@korigamik Жыл бұрын
This is pretty cool! Can you tell us what you use for these nice animations and graphics?
@peppidesu
@peppidesu Жыл бұрын
it is literally ms powerpoint, no joke
@reycorbie3581
@reycorbie3581 Жыл бұрын
wow! this is amazing! thank you! need more
@daferade
@daferade Жыл бұрын
Computer science student from argentina looking forward to your haskell series!
@daferade
@daferade Жыл бұрын
PLEASE dont give up c:
@RottenFishbone
@RottenFishbone Жыл бұрын
With almost every modern programming language adopting some level of functional programming, this can be achieved in virtually any language pretty easily. That said, I think Haskell is a great language and I have more fun in it over any other. I think a better example would be showcasing pattern matching, specifically coupled with recursion. I found that had a huge impact on how I think about recursive problems as more of a piecewise function rather than what imperative languages construct it as (at least superficially).
@add-iv
@add-iv Жыл бұрын
wiht list comprehensions in python: bestDistance, bestPoint = min((distance(point, target), point) for point in points)
@dedebenui
@dedebenui Жыл бұрын
Yes! The example in the video is awful. Your code is much closer to what I would actually write in python, and it's also probably faster.
@Toleich
@Toleich Жыл бұрын
An experienced programmer can make clean, readable code in any language. Your "straight forward" approach is nearly incomprehensible to someone who doesn't have experience with Haskell. Brevity != simplicity.
@Markyparky56
@Markyparky56 Жыл бұрын
We've been pushing to use more pre-implemented Algo functions in our codebase, even for cases like a for-each with a branch. Ex: Algo::ForEachIf cleanly separates the condition from the operation, rather than double-nested brackets, especially if all the code is in one place rather than broken out into its own functions. Very often we write the same code over and over. Simple operations like finding a matching element in a list, or the minimum/maximum element. These are things we should only need to write once, ever. Still, we're prone to reinventing the wheel for each problem presented. In this case, and as shown, the solution is to use the algorithm Min, and the projection is a distance calculation. The implementation handles the rest and you move on with the result.
@sevangolnazarian7713
@sevangolnazarian7713 2 ай бұрын
This is great but I think it is slightly misleading since you aren't showing the implementation of Point or distance (unless there is a distance function outside of prelude I'm not remembering...)
@legittaco4440
@legittaco4440 Жыл бұрын
It’s not that special. C#. var closestPoint = points.MinBy(point => point.DistanceTo(target)) In fact, that’s a one line and way more understandable than that. All you have done is learned that Haskell has a query language, like C#s LINQ, and assumed that it’s unique. A lot of languages have it.
@peppidesu
@peppidesu Жыл бұрын
That's what makes it so great. A lot of languages have features in common with Haskell. Haskell just forces you into using them, allowing you to recognize more nuanced scenarios where it might be useful.
@Mika_565
@Mika_565 Жыл бұрын
Nice transitions on those slides. very smooth
@peppidesu
@peppidesu Жыл бұрын
thank you!! powerpoint has it built in and it works great for code
@domenicosantone5264
@domenicosantone5264 Жыл бұрын
Great fan, you got my subscription and I'm waiting for the series I hope you'll integrate with howtos in other languages like you did here
@CollCaz-2
@CollCaz-2 Жыл бұрын
you have convinced me to set aside some time and learn haskell
@chrisalexthomas
@chrisalexthomas Жыл бұрын
from the example you gave, I still don't know why I want to write any code in haskell, since you didn't explain why it's better, what it's doing, or how it works. You just showed an example with less lines of code, more noisy syntax, a weird "on" thing, whatever that is, and to be honest, it's not easier to read, there are more syntax elements and grammar to understand. So why exactly is this any example of why I should? It seems like a reason why I shouldn't. The weird "on" syntax makes me wonder, what are you doing with strings here??
@peppidesu
@peppidesu Жыл бұрын
the thing is that you learn to create code with bigger building blocks, dubbed "declarative programming". This is important because: 1. it is faster to write and read 2. you don't have to bother about performance as much, since the building blocks are already highly optimized 3. it tends to clearly present the semantics of your code, as i showed in the example Now, a good imperative approach will always beat a declarative one, but when you are in a rush or the code isn't "that important right now", declarative approaches will perform better than a naive imperative one. Haskell is a language that forces you into this workflow, which makes it a great learning tool for coming up with declarative solutions to problems, which is why i am teaching you this. Edit: I should've made the introduction a bit more fleshed out, I noticed I got a lot of comments like yours. Thanks for giving me some constructive feedback unlike the others though!
@chrisalexthomas
@chrisalexthomas Жыл бұрын
@@peppidesu I've tried to learn haskell a few times but I keep failing cause the syntax is too unfamiliar and it's too weird to think how a full project would work. So I keep failing. Thats how I ended up on your video. Keep pushing out the videos though, they're not junk, they obviously has value. One day, I'll come across the "a-ha!" video. Until then, thanks for the well thought out response
@nightlockhayze
@nightlockhayze Жыл бұрын
Peppi!!!
@peppidesu
@peppidesu Жыл бұрын
ahahaha hiii
@ChamberOfTimeLover
@ChamberOfTimeLover Жыл бұрын
based Wandersong fan, looking forward to those tutorials.
@256k_
@256k_ Жыл бұрын
loking forward to this series and hearing your arguments
@alexanderoransky7601
@alexanderoransky7601 Жыл бұрын
The video convinced me to learn functional programming utilities in Python!
@TheViperZed
@TheViperZed Жыл бұрын
Oh nice, haskell has iterators and map. just get itertools and you can do it in a single line in python essentially the same, and then you don't have to bother with all the noise Haskell throws at you. Strong typing is great but haskell is really most interesting if you need the extreme adjacency to formal mathematics that haskell sprung up from, which is a good deal still removed from the functional programming paradigm.
@somniad
@somniad Жыл бұрын
eh, minimumBy is a bit on the specific side, and pointfree notation almost feels like cheating because of how confusing it can be closest p ps = min $ (dist p) ps I haven't written haskell in a while but this seems basically fine - curry dist with the target point and map the resulting function over all of the test points, and take the minimum of that; not QUITE as readable, but still pretty much fine imo I learned Haskell while I was still in school, and it was an extremely valuable experience for me. I still write procedural code whenever something is straightforward, but when it's time to get weird and abstract, functions and even higher-order functions are one of my go-to tools for expressing such ideas. Today I write code mainly in C++ for work, and while surely I'd mostly write code more like the first example, you could always more or less translate it to c++ std::pair closest(std::pair point, std::vector points) { return std::min_element(std::transform(points.begin(), points.end(), [&point](std::pair cmpPoint){ return distance(point, cmpPoint); })); } Okay, I admit. Not all languages are made equal.
@TRex266
@TRex266 Жыл бұрын
Nesting transform and min_element line this won't even compile
@somniad
@somniad Жыл бұрын
@@TRex266 I just put together the idea, I didn't bother checking it with a compiler lol
@TRex266
@TRex266 Жыл бұрын
@@somniad yeah it just proves the point how awkward functional programming in C++ can be oftentimes
@somniad
@somniad Жыл бұрын
​@@TRex266 yeah, even the functional stuff in C++ is really not made for composability lol which is fair, given what C++ is, but still - it can be awkward
@Grom1477
@Grom1477 Жыл бұрын
That's hilarious!
@nelsonjanusson7278
@nelsonjanusson7278 3 ай бұрын
damn..... even the title is declarative.
@nicksmith9521
@nicksmith9521 Жыл бұрын
I think the Python code could be just as succinct: idx = min(enumerate(points), key=lambda p: distance(p[1], target))[0] return points[idx]
@Soul-Burn
@Soul-Burn Жыл бұрын
return min(points, key=lambda p: distance(p, target))
@helck1153
@helck1153 Жыл бұрын
I don't know if writing less is the point as much as easily reading what the code is doing
@peppidesu
@peppidesu Жыл бұрын
i showed that at the end of the video, but great to see you already knew thats a thing!
@nicksmith9521
@nicksmith9521 Жыл бұрын
@@helck1153 I'd argue that @Soul-Burn's solution is easier to read than the haskell solution. The haskell version that was proposed requires knowledge of `minimumBy` and `on` and how they can be composed together to provide a solution.
@px64
@px64 Жыл бұрын
Wishing all the best in your KZbin journey. Great video
@xkcdapostle
@xkcdapostle Ай бұрын
Monads aren't a nightmare, they are dreams wrapped by nightmares. Side effects include... Terror.
@ThePowerRanger
@ThePowerRanger Жыл бұрын
Looking forward to the series.
@abrarmasumabir3809
@abrarmasumabir3809 Жыл бұрын
Okay, then I'll learn it from you. please make the series epic.
@Poke52380
@Poke52380 11 ай бұрын
This is not a good example. You can write this in literally any language you can think of, including C. You just hid the "complexity" inside of the minimumBy function. Haskell gives us this function instead us writing it ourselves, big woop.
@larjasoul
@larjasoul 2 ай бұрын
Do you really like the idea of your coworker's "minimumBy" implementation? Haskell gives us a dictionary's worth of well-made, standardized shorthand. Surely I can say "6 string instrument tuned EADGBE (usually) originating from 19th century Spain", but if we all know the word "guitar", I can save my fingers and avoid the risk of inaccurate description.
@zeez7777
@zeez7777 Жыл бұрын
The problem is that while the code is extremely elegant its also not fast. Clean code can be an alluring trap and you easily end up overdoing it which functional programming inherently does by stuff being immutable. Don't get me wrong functional programming is beautiful but that beauty has a price and it makes it simply not practical for USEFUL real-world software. If you want to broaden your horizon and get a new perspective on problems, sure learn functional programming. But i wouldn't recommend becoming one of those people who try do force everything into a functional programming way. If you ever hear people who parrot that performance doesn't matter they are usually the ones sitting on some high level language which is getting hard carried by C/C++ in one way or another which is written by really smart software engineers who have written the most performant code they could. Guess what, they didn't use functional principles because its simply not viable. It's really hard to find someone that built a real application that really DOES something and not just some snippets or tiny toy projects in a purely functional way and it not be a performance disaster. Immutability is your biggest enemy regarding performance and you'll have to decide whether you're willing to trade decades of hardware advancements for being "safer" and "it being harder to create bugs" and ultimately your code looking beautiful. That trade is simply not worth it in a professional environment.
@vikingthedude
@vikingthedude Жыл бұрын
There are optimisations in place that make this paradigm performant: lazy evaluation, transducers, copy-on-write, parallelisation, etc. Many of these optimisations are given to you for free due to immutability. Not to mention other benefits such as thread-safety and having concurrent code that is simple to reason about. So your comment is ignorant. The reasons for real-world speed are not due to the paradigm, but due to the implementation. Look at rust for example
@zeez7777
@zeez7777 Жыл бұрын
​@@vikingthedude Are you really arguing that immutability wins over in-place/reference in terms of performance because of some basic optimization techniques? You are paying for thread safety and easy to reason about concurrency. By your logic you have the best of both worlds which does not reflect reality and I'll gladly wait for you to name any useful real world applications written in Haskell.
@ShadoFXPerino
@ShadoFXPerino Жыл бұрын
@@vikingthedude Rust has controlled mutuability, which gives it the benefits of performance of mutability along with the safety of immutability. If you tried to write Rust exclusively with true immutability then under the right workload it would run slower than Javascript.
@vitalyl1327
@vitalyl1327 Жыл бұрын
In a world where people do practical things in an insanely slow Python, criticising Haskell and pure FP for a somewhat lower performance than the maximum you can achieve on the current hardware is somewhat uncalled for. It's still order of magnitude faster than Python, how is it "not practical for useful real-world sofware" then?
@vitalyl1327
@vitalyl1327 Жыл бұрын
@@zeez7777 there's a lot of cases where copying is more performant than replacing in place - given that compying also does compactification. Think of compilers, for example - there's no point in replacing your IR in place as you may need to roll back your changes and apply some other heuristics.
@hartree.y
@hartree.y Жыл бұрын
"persuade" is the word you were looking for
@mumk
@mumk Жыл бұрын
I subscribed for the series, looking forward to that!
@HiImKyle
@HiImKyle Жыл бұрын
I still don't want to learn Haskell, mostly because I can't see a use case in anything I do that would warrant learning it but I'd like to see the same syntax be more widespread
@adryelbarros3250
@adryelbarros3250 5 ай бұрын
def closest(target, points, dist): distances = ((dist(target, p), p) for p in points) _, closest_point = min(distances, key=lambda i: i[0]) return closest_point
@adryelbarros3250
@adryelbarros3250 5 ай бұрын
Ok, I could've used the dist directly in the min function
@maciejkarczewski9475
@maciejkarczewski9475 Жыл бұрын
Nice work. I can't wait for the next one.
@smaza2
@smaza2 Жыл бұрын
goddamn that last python snippet was beautiful
@TimJSwan
@TimJSwan Жыл бұрын
I would expect that most people don't grasp the depth of the calculus of constructions ability to normalize all possible expressions behind this language which is only a subset of that.
@Metruzanca
@Metruzanca Жыл бұрын
Great work!
@cocoabutter5888
@cocoabutter5888 Жыл бұрын
Wandersong!!!!!!!!!!! ❤❤ Also functional programming!! ❤ (I'm coming from Julia which is functional adjacent at leasr imo)
@p1geon45
@p1geon45 Жыл бұрын
min([dist(target, p) for p in points]) is even shorter and more understandable
@agustinrusso5752
@agustinrusso5752 Жыл бұрын
I'm a data science student from argentina and please i need this!!!
@IvanYugov
@IvanYugov Жыл бұрын
However, the Haskell code leaves questions about the definitions of "compare" and "minimumBy". If the program requires so many prerequisites, pre-written functions, it's no better than procedural code in Python or C++. Someone still has to write all those functions.
@peppidesu
@peppidesu Жыл бұрын
yes, but that misses the point i am trying to make. Writing code that performs well takes a lot of time, but if you can recognize high-level patterns to build your code from pre-existing building blocks, you can write code that gets you in the same ballpark when it comes to performance. minimum and compare are operations that are so common, people have already done the implementation and optimization work there, so you don't need to do that.
@CarrieForle
@CarrieForle Жыл бұрын
You make me, who knows nothing about Haskell, interested in this mystery language in just 3 minutes flat. I'm looking forward to the series!
@ficolas2
@ficolas2 Жыл бұрын
Arrays.stream(points) .min((p1, p2) -> Double.compare(p1.distance(referencePoint), p2.distance(referencePoint))); Thankfuly modern programming languages have lambda expressions, so you can do functional things without actually using a functional programming language.
@sadkebab
@sadkebab Жыл бұрын
Looking forward for this
@airatvaliullin8420
@airatvaliullin8420 Жыл бұрын
How about return min(points, key=lambda x: distance(target, x)) ? edit: apparently, some lad wrote the same thing :)
@Baile_an_Locha
@Baile_an_Locha Жыл бұрын
In C++17, I would do this: Point& closestPoint = *std::min_element( points.begin(), points.end(), [&target](Point& lhs, Point& rhs) { return distance(target, lhs) < distance(target, rhs); });
@user-tk2jy8xr8b
@user-tk2jy8xr8b Жыл бұрын
wow, that's impressively lot of noise
@Baile_an_Locha
@Baile_an_Locha Жыл бұрын
@@user-tk2jy8xr8b Well, compared to Haskell, yes. But it’s still much cleaner than an imperative approach. And you can do it more cleanly in C++20.
@Ich_liebe_brezeln
@Ich_liebe_brezeln 2 ай бұрын
⁠​⁠​⁠​⁠​⁠​⁠​⁠​⁠@@Baile_an_Lochayeah like this // could’ve been a one liner here if I did std::ranges::min_element, but let’s import the name so it becomes less noisy using std::ranges::min_element; Point& closestPoint = *min_element( points, [&target](auto& lhs, auto& rhs) { return distance(target, lhs) < distance(target, rhs); });
@brook1598
@brook1598 Жыл бұрын
amazing video, what software do you use to create your animations?
@peppidesu
@peppidesu Жыл бұрын
ms powerpoint, specifically, i use the morph transition for the code transitions
Жыл бұрын
Waiting for the next part
@ryagas5369
@ryagas5369 Жыл бұрын
Haskell definitely is interesting in the self-documenting aspect.
@freedom_aint_free
@freedom_aint_free Жыл бұрын
I love functional programming as a whole as Haskell is absolutely awesome, but this example was a little bit dishonest, following your logic I could use Python's module Scipy and import cKDTree and calculate the same with one line of code. You should've compared the raw implementation from scratch in each language, otherwise, by golly, we could have argue in favor of Java (a horrible language with multiple amazing libraries and a sleek virtual machine that is also faster than python).
@lpi3
@lpi3 8 ай бұрын
Well, all you need for Haskell to work is foldable and ordering class instances for your type. Python would be too much specific about data. If you write it as general as Haskel is you would loose performance
@user-tk2jy8xr8b
@user-tk2jy8xr8b Жыл бұрын
C#: static Point ClosestPoint(Point target, IEnumerable others) => others.MinBy(point => Distance(point, target)); BTW, the impl in the video is unsafe, it fails for an empty list
@mighwalghal1043
@mighwalghal1043 Жыл бұрын
Less go!!
@dorithegreat6155
@dorithegreat6155 Жыл бұрын
My university offers classes on haskell and they're scaring me a lot but maybe I will take them
@jeffreysun7983
@jeffreysun7983 Жыл бұрын
In Julia, this code is closestpoint(points, target) = findmin(distance.(points, target)) And it's *fast*. I love Julia.
@IllusionDX
@IllusionDX 3 ай бұрын
I can barely understand simpler code that does things step by step, I don't want to make it harder for myself
@angledmusasabi
@angledmusasabi Жыл бұрын
You've convinced me. =) Sub'd and waiting on the next one
@kamaeff
@kamaeff Жыл бұрын
Python version: best_distance = min(points, key=partial(distance, target))
@CamaradaArdi
@CamaradaArdi Жыл бұрын
Rust also has the same thing. Writting idiomatic rust is pretty close to writing haskell
@motyakskellington7723
@motyakskellington7723 Жыл бұрын
What about the time writing the code ? And the time to understand the code, ..
@norude
@norude Жыл бұрын
Defense for python: You totaly could do something like this: def closestPoint(points,target,distance): return min(((point,distance(point,target)) for point in points), key=lambda x:x[1])[0] Which is beautiful Another way would be to use more lambdas for this: def closestPoint(points,target,distance): return min(map(lambda point:(point,distance(point,target)),points), key=lambda x:x[1])[0] Python does not have good syntax for lambdas which is really disapointing. Doing something like js would be better: point => (point,distance(point,target)) Edit: As suggested in comments you could also write it as this: def closestPoint(points,target,distance): return min(points, key=lambda point:distance(point,target)) Which is best
@piaIy
@piaIy Жыл бұрын
You're way overcomplicating this. Why don't you move the distance calculation into the key function, which is, you know, the whole point of this parameter? min(points, key=lambda point: distance(point, target))
@norude
@norude Жыл бұрын
@@piaIy Yes! I didn't realise that was possible because I found out about the key function when needing to get both max and min of something. But that is totally valid too
@MaybeJustJames
@MaybeJustJames Жыл бұрын
Great video! I hope you keep going
How to read Haskell code (in 7 minutes)
6:51
peppidesu
Рет қаралды 63 М.
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,7 МЛН
My daughter is creative when it comes to eating food #funny #comedy #cute #baby#smart girl
00:17
WORLD BEST MAGIC SECRETS
00:50
MasomkaMagic
Рет қаралды 51 МЛН
The Joker wanted to stand at the front, but unexpectedly was beaten up by Officer Rabbit
00:12
Functional Programming & Haskell - Computerphile
9:19
Computerphile
Рет қаралды 667 М.
Ditch your Favorite Programming Paradigm
6:08
Code Persist
Рет қаралды 182 М.
Recursion in Haskell
14:03
Frazer Mills
Рет қаралды 33
Never install locally
5:45
Coderized
Рет қаралды 1,8 МЛН
Naming Things in Code
7:25
CodeAesthetic
Рет қаралды 2,1 МЛН
The purest coding style, where bugs are near impossible
10:25
Coderized
Рет қаралды 974 М.
how NASA writes space-proof code
6:03
Low Level
Рет қаралды 2,2 МЛН
My daughter is creative when it comes to eating food #funny #comedy #cute #baby#smart girl
00:17