haskell.
Вставка
- Опубліковано 30 вер 2024
- 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/...
Follow me on Twitter: / lowlevellearni1
Follow me on Twitch: / lowlevellearning
Join me on Discord!: / discord
haha anyway learn a better language (c btw) at lowlevel.academy
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
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 :)
"foldr mappend mempty" is exactly how this makes me feel
sounds like simlish 😄
this mmakes mme mmangry
@@rgw5991 😂😂😂😂😂
Bro this sh kills me fr 😂😂
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.)
"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"
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).
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
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!
@@galaxygur 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.
God looks away when one programs in Haskell
Seems like God abandons the programmer too
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.
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!
0:15 any body notice "how to exit vim " 😅
@@jabal_team
1st month of programming: "How to exit Vim"
10 years of programming: "How to exit Vim"
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.
What you get when a computer scientist is married to a software engineer but the milkman is a category theorist 👀
ua-cam.com/video/aZscBf10Y5A/v-deo.html
NO YOU DIDNT
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.
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).
@@БогданСтасив-ч8к 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.
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.
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? 🤔
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.
I do not have the maths background or even background to learn the background. I so want to love Haskell, but so far I cannot grok it, nor the materials that try to help me do so.
I don’t even know if this comment is satire or not
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
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.
@@СергейМакеев-ж2нnd 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.
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.
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.
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
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-.
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 was so lost just watching this minute
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.
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...
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.
@@AndreiGeorgescu-j9p 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.
@@torarinvik4920 As a dyslexic person, that was awful to read.
@@Jupiter__001_ I can understand that!!!
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.
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.
Your programming-wiki reading experience is so similar to mine!
I thought I was just stupid lol 😂
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.
I actually recommend Haskell. To everyone. Sure, weird at first... but definitely worth it. It's not everyday (or every programming language) that, when you finish, you think to yourself "that's the most f***ing beautiful code I've ever written."
@@doublewhopper67 Haskell refactors easily. The only reason you need skilled Haskellers is to work around performance and laziness issues, with the latter causing memory leaks. And you can always turn on strict mode with -XStrict to turn off laziness (in most cases), with a moderate performance penalty.
Haskell can replace Python in any case where the Haskell library ecosystem is sufficient; since at the scale Python works at means that you're unlikely to face Haskell memory leaks, there's little to lose as long as you have the Haskell libraries you need.
@@doublewhopper67 Suit yourself then. I'll keep it as my secret weapon ;)
I think the problem with acadamic languages 😂😂😂😂 not with the functional languages
Sorry, what problem? There's a problem?
@@qm3ster it is not a practical languages
@@mzerone-g6m that's not something shown in the video.
Out of curiosity, what makes it impractical?
@@qm3ster bad syntax, bad tooling, inconsistent standards (everyone uses their own flavor of ghc with whatever cherry-picked extensions), bad compile times, huge binaries, bad/difficult-to-reason-about performance. It's also a fact that Haskell is difficult to learn and impossible to teach, which means using it in industry will greatly restrict the pool of available programmers.
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...
As a math major, Haskell’s typeclass names are very intuitive for me.
(Dis)functional programming.
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!
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.
I have just one question. Why?
Lmk if you ever figure out how to exit vim, I've been stuck here for three years.
"yields the trees appended at the root node". What root node? How do you append trees?
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 🤓☝
* lang is evil
Long live rust lang
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 😆
Did you get mad because of how simple the `append` "implementation" was?
Or because of 🤢`undefined`🤮?
Haskell is a real piece of work, it's a pain. Almost any other functional language is easier to learn. Absolutely pointless dump that forces recursion.
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
More Haskell please 🥹👉👈?
I like the video, but all languages are garblygoop when you name variables like that 😄
0:46 since when do vim has right click context menus for "cut, copy, paste, del"?
Is this language created by mazochists for mazochists?
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.
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.
im not sure if few hours back the text on the thumbnail was different but nvm once i posted a video and changed the thumbnail like 5x times 💀
I did seriously lol. Haskell reminds me of all that is bad in our world.
You'd absolutely hate prolog going off your username.
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
gosh,I wound rather be abused by those borrow checkers.
The code looked like it was written by some faros back in the ancient Egypt.
i love haskell its utterly incomprehensible
that how to exit vim was personal 😭
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.
foldr mappend mempty
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.
its ez bro Haskell is just a Lisp but with types instead of parens
What youth thay about my lithp?!
Wow, you managed to exit vim?! Ho did you do that?
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.
Haskell code giving off abstract algebra vibes
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
It's easy, just "foldr mapend mempty"
I'm getting Vietnam flashbacks to my college module with Haskell.
Well, it looks like it's a brand new concept. Programming is a form of communication and if you were used to communicate in Italian, you can't expect to switch to French in a couple of minutes. It looks like Haskell requires heavier background in mathematics and some extra vocabulary. Only once you get there you can start judging the language. Imagine if the entire world spoke Mandarin and they would refuse English for being too hard to learn. Does it really mean Mandarin is so easy?
I agree, and i understood the video as good humored teasing.
For those people yes
Maybe and Either are not "brand new concepts", they have been around in our field of Computer Science for many, many decades. Please inform yourself about your own field instead of saying silly things like "Maybe and Either sound like brand new concepts!"
@@jboss1073 A brand new concept for him or anyone who wants to learn it. I never specified it. Mandarin is a brand new concept for anyone too, although it's been around for ages.
@@jurajchobot But Mandarin has nothing to do with programming, whereas you are supposed to know the mathematical foundations of computer programming if you are a programmer. So your analogy is invalid.
had to use haskell in one of my university courses...made a serious knot in my brain.
Ah, haskell. My favorite esolang.
Bro, mempty = undefined sent me 💀
Wasn't it invented and developed by Eddie Haskell, that neighbor kid on Leave It To Beaver?
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)
I get that same feeling about web frameworks.
"how to exit vim" got me laughing 😂, too relatable
A monoid is a collection of things that can be combined to form other things - like combining numbers by adding them together - such that there's an analogue to 0, which when combined with some other thing x just returns x. Here are examples of monoids that we probably use every day: (whole numbers, +, 0), (lists, list concatenation, the empty list), (words, word concatenation, the empty word), (matrices, matrix multiplication, the identity matrix), (dance choreography, joining up dance moves, staying still). You might notice the word "associative" in any "proper" definition of a monoid - this just means that (x + y) + z = x + (y + z). I'm not a professional programmer but I do need to write code for my job to implement mathematical or combinatorial algorithms, so I find these sorts of abstractions useful to compress the information I need to hold in my head when writing code. It takes some time to get used to the "conpression" and "decompression" while moving from idea to code. YMMV.
Well this isn't really hard, monoids represent anything which can be combined in a way like lists or strings, with neutral element which when combined changes nothing.
`mappend` is such combining
`mempty` is such neutral element
You had to implement Tree datatype and implement Monoid instance for it, which combines two subtrees into one
and i know about about haskell like nothing
You only pretented to close the laptop, because no programmer ever closes the laptop except he goes outside every few years.
A good programmer always has some empty pizza boxes everywhere that validate his credentials, just like seeing his butt when he bends down, to impress the ladys.
Coding and problem solving skills are secondary at best
dont waste your time, guys
haskell filters the soydevs
For anyone interested: #Here is a simple, but possibly flawed python snippet
#to illustrate how the IO Monad works.
class IO:
def __init__(self, f):
self.f = f
def bind(self, g):
return IO(lambda: g(self.f())())
def __call__(self):
return self.f()
#A few functions wrapped in IO
def ask_user():
return IO(lambda: input("Please enter your name: "))
def greet_user(name):
print(f"Hello, {name}, nice to meet you!")
return IO(lambda: None)
def uppercase(s):
return IO(lambda: s.upper())
#Here is the "main" program. A Haskell program is a long
#chain of commands executed in sequence.
program = ask_user().bind(uppercase).bind(greet_user)
program()
#The program uses bind to glue IO operations into a bigger
#IO operation, they are composable :)
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.
How to exit vim😂😂
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?
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.
Just popped in to say that a monad is a monoid in the category of endofunctors
Watching you struggle with Haskell as much as I do, reminds me that I'm not stupid, just not patient enough to deal with this language.
A monad is just a monoid in the category of endofunctors. What's the problem?
"Obviously" loool
Ah! So a monoid is just a monoid, then? Binary operation, closure, and that's it? (I think that's all the structure it has).
Maybe I'm wrong, but I saw a semigroup there, and that's one complication up from a monoid. I mean a monoid-monoid ... um ... an actual monoid - which a Haskell monoid is looking like it might be ...
At which point this becomes like the ancient Punch cartoon where a man and a little girl are walking into a field on a country ramble, and the little girl says, "What's that, Daddy?"
Daddy: "That's a cow, dear."
Little Girl: "WHY?"
love the meme content, keep em coming 👍
For those trying to understand, the 'monoid' in this case is just a way to add properties to your type. When a type is a monoid, you can assume it always has 2 functions: an empty function, kind of like the first element of a set/category. Think of this as 0 for natural numbers, or the empty list. Then there is a binary function that can take 2 instances of the same type, and produce a new instance of that type. For integers, this could be addition, for lists this is appending lists together (just like for this tree).
Essentially, because appending 2 instances of the Tree type has a couple of different cases, we use the Semigroup to cover the complexity of appending. But now, mempty is the empty function, and is the append function. Whenever you use type Tree, you can always use these functions, essentially making the type a monoid. It's just a way of summarizing certain properties that a type has.
Now, the type definition is a bit harder to grasp... these are inductive types and they're just recursive (like everything in Haskell), but I wouldn't be able to explain this here