coding in haskell until i rage quit
ฝัง
- เผยแพร่เมื่อ 1 ก.ค. 2023
- I tried to learn Haskell. I tried to be a good boy and learn the way of functional programming. But what the func is happening. What's the deal with Haskell? Why? Monoids?
Follow along with me on my journey in learning this "programming language". If you think Haskell is hard... try learning C • coding in c until my p...
🏫 COURSES 🏫
Learn to code in C at lowlevel.academy
🔥🔥🔥 SOCIALS 🔥🔥🔥
Low Level Merch!: www.linktr.ee/lowlevellearning
Follow me on Twitter: / lowlevellearni1
Follow me on Twitch: / lowlevellearning
Join me on Discord!: / discord - บันเทิง
this is great
A monad is just a monoid in the category of endofunctors. What's the problem?
But why
momad
No it isn't 😡
I was thinking definitely you will comment :)
Every Haskell tutorial:
Lesson 1: To add 2 numbers, use "+". Easy!
Lesson 2: To concatenate two lists, use "++". Easy!
Lesson 3: So to do I/O the only thing you really need to understand is that a monoid is simply a noncomposable convex bijection into inverse functor space. In other words it is a mapping over types. This allows you to
That’s confusing for non-math nerds though.
It becomes a lot easier when one realises that Haskell can't execute code. One can only make functions that is a chain of operations to be executed when the program runs. An incredible clever idea, really. This was the program OG John Backus wasn't able to solve. He said in an interview that he wasnt able to solve the problem of time and considered his explorations of FP to be failure.
Allows you to what? ALLOWS YOU TO WHAT?
@@mrtruman4339 It allows you to build a state based algorithm that is great for timing based attacks on systems that are otherwise rather difficult to build injection and attack packages for.
Julia is still better. Can do almost all of the same things, and the syntax is easier for when it's 3am and you're still working on an annoying project with far too many issues to work reasonably well.
@@Stopinvadingmyhardware I like your word soup of an explanation
"foldr mappend mempty" is exactly how this makes me feel
sounds like simlish 😄
this mmakes mme mmangry
@@rgw5991 😂😂😂😂😂
Bro this sh kills me fr 😂😂
What you get when a computer scientist is married to a software engineer but the milkman is a category theorist 👀
th-cam.com/video/aZscBf10Y5A/w-d-xo.html
NO YOU DIDNT
"How to exit vim" 🤣🤣🤣🤣 🤣
The video ended and I still can't stop laughing about it.
That just becomes muscle memory after a few years. :q! of course, why would it be anything else? Colon ":" for "this is a command", q for "quit", and ! for "simon says, I really mean it this time, so do it or I'll set you on fire"
Haskell fanboy here and I've been laughing hysterically for 2 minutes straight.
ahahah same
As the video is only 1:02 long, I can clearly state that your 2 minutes of laughter is *out of bounds*
And that's not acceptable...
And that was before you even watched the video!
“Rubs two brain cells together intensely.”
Nope, Erlang still makes more sense.
@@Verbatino Technically, they never said they laughed only during the video, so still totally in bounds.
(Also some people might be weird and watch youtube at 0.5x speed.)
Wait until you see the APL guy pull out his special keyboard
wait until the J guy slams his fist on the keyboard a few times and that produces a working constraint solver
Can you not just use ANSI trigraphs to generate apl characters?
The APL guy keeps his special keyboard in a very special place.
@@raskr8137 Still more legible than Perl
Everyone's having fun until the functional languages arrive
Lisp is functional but isn't annoying like the ML family.
@@tophy9865yeah I agree
The weirdest part is that functional languages just simply _deny_ the most common concept of computers: memory.
@@ern0plus4 No. They don't deny it. They abstract over it. Our machines have memory. But our minds don't do well when we have to think about operations of the underlying machine. Instead we use a different model of computation to think about and let the compiler and runtime worry about talking to the machine.
And I should note that these abstractions not only make things incredibly easy to think about, but they work very well. Even systems languages like Rust now have tons of functional APIs where you just don't have to bang your head against the wall worrying about unsafe stuff. I think the Lisp and Rust way is just good: make things easy by default, but allow people to do weird mutable stuff (Rust allows much more than this).
A nice mental excercise is to come up with a type system where types share as much common typeclasses as possible. This is how you get Semigroup (anything that can concat), Monoid (Semigroup + a way to concat an empty value), Foldable (fold, a.k.a. reduce), etc.. Typeclass names sound complicated, but it gets easier once you can understand the meaning behind it.
tc = interface
Well explained, you should record some tutorials
Make sure they're magma as well... although that presumably comes with the territory of having types and such!
@@berliangur thianks, I can recommend reading "Learn You a Haskell for Great Good!" if you want to learn more.
I didn't understand a single thing you just said.
I've glanced over at Haskel a few times now but I still think I'm fine with C...
we need to rename it H
@@IronCandyNotes I can't wait for H++.
@@DrSpooglemon how about Microsoft's H#
I'd consder going it alone with a bucket of diodes, transistors and resistors before whatever that was/is/shouldn't be.
Almost a thing until SPJ, one of the big names in Haskell-land, talked the Microsoft team out of it.
God looks away when one programs in Haskell
Seems like God abandons the programmer too
If you haven’t learned Haskell or another functional language I highly recommend. I was taught in university and at first I was lost but once it clicks it becomes fun. You start to notice how your brain thinks differently as you slowly go into flow.
Functional: yes. Haskell: no thanks.
I have no issues with FP but Haskell feels more like maths than programming.
@@SaHaRaSquad Agda:
@@SaHaRaSquad It is natural for purely functional language to be able to express things from category theory with ease (typeclasses, immutability, overall purity).
@@user-we4jg5yy4d My point has nothing to do with features, but the user experience. Haskell isn't a bad language but its design is more oriented at theory than practice.
I took a compiler design class in OCaml. Ocaml is one of the better functional languages. I still prefer imperative programming.
I love the little jokes that you add into the videos. They don't go unnoticed. "How do I escape VIM" as the default search. Love it. Been in EE/CS/Linux for many years and the joke never gets old. There's always a Grad or something asking! :)
Glad you like them!
EDIT 2: Please read my whole comment. I keep getting replies about functional programming. This comment is not about functional programming, as I already added at the bottom.
------
My main gripe with Haskell is just that... you can tell it was made by mathematicians, not by IT people, bringing along design philosophies that make sense in math, but probably not as much in a programming languages, like optimizing for fast writing, not fast reading of code
------
EDIT: Just to be clear: I'm talking about Haskell as a language and its syntax. Not about functional programming.
But that's what Haskell is for. It has its place. If you want performance you wouldn't use Haskell. But if you wanna prove a complex peace of software does and does only what it's supposed to e.g. cause it handles something critical functional programming offers you that.
@@BlauerTeeLp Thanfully Rust is a viable language today, i have seen a very good description of Rust online: "Haskell if it were useful"
@@techtutorvideos Rust have lots of functional features, for example the Option monad, like Maybe in Haskell. you do not need a PhD to understand its type system, but it still very strict like Haskell.
But it is closer to imperative languages, so it is more "normal" compared to Haskell.
The hardest part is ownership and borrowing, since Rust do not have a GC, you have to think more about memory, it is going to be hard if you never learned C or C++. For example, if you a a data structure with unkown size at compile-time, you need to put in a box, Box puts the variable in the heap, Or Rc if you want multiple ownership over a value. Example:
enum List {
Cons(i32, Box),
Nil,
}
This enum emulates a Lisp list, there can be a list inside a list, so there could be a stack overflown, it is only safe to store in the heap, that is what Box indicates, unlike lisp where everything is allocated on the heap without you noticing.
That is because Rust is a systems language, so it needs to give up some abstractions to be very fast.
@@rj7250a More like C++ if it had worse syntax. I thought C++ had disgusting syntax until I learned Rust. Now I know where all the brain damaged people that learned Haskell went. Moral of the story is, you actually can have a worse language and Rustaceans have shown us the way.
@@rj7250a is it necessary for you crabs to be everywhere? Don't kid yourself. Rust advertises itself as a C replacement, not a Haskell replacement.
Your synopsis is 100% correct. I haven't had to touch Haskell in > 20 years and its still giving me nightmares!
If you think Haskell is hard, try its tooling.
I was so lost just watching this minute
Funnily enough I found Haskell quite straightforward from the beginning and I wrote my first "useful" project using it and I am like 3 weeks into the language.
I really recommend everyone to do a paradigm switch it teaches you a lot. It doesn't have to be Haskell if you're not comfortable with it maybe consider trying ocaml, elixir, scala or even F#. Just break your norm.
I miss learning new tech. After work, i just don't have the mental capacity for it. And if i do feel like coding, i typically wanna improve one of my many foss projects.
OCAML made me fall in love with programming
"3 weeks", omg, that's a lot.
You forgot Clojure or Lisp.
@@reed6514 i don't know if I would call it "new tech", it's more of an entirely different paradigm really. And that's why it is so cool and useful to learn, it just trains your brain to think in entirely new ways that make you feel stupidly smart even though you really aren't that special at the end of the day
haskel is built around pure maths and theory in more mathematical stuff. If you don't have the foundation and that already then you're just going to be very confused. Unlike other languages, instead of it being based off of the foundations of more of a literal Hardware aspect of computer science this is mostly very high-level theory of computer science. It's not that it's a dumb or bad language it's just that it's very foreign to most people who don't already have the foundation in theoretical mathematics. It's a very fascinating and very interesting topic if you decide to do a deep dive. I'm not very good at it, but personally I think it is very cool
I don't have mathematics foundations but II like Haskell because it makes me feel like I'm learning programming from the beginning. I learn it to fight depression, believe it or not, and it helps.
Your explanations are so concise and easy to follow😀. Thank you for making this video!
This is how I understand it: A Monoid sometimes called a Combinator in F# is a datatype that can be combined/concatenated. This is usually done on a collection such as a list or in your case a tree. Without using loops you have 2 choices either sum the tree recursively, or use the more elegant method by using a fold. Fold applies a binary function such as plus operator between all elements of the Monoid. So applying fold on + function on the list [1,2,3] it sticks the plus in between the values and calculates a result. Concatenating a string is also an example taking a list of strings and adding them together to form a larger string. So it's sort of like anything that is a collection that can be reduced to a single value. Another frequent operation of folds are checking if a list has "any of", "none of", or "all of" a certain element. So for instance fold (==5) [1,2,3,4,5] will result in the value false since not all values are 5. This is a somewhat simplified version. In a short sentence a Monoid is a collection that can be reduced to a single value(simplified version). Btw use F# instead of Haskell is my advice to everyone if you want to stay sane, Cabal will take 10 years off your life :-D
ah, F#, the Ocaml ripoff. (Im kidding. I don't actually know anything about F#, but it looks uncanny similar to OCaml)
A monoid is simply a collection of elements that has just one operation defined for them, whose properties align with the properties of multiplication as we know it.
@@bigshrekhorner That is a good way to look at it.
Why combinator?
@@stevefan8283 Folding is about combining various elements into a new one. So «ab» + «c» = «abc». I think that is why they chose to call it that.
This content is bringing me waaaaaaaaay too much joy.
it helps to look at the math definitions for this kind of stuff, because that's what haskell and related languages are based on. a monoid is just a semigroup equipped with an identity element, and a semigroup is a set of elements with a closed "combination" operation defined over the set. you could take the set of natural numbers and form a semigroup where the operation is simple addition. to extend it to a monoid, define the identity element to be zero, because n + 0 = n. You could instead define a semigroup over the natural numbers that uses multiplication, and the identity element is 1. In this "assignment" the natural semigroup operation would be to create a new node and install both operands as its children, and the identity element would be an empty tree.
i think the problem IS the math definitions (and the vocabulary itself) for most people. But this is a good explanation either way.
@@homelessrobot The problem is education that convinces people that math has to be hard
Versus: Think of a monad like a conveyor belt in a factory (the factory is your program). Items (values) are placed on the conveyor belt (wrapped in a monad). As they move along, various machines (functions) can act on these items, transforming them as needed. However, the items remain on the conveyor belt throughout the process (stay within the monad). In the end, you get a transformed item still on the conveyor belt (a new monad).
The monadic operations allow you to chain together computations that might fail without having to constantly check for failure at each step. If any computation fails, the entire chain "short-circuits" with a failure result.
Wow it finally just clicked for me.
Monoids are a useful concept in programming indepently of Haskell. For example: if an operation is a monoid (hence associative) then it can more efficiently evaluated in parallel but performing the computation as a tree instead of sequentially.
Yeah I think he got the meme wrong. It should have been something about monads. Monoids are a pretty straight forward concept. Monads are the ones notoriously hard to understand.
@@grivza aren't they just a proxy to represent whatever is inside them?
@@bruhmoment1835 No, monad is a monoid in the category of endofunctors, don't you know? But seriously, I don't know. Interesting explanation though, I'll keep it in mind.
That is so relatable, this is exactly what happened to me last week when I was preparing for the new semester
Your programming-wiki reading experience is so similar to mine!
I thought I was just stupid lol 😂
Way back in 2002 this was typically the 1st programming language my uni taught for computer science, though I happened to take a C elective before it. I thought it was interesting rather than annoying, as I had little exposure to programming before then.
Had to learn it on functional programming classes and was actually really fun. Extreme confusing on the beginning, but when it clicks your brain fly
At University the Haskell programming class was (after OS programming with C) my second most favorite class (in IT - but of course nothing goes above Mathematics, which is my only true love).
You love Discrete math and analysis?
@@kikihun9726 I don't narrow it down to these both topics. Mathematics is the beautiful search for truth. And all parts belong together.
@@Zeitgeistpionier i was acing all math classes until i faced dischrethe math. I failed on the first year🤣 so no. Don't group them together
you must be a cs-math double major student
@@kikihun9726 complete opposite. i got straight D's/C's in all my maths classes Except discrete maths, easy A-.
Yep functional programming languages are designed to communicate with aliens.😂
I guess you are right they do feel like an anal probe 😂
No. Go learn Scheme.
@@tophy9865 But can Scheme learn Go?
@@PlasticCogLiquidLOL
So, does it follow that only aliens can truly understand it? 🤔
I'm in the process of learning Haskell for a class right now and this explains perfectly how I feel
Good luck, I went through that last year and it was the worst time of my life (I had to implement AES encryption with Haskell)
Never used Haskell, but as a mathematician reading that short definition of a monoid, it sounded really straight forward and useful to me. It’s like a Group in mathematics, defining a type of object and a function of combining these objects - very straight forward.
That's because Haskell was cooked up by a committee of programming professors that wanted to represent higher mathematics more easily in code.
It's by no means an efficient language, but it allows for very mathematical code, typically extremely short but incomprehensible. You'll usually only ever find it in research and teaching, hardly ever in practical applications.
But if you want to play around with it as a mathematician, it might just be right up your alley.
@@voxelfusion9894
You do realize the imperative side is just slightly-more-verbose Python, right? And all you need to understand "pure" Haskell code is to be comfortable with recursion and be willing to read the definitions of the operators, functions, and values in use.
main = for_ [1..100]
um ->
case (num `mod` 3, num `mod` 5) of -- case equals match + pattern matching, `mod` is the function mod (modulus, % in other languages) converted to an operator
(0,0) -> putStrLn "FizzBuzz"
(0,_) -> putStrLn "Fizz"
(_,0) -> putStrLn "Buzz"
_ -> putStrLn (show num)
-- show converts a value of showable type to String
for_ is a higher order function that takes a value of foldable type (a container that supports reduce operations) and a function that returns values of applicative type (IO is, in this case, an applicative type) and sequences the resulting applicative values together; this is the semantic equivalent of a for loop.
@@jindrichsedlacek5298 at least thats readable instead of just character soup
@@tauiinwhat do you mean, what >>= does is intuitively understandable
@@voxelfusion9894 If you want an efficient Haskell, there is Rust.
kkkkkkkkkkkkkkkkkkkkkkk my gosh this video translated perfectly what I felt when starting the studies of functional programming
I felt this way too, (and Haskell's actual syntax leaves something to be desired) but FP really allowed me to reason about my programs in a way that I could never do before
"how to exit vim" got me laughing 😂, too relatable
The only course I failed during my undergraduate study is the Functional Programming, even though my lecturer is one of the creator of the GHC...
It seems we had the same impression of Haskell 😂
I made more progress with Erlang, thanks to "learn you an erlang for great good" but most of the functional weirdness remains. This is why programming languages are for engineers, not math people who would do everything in lisp with cryptic single letter variables based on words nobody else has ever heard
There's "learn you a haskell for great good" too if you feel like taking another shot!
Abbreviations are the wrk of the dvl. Just wrt evrythng in pln eglsh.
@@user-tx4wj7qk4t I have done a ton of programming in Haskell as well as F# and learning Coq at the moment, and in my opinion Haskell isn't really about the math that one usually learns at school. One doesn't need to be good at math to do functional programming. I do find that people usually complains that Haskell is different from other languages or "I don't understand it", but of course that is just in the beginning until one gets used to it. With time it will become natural and intuitive.
1 minute and 3 seconds until you got lost! You outdone me!!! I was lost after 15 seconds - not worthy of a video in my case 😂 I just can’t understand that there are people who can program
Haskell and not C/assembly…
Well these are two different skillsets entirely. Good luck trying to program cryptographically secure applications in Assembly.
@@Finkelfunk That's not that hard on modern cpus as there's hardare for that on the CPU. And frankly you wouldn't do that in Haskell either but in C/C++ :D
@@Finkelfunk AFAIK haskell isn't that good for cryptographic security due to the potential implications of lazy evaluation for secrecy - half of the cryptonite library is written in C
love the meme content, keep em coming 👍
Question: I see you run a mbp, what’s the specs? Looking to buy one and running VMs. Thanks!
This was funny, I would have done the same. And as you, I am closing the laptop, getting a shower, and going to the groceries store.
In math, a Monoid is a group of objects as well as a function that takes any two of those objects and returns a third one; such that the function is associative and there exists a neutral element in the group
For all a,b,e in the group:
the function (f) is associative if f(a,f(b,e))=f(f(a,b),e)
e is neutral if f(a,e)=f(e,a)=a
I've learnt quite a lot thorough watching this video because of reading helpful comments like this.
Ok. I understand the fn you gave here. What deparment of Mathematics is this exactly? And can I learn it on a 10+2 Level of Mathematics that I'm currently on? Meaning that I know know what someone needs to know to study Engineering.
@@friedrichmyers Not sure what department of Math this is in.
I studied that for engineering so shouldn't be a problem for you.
This isn't related to Calculus
Yeah, I think it is related to Discrete Mathematics and Set Theory, then.@@yoavmor9002
@@friedrichmyers abstract algebra
I took a break from Haskell after I tried modifying values in an XML document, looking for simple operations.
It's been a few years...
had to use haskell in one of my university courses...made a serious knot in my brain.
Decided to try learning at least one FP language yesterday for the sake of understanding it's concepts and this drops. Can't decipher if it's a good sign or...
I can really recommend learning functional programming, but imho don't start with Haskell unless you love maths. Haskell is just mathematics pretending to be a programming language, and there are others which are much simpler.
@@SaHaRaSquadif Haskell is math pretending to be programming that is kinda cool haha but not what I'm looking for. I just want to learn FP concepts. There's still Ocaml to consider.
@@SaHaRaSquad Which do you recommend?
What monospace font were u using in the shell, if you don't mind sharing?
I think the thing that makes fp hard to get into is that there is a focus on introducing these abstractions which (while ultimately useful) are a million miles away from the actual use case. The classic one is the monad- in practice you're very rarely going to use any monad other than lists (and similar array-like types), options (maybes), results (eithers) and IO. Ideally you would be able to interact with these types in a specific way *without having to know* that they're actually monads and without needing to use the general monad behaviours and figure out how those behaviours are implemented in the specific monad you want to use. Say I have a list of strings, and I want to split each of those strings into a list of characters and return a flat list that contains all the characters, *i don't care* that the same operation happens to be possible on various other types because they're all monads, and I shouldn't need to care.
I'm getting Vietnam flashbacks to my college module with Haskell.
that how to exit vim was personal 😭
not gonna lie, it kinda easy to understand if you get the idea that Semigroup is stuff that can be concatenated, and monoid is just Semigroup + mempty function that return default value.
The 4 line semigroup part is just a pattern matching that tell what to do if it get the leaf or the tree 🤓☝
"how to exit vim" bro you kill me with those little tidbits like that 😂 definitely underrated af
Plz make more of these skits man. These are good.
It's really painful to move from imperative to functional programming
A pain in the monoids
Its even harder to move back to imperative
@@dithy imagine getting used to Rust safety standards then back to JS 🤷♂️
@@thanatosorwho codes in JS? its only a compiler target 😆
Well now, butter my butt and call me a biscuit! Yer tellin' me you ain't hip to the wonders of Haskell? Well, sit a spell, partner, 'cause I'm about to school ya.
Now, I ain't no high-falutin' big city computer whiz, but I know a thing or two about good old fashioned logic. An' that there's what Haskell's all about. Ya see, it's got this thing called a "static type system," which basically means the computer does a whole mess of checkin' before it even runs your program. Cuts down on them pesky bugs, don't ya know.
Ever hear tell of "side effects"? In most o' them other languages, your functions can just go 'round changin' things willy-nilly. Not in Haskell, no sir. Functions in Haskell are like good, honest work: ya put somethin' in, ya get somethin' out. None o' this behind-the-scenes tomfoolery.
An' speakin' of work, Haskell's got this thing called "lazy evaluation." Now, I know what you're thinkin', but it ain't what it sounds like. It ain't about avoidin' work, it's about doin' work only when you need to. It's like when you're fixin' to build a barn, but you only cut down trees as you need 'em instead of all at once. Saves a heap o' time an' effort, I tell ya.
Now, I ain't sayin' Haskell's the be-all and end-all. Like a good pickup truck, every tool's got its job. But I'll be hog-tied if it ain't got a lot goin' for it. So next time ya hear some city slicker yammerin' on 'bout Python or Java, just remember: there's more'n one way to skin a cat, an' Haskell's one heck of a knife.
I am starting a haskell class today, after seeing this video, I am terrified
Next time, when a friend asks you to learn them programming and you are confused why they can't understand so obvious basic programming principles, think about haskell
Haskell Programming from First Principles is a wonderful book, and I absolutely recommend it if you read Learn You a Haskell for Great Good and hit a wall at typeclasses.
Haskell is fun as hell when you "get it", and HPFP makes getting it fun and easy-ish.
Lmk if you ever figure out how to exit vim, I've been stuck here for three years.
As a math major, Haskell’s typeclass names are very intuitive for me.
Wasn't it invented and developed by Eddie Haskell, that neighbor kid on Leave It To Beaver?
Haskell code giving off abstract algebra vibes
More Haskell please 🥹👉👈?
This is funny :)
I do programming in haskell as a hobby (yes) but i say something along with the motto of the video:
Haskell itself is not hard, the type system is kinda of. The big problem on the past was the lack of learning material that don't try to prove that something is a monad, or something like that.
If you are really triyng to learn haskell first read learn yourself a haskell for great good from lipovaca, then read Haskell in depth from Bragilevsky. Both are more focused on the programming than the theory behind the language and the type system.
I wouldn't even say the type system is difficult per se; but the compiler error messages are criminally bad.
The other problem is the glut of monad tutorials written by people who don't understand monads.
We did haskell in first year CS in parallel to java as part of "software engineering". FOr certain data structures it's useful, although for the life of me wouldn't remember a single thing about it now.
"How to exit VIM..." as the last google search. HILARIOUS!!!!!
Haskell and friends contain many good ideas.
The problem is they suck as actual programming LANGUAGES. Their syntax is terrible, and not everything in the world is modeled well by verbs. The real world has both nouns & verbs; pure OOP languages suffer a milder version of this same problem by refusing to have 1st class functions. All you need do is look at Haskell’s inability to intuitively model files & I/O to see the underlying problem. A file is an inject, a thing, not a process.
Strongly-typed functional languages are just as much about "nouns" as they are about "verbs". The use of "Maybe", "Either" and other algebraic data types is a way better approach to "nouns" than in the OO languages.
@@user-qm4ev6jb7dnd imperative is superior to both IMO, no noun/verb nonsense, no false pretense that the real world can be accurately and consistently modeled through code, just data and functions.
Just popped in to say that a monad is a monoid in the category of endofunctors
Ive heard about monoids. Arent they a thing in Universal Algebras?
On line exists book or pdf (free) "I learn you Haskell for greater good" or something like this, you should start there, bacause even syntax is diffrent and mode of thinking also... I tried once..
Syntax i absorbed but to change thinking i landed on things called "Little Schemer" (also free as i rembeber) series of books.
Lisp, Clojure, Scheme, Guile, Zig
Christian Schafmeister, Why he chose Lisp for complex 3D molecular modeling for Chemical Engineering.
See Andy Keep and his Nanopass compiler, very cool.
0:46 since when do vim has right click context menus for "cut, copy, paste, del"?
I am a legendary video game developer, having created over 25 video games that have sold 1 million copies of more. My first video game was published when I was 12 in Compute magazine. I have been coding for 45 years. And I just tonight heard about Haskell. I was confused about how this was supposed to be an advancement of coding, when it looked like the opposite. So I searched for TH-cam videos on the subject and found yours after three others and... not only did it make me laugh out loud, it also restored my faith in the world. I sincerely appreciate your take and thank you for taking the time to share your feelings on the subject. It cleared things up for me.
what's your best selling game?
Lol, this is how I felt when learning all of Swift's weird syntax if I'm honest.
"yields the trees appended at the root node". What root node? How do you append trees?
The code looked like it was written by some faros back in the ancient Egypt.
while the instructions were kind of unclear, that's a terrible solution that chatgpt gave you, if just because it returns a function of *undefined*, which will throw an exception when evaluated.
the best solution my friend and i could come up with, given the (again, very vague) assignment, was
... haskell code incoming, brace yourselves:
data Tree a = Leaf a | Node [Tree a] deriving (Show, Eq)
instance Semigroup (Tree a) where
Node l Node r = Node (l ++ r)
l@(Leaf _) Node [] = l
Node [] r@(Leaf _) = r
l@(Leaf _) Node r = Node ([l] ++ r)
Node l r@(Leaf _) = Node (l ++ [r])
l r = Node [l, r]
instance Monoid (Tree a) where
mempty = Node []
a binary tree can't fulfill the associativity requirement on the Semigroup operator , so we instead defined an arbitrary tree where inner nodes have a list of their children. the obvious definition for concatenation (that's the operator) is then just appending those child lists at the roots, and the neutral element is a node with no children. if a leaf is involved, you just add it to the other node's children; if there are two leaves, you just combine them into a node.
Binary tree can fulfill associativity requirement if the binary tree holds data in branches, not leaves, and the joining of a binary tree is done on the leaves.
Think of defined as "left tree has right tree connected via the right-most leaf", then (tree tree) tree = connections via right-most leaf, tree (tree tree) looks exactly the same.
As the question is proposed, you need a rose tree to make it work, since (tree tree) tree has the long portion on the left, whereas tree (tree tree) has the long portion on the right.
When you leave someone to do a project, and they lock themselves in their basement for years, that project was probably a programming language.
Haskell is made to drive mortals mad. But at least it isn't JS.
We had a bonus task in uni to write a text editor in haskell. I did not get a good mark.
Wow, you managed to exit vim?! Ho did you do that?
Fyi, monoid is just an associative operation over a set that respects an identity element in the set. A commonplace example would be addition or multiplication, with 0 or 1 functioning as the identity element.
In Haskell, it refers to a type with a valid monoid instance ( from semigroup, which requires only an associative operation, and mempty, which is the identity element).
The most commonly used monoid is the list type.
Ironically, booleans and numbers aren't monoids because they support both monoidal addition and multiplication; you require a wrapper type to specify what monoid you want.
Conveniently, functions are monoids provided their output type is a monoid and they share the same input type. That is to say, you can monoidally compose two functions where given an input, the resulting function will produce the monoidal composition of the two results.
A lot of Haskell is coming up with complicated mathematical theory for everyday things. 80% of magic Haskell math terms can be reduced to "everyday object x on steroids"; here, monoid is just addition on steroids.
Edit: addition or list append on steroids.
A monad is just a monoid in the category of endofunctors. What's the problem?
When you said, "no, I'm good" ... I felt that.
Is that bookbag by E Jammy Jams?
Dr. Chuck reference spotted.
glad my brain isn't the only one that breaks when looking at those lines
It's pattern matching.
I get that same feeling about web frameworks.
Is it weird that I really like both C and Haskell? They are at opposite ends of the spectrum but both great at what they do.
How, exactly, are they polar opposites? Because to me they're way less different than, say, Java and Haskell.
C and Haskell are both relatively small, terse, and you can technically use both for functional programming. In contrast, Java is very verbose, has a ton of boilerplate, and you can realistically only do OOP with it.
@@Diapolo10 Fair point.
No it's perfectly normal. I'm also like that.
@@Diapolo10
I'm not sure what you mean when you say Haskell is small because Haskell is actually one the largest and richest languages that I was exposed to.
@@khengari77 At least from my point of view, Haskell's "vocabulary" is fairly small. Like in C, there's the usual operators, and a few keywords thrown into the mix.
Compared to Python, C++, Java, or C#, the total is considerably less.
mathematicians be like: functional programming just makes so much more sense!
mathematicians also be like: 2^3 is 3 copies of 2 multiplied together, using 2 multiplications, because exponentiation is iterated multiplication so obviously when you multiply 3 times it results in 2 multiplications, which is why we can't figure out what 0^0 means.
meanwhile irl: 2^3 = 1 *2 *2 *2; 2^0 = 1; 2^-3 = 1 /2) /2) /2)... so there's always an initial condition of 1 which explains everything perfectly including why 0^0 = 1. but because the 1 is optional in the expansion when the exponent is positive absolutely nobody ever noticed this, and the discrepency between the exponent and the number of multiplications in the conventional approach is doubled-down on in the definition of the hyperoperations, like tetration and pentation, etc. because... rigor? no, no... RiGoR!
BRUH I was just about to solve some hackerrank in haskell and this pops up
Lasted longer than me.
You who enter, abandon all hope.
The task isn't clear whether it has to be a binary tree and the trees have to be added continuously, or a regular tree with all the trees at root at the end. I understood the later, which makes ChatGPT's solution incorrect. It would be a really easy task however, since all you have to do is lift the list monoid.
@@TapetBart any tree that can fulfill the requirement to have *the trees appended at the root node*. a binary tree can not have more than two trees at the root node at the same time.
As someone who tried to learn Haskell as his first programming language I approve of this video.
The thing is if Haskell tutorials simply banned using math terms and built on my understanding of map, fold, closures etc, I'd probably get somewhere
If only Haskell folks fixed their package manager, we could all try learning the language.
I like how the last search keyword is "how to exit vim".XDD
i love haskell its utterly incomprehensible
Haskell is the best programming language and there's nothing anyone can say to change my mind.
With that said, this video showed basically how I felt when I began learning it.
It's certainly is extremely enjoyable to program in, but the tooling and ecosystem makes it difficult to use for real work. Not impossible, but difficult. The cabal folks should really study Cargo and pip, but at this time it might be too late.
> pip
But slightly more seriously: we would be way better off if we began replacing language-specific package managers with Nix or Guix
@@mskiptr Thats a really good idea! Love it!
What about the fact that Haskell literally can't even excecute without the Haskell runtime? - which is written in C, because of course it is.
@@joestevenson5568 There are of course pros and cons to having a runtime. It can help with a lot with concurrency like it does in Go and Swift. But you always pay a price for it of course.
I love this guy
In english, Implement the '+' opperator for a pair of tree datastructures. It should return a new tree with the two other trees as children of the root.
I took a class on programming languages and I didn't learn Haskell by the end of it despite passing the class.
A monad is just a monoid in the category of endofunctors
hahaha i feel like that when i don't understand something or whatever reason, "let's continue tomorrow" haha
gosh,I wound rather be abused by those borrow checkers.