Getting Started With Haskell
HTML-код
- Опубликовано: 27 окт 2024
- Some of the viewers have asked me to take a closer look at Haskell since I've done so much content regarding Xmonad, a tiling window manager written in Haskell. Well, I'm not a programmer by trade. And I certainly wouldn't say I "know" Haskell. But I, a non-programmer, will attempt to cover some of the basics of Haskell in this video.
ERRATA:
I messed up in explaining the order of operations for 'foldl'. 'foldr' and 'foldl' are confusing as hell. But the following diagram should be right...
foldl (+) 0 [1,2,3,4] = ((((0 + 1) + 2) + 3) + 4)
foldr (+) 0 [1,2,3,4] = (1 + (2 + (3 + (4 + 0))))
REFERENCED:
► learnyouahaskel...
► www.haskell.org/
WANT TO SUPPORT THE CHANNEL?
💰 Patreon: / distrotube
💳 Paypal: www.paypal.com...
🛍️ Amazon: amzn.to/2RotFFi
👕 Teespring: teespring.com/...
SOCIAL PLATFORMS:
🗨️ Mastodon: mastodon.techn...
💬 IRC: irc://freenode #distrotube
👫 Reddit: / distrotube
📽️ LBRY: lbry.tv/$/invi...
DT ON THE WEB:
🕸️ Website: distrotube.com/
🐿️ Gopherhole: gopher://distro.tube
📁 GitLab: gitlab.com/dwt1
FREE AND OPEN SOURCE SOFTWARE THAT I USE:
🌐 Brave Browser - brave.com/dis872
📽️ Open Broadcaster Software: obsproject.com/
🎬 Kdenlive: kdenlive.org
🎨 GIMP: www.gimp.org/
🔊 Audacity: www.audacityte...
💻 VirtualBox: www.virtualbox...
Your support is very much appreciated. Thanks, guys!
Tsoding is my favorite haskell programming channel. if people want to learn more.
Thank you for introducing me to this fellow.
@@mustyhead No problem, I love his twitch streams
There's a series called "Haskell for imperative programmers" here in RUclips
@@santiagolerin Yes, it's a nice series. Short lessons that don't hurt my brain. Many nice people, like Tsoding and Hagenlocher, teaching Haskell :-)
@@sho3bum are you on LinkedIn
HE GOT ON THE HASKELL BANDWAGON GUYS, HE DID IT
Programming tutorial on dt channel
where the hell am I
Luke Smith is getting more programmy with his videos too. 2 years from now these guys become full blown devs, I wouldn't be surprised lol.
An introduction to the configuration language of XMonad, and in the end he even might explain what a monad is. :-)
@@AndersJackson "A monad is just a monoid in the category of endofunctors, what's the problem? "
@@stradomus9673 Yes, what is the problem?
Quite a Big before you wrap your head around it, then you can't understand what the problem was. 😜
English isn't my first language, and I have to mention your accent is so cool, your English is so clear and easily understood! Great tutorial, thank you!
I wonder where he's from. Sounds very southern
Single quote near variable is called "prime". It is mathematical notation. E.g. when someone defines two variables taking values from the same set, then they can be X and X'. The second one is called "x prime".
I thought it means the derivative of the function
@@toastybread_ch It can mean that as well. in general, x’ is some new thing that is (usually) distinct from x but closely related in the context of the math being discussed. In calculus, the derivative of a function is closely associated with the function, hence x and x’. But you could be discussing a vector x and the vector it gets mapped to after a linear transformation, x’. or a group element x and the element it gets mapped to via a homomorphism, x’. All depends on the context.
honestly i'd love to see more dt programming tutorials
Still relevant in 2023, awesome crash course. Thanks, DT!
Fantastic video to make the first step and hop into learning Haskell for greater good!
Haskell is a beautiful language, especially if you enjoy the Unix philosophy: compose (functions/programs) that do one thing and do it well in order to build complex stuff.
There's a lot of amazing things about Haskell, but you need to spend some time with it in order to appreciate it. I've worked with tons of languages (Java, PHP, Python, Javascript, C...) and none come close to the power of Haskell.
Wtf is a monad?
@@nevoyu a monad is a monoid in the category of endofunctions
duh
@@vansweej you said the line, bart
Such a great starting point for Haskell.
It warms my heart to see one of my favorite [non-programmer] youtuber to do an intro into my favorite programming language.
If you need help in understanding something in Haskell then you can contact me and i will try to help.
Thanks! Appreciate that.
Does this apply to non-Distro Tube people too?
-> @@KGafterdark : Yes, i would like to help to everyone. I imagine people calling me up on GoogleHangouts [my account name is "libeako"], where i am often available.
@@DistroTube you have done a really good introduction, going all to using functions as parameters. Nice work, really.
That is nice abstraction, without the fuzz of for loops and stuff. All that map, foldl and that are strong programming concepts.
@@DistroTube fantastic job!
This is great. Just hanging out with Derek, learning some Haskell along the way. Man, that infFibs list really twisted my brain!
Great to hear!
a |> b = b a
this blew my mind when I stumbled across it. I'd seen it in Ocaml or F#, and figured it must be possible in Haskell. I started with the type signature ( ( |> ) :: t1 -> (t1 -> t2) -> t2 ), and the function basically wrote itself. If it's not clear, this behaves like the pipe operator in shell script. It's one of the easiest functions to write.
It's also already in base: Data.Function.&
your outboard audio gear is freaking amazing!
i just started hacking hakyll and lo , DT with haskell video ! Awesome content man, keep rolling !
Mostly because of you I switch from dwm to xmonad. Great wm
Thank you, Derek. Another video to safe for reference.
Really nice tutorial, and you added concepts like functions are like any other value, so you can send them as arguments to map and fold{r,l}
In Emacs you also can run the REPL from within Emacs, also in another frame. A bit nicer integrarion, but good to introduce all.
That’s the funniest use of a REPL I have ever seen. Can’t wait for the next „aaand ... reload“ :)
As a "Non-programmer", you my good sir, have pretty good taste in programming and apparently, sure as hell know how to teach programming well.
I have experience in programming; and he is one hell of a teacher!
Hey man, you are an excellent teacher! :)
Knowing Perl6 metaoperators Z zip X cross and [] reduce helped me recognize some of the functions
edX has course 'DelftX - FP101x' - this is free course on Functional Programming based on Haskell.. learn from the best, this time it's Erik Meijer
Thanks for the course. I just started learning Haskell few weeks back using reddit sources. Didn't know about this course. Will check.
@@dhruvrana4735 have fun, they recommend students to use HUGS version of Haskell, but this is not so important
I love me my Perl, but I think I'd gain a lot from learning another language. Raku's high on the list, but this video's got me thinking Haskell too. Most Haskell concepts are familiar to me from Perl, except infinite lists (yum), immutability, and *so many datatypes!*
I've got a pretty massive PERL programming book in my library, but I haven't even opened it yet. What do you like about Perl? Does Perl have a REPL? A CS professor told me a while ago that Perl has a little bit of everything in it: some object-oriented programming, some procedural programming, some functional programming, and maybe even some logic programming too? But isn't Perl kind of a dead language? Except maybe in the area of Bio-informatics?
I got started with Python, and finally have a first serious project to work on. I read about Haskell, and its concept seems very interesting. Same with the Go language.
Earlier, I complained about the amount of dependencies that Haskell would pull on Arch. It might be specific to Arch though.
By the way, tuples are an awesome data type. I learned from Python that tuples are lightweight and fast, generating about a hundred times faster, yet consuming a lot less memory. However, tuples, unlike lists, are immutable, if I remember correctly.
Thumbs up for this tutorial, DT!
Don't do go please. Python sucks too, but go was literally made to be stupid
@@leonk6950 I'm not going to dive into any discussions about Python at this point, but what's wrong with Go? From what I hear, it delivers single binary files with notable execution speed. Could you elaborate (briefly!) what you believe Go is doing wrong?
In Haskell all data types are immutable.
@@tokiomutex4148 Didn't know that. Thanks! 🙂
@@marioschroers7318 Well, a lot of languages can translate source code to native binaries - C, C++, Rust and of course, Haskell. But Go has a lot of cons of wich people don't like it. One of them is awful error handling - every function with possible error returns tuple like (Maybe result, Maybe error) wich forces you to write memed boilerplate code "if (err != nill){}". Another problem is lack of generics wich also forces you to write boilerplate code.
For more details you can read some of these articles: github.com/ksimka/go-is-not-good
Great! I liked the employee name, "Ben Dover"....um, is he related to MR. BEND OVER?! LOL!!!! What is Patreon? Did you use a Linux computer to make this tutorial? I think you should definitely make many more such tutorials having to do with the Haskell language. It is an excellent and elegant programming language, and sadly most CS departments don't teach this language. If Haskell appears at all in a CS program, it's usually in an upper level Programming Languages course. Those courses can be extremely theoretical, and sadly do not emphasize the practical applications of Haskell. Thanks man! You did a great job. And by the way, I agree that the Lisp family of languages can really torment people with so many parentheses! Having said that however, I confess that I really do like the Racket programming language. Haskell is great, but don't underestimate Racket. Racket (descended from Lisp) is also a really neat programming language, and its IDE, DrRacket, is very easy to use and makes learning Racket so much easier.
If you are wondering if this video will cover Monads, the answer is Maybe.
Amazing language. I love lamda calculus, once you get it, its so easy
AWESOME !! You finally did it !
thanks for this overview
You showcased recursion, great. Now can you make a video explaining what a monad is?
A monad is just a monoid in the category of endofunctors, what's the problem?
A monad is any structure that can implement the 'return' and the 'bind' (>>=) operator (think of it as a Java interface).
What does 'return' do (not your average programming language 'return')? Puts a value inside the structure.
What does 'bind' do? It extracts a value/values from the given structure and sends it to a receiving function, and that function also returns the same structure.
For example, take the Maybe type:
'Maybe' is defined as Maybe a = Just a | Nothing, that means that you can create a 'Maybe a ' value using 'Just ' or 'Nothing' - note that 'a' must be a type like 'Int' or 'Bool'.
Now lets say you have a value 'x' of type 'Maybe Int'. How can you know if x holds an Int (x = Just 5, for example) or not (x = Nothing)? And what if you need the value of x for another expression, for example, lets say 'y = (the value inside of x) + 1'? Note that if 'x = Nothing' this expression should fail (y = Nothing)
Well, you can use the bind operator for this very easily: 'y = x >>= return . (+1)'.
If x = Just then 'y = Just ', otherwise 'y = Nothing'.
We used the >>= in order to extract the value (if one exists) from x, we applied the (+1) function over it, and then we put the resulting value inside a Maybe using return. That's it.
Now think of Maybe like a Nullable type (Nullable Int = Just Int | Null) in your favorite programming language. Now you're forced to handle all null values, and you can safely extract values from Nulls. Some languages have this baked in like Kotlin, C# and Typescript (the '?' accessor), so you end up doing something like "person?.name?".
The famous 'do' notations is some syntactic on top of monads, so you can write the previous expression as
y = do
valueInsideX
@@valcron-1000 damn, I did not actually expect such a good elaborate answer.
I watched a few videos on it in past but I didn't get it. I might have to read this a few more times but it feels a lot more practical. Might still take a while to really click with me
You're the man, dt
Remember kids.
An Int is an integer. An Integer is also an integer. But, an Integer is not an Int.
Haskell, puts the 'fun' in functional! >.
I think it's simple, an Integer is longer than an Int
Ben Dover LoL! Very nice video! Please keep doing this kind of content!
How exactly did you get ghc to allow for non-dynamic linking? Normally, Arch builds everything as a dynamic package which will cause ghc to fail if you don't pass -dynamic in the compile.
I figured it out. I am using Windows so to clear the terminal screen use :!cls and for Linux use :!clear
:!clear does not work for me, and when I type :? it doesn't show it as being a command.
Hey dt! Fantastic video. Im a linux/Emacs noob but i wanted to understand how to deal with guile scheme on a fedora based distro. Howd you go about that?.
Doing this for Plutus, thanks!
Great video!
Very good man. Thanks!
49:20 right side of 152 looks like lisp
is there exponent and log ? Also, can you do imaginary and complex numbers?
Yes. I mentioned them but didn't demonstrate...exponent is 'exp' and log is 'log'. And yes to complex numbers as well. There is a module that might help with that: hackage.haskell.org/package/base-4.12.0.0/docs/Data-Complex.html
Good Job!
Mad cool, your a programmer DT.
In Haskell too. Which scares the hell out of C, C++, Java and C# programmers. ;-)
Richard Stallman comes into the house with his Thinkpad and busting out new code, stares at DT "yours a programmer DT" and the rest of the family are horrified by the strange man in their house and he takes DT away to the magical works of free software
@@MyurrDurr think Stallman is more of a C or Lisp man. 😜
@@AndersJackson well damn :') I was just trying to make a funny comment!
@@MyurrDurr me too. I thought you post was funny.
Hey Distrohuggers,
I am excited to report that my install on hardware of Fedora Rawhide is still going well. Today's update brought in a new beta-build of the rpm package ( Version 4.16.0 ). And also, systemd 245-6. If one were to install Rawhide today, they would get something that resembles Version 32 of Fedora, but about half the packages would be labeled Fedora 33, and would have received some update that the same packages in Version 32 might not have received. Kernel, of course is the very latest, but from my experience, when kernel 5.7.0 becomes 5.7.1, the kernel for Rawhide will already be on 5.8.0.rc0.git123something. That is one of the reasons many Fedora users do not recommend that you use Rawhide. Another is that there is debugging stuff going on that could confuse people or slow down your system. And another is some of the packages may be straight off of git, and not tested much, if at all ( examples: conmon, podman, runc, etc. ) Some would suggest that if you really want something newer than Version 32 of Fedora ( in the rpm-based distros ), then best to use OpenSUSE Tumbleweed. I am not one of those. I say, if you can use Rawhide, then do it, as my motto is "Live on the Edge - Live in Rawhide."
I’m surprised that many things on the Haskell syntax are very similar to Pascal.
What packages do i need on arch for this more than GHC and GHCI?
people who learned what variables in javascript are consider themselves programmers, but haskell-knowing linux-using emacs-enjoying gigachad right here doesn't?
What setup are you using? Is it just vim with some themes? Could you point me to how I could recreate your text editor setup?
can you make a video about dwmblocks and the required patch for it. i have really started to love DWM for some reason. i started with Xmonad when your video came out for getting started with Xmonad, i start configuring it and almost had done with the setup. took your config and striped stuff i didn't needed and added what i need, but then i saw videos yours and luke's video about DWM, at first glanced i liked how it looked, its minimal yet beautiful. i though I'd struggle with the patching but so far its been really fun time consuming but fun. i like tinkering with stuff.i now have DWM almost setup just need to configure the status bar. i could not find something helpful about dwmblocks
well i had this question in unix & linux stack exchange and some guy suggested me this project for easy DWM and other suckless tools confuguration - github.com/bakkeby
seems interesting
Waiting for second chapter with complaining about custom data types, pattern mathing, typeclasses and currying
Which font is that specifically?
Using Haskell without ligatures considered harmful.
it seems I've found another extremely advanced feature rich GUI written in Haskell hmmm
If ghc won't work for you, installing ghc-static fixed it for me
I just read enough example configs to figure out enough for me to get by. Anyway, I am having a small problem with XMonad and Polybar: For some reason on XMonad Polybar tends to Segfault.
Central time is the right time.
what's the point of Int when you have Integer
Is that status bar on top shipped with XMonad by default?
Xmonad doesn't have a builtin bar but there is a bar called Xmobar that's written in Haskell and designed to work with Xmonad.
@@DistroTube Thanks bruh! I really enjoyed your videos. Thanks to your videos (and the community) I switched to ArchLinux since late 2018.
thanks dt
"...LOOKING AT YOU, *LISP* ! '''
what are you using for autocomplete in emacs for haskell?
You might want to get lsp-mode, haskell-mode, haskell-language-server and for example company. That should provide you with great autocompletion plus all kinds of other information and analysis/hints on the fly.
Nice informative video. It's look like you dig in to it ;-]
"I dont really program I just know enough to do things" --an extremely efficient Software Engineer probably
i got 99% in an university coursework in haskell for functional programming and still don't feel I really understand haskell
Have you tried reading a textbook, for me it's the best way to learn a new language. The wiki recommends a few titles wiki.haskell.org/Learning_Haskell#Textbooks
It has some concepts that you just need to work with, like monads. Which actually is used in some Java Script frameworks, but they have not named it that. :-)
@Jeffrey Wolsieffer I'd love to see more code examples so we can better understand _how_ these functions can be used instead of blind luck as we find some obscure repo as the only "practical" example of mapAndUnzipM or something like that
Comjent Komrad!
Im programming on Haskell, but prefer i3, because xmonad is so verbose and more difficult comparing to i3((
On Arch I couldn't find ghci but I installed stack and then ran $ stack ghci
So 'ghci' is the interactive mode of 'ghc' which is the Haskell compiler. So you need to install 'ghc' but you probably already have it if you had installed Haskell or any Haskell program.
Why someone would think about haskell? I wouldn't.
You can just do Ctrl L even in ghci instead of typing clear
44 modNum' = Advil® (Ibuprofen) after this mod section.
Watch in 0.75x ;)
why make it require so much math to learn ?
Ahahah, ty bro :D
heeehee when derek say i'm not a programmer..... i'm LOL....
44:30 is best xd
Next up, clojure
The funny thing is, as soon as you tell me (and quite proudly, I might add) that you primarily run Linux, I already know a ton about you. I know that you have no artistic ability -- that you're not into full-stack or front-end dev (no photoshop), you're not a photographer (no lightroom), and you're not into video editing (no premiere). I know you're not a software entrepreneur, as you would have needed full-stack development for that. I know you're not into remote collaboration with Google Drive (and Dropbox support is being ended soon). I know you're not an iOS developer (no XCode), or mobile developer at all (which generally requires Photoshop). I know you haven't honed your UX/product sense. Even if you dual-boot, I know you're in pain and will probably lose a bunch of data one day and have no idea what happened. You see that? In your search for "freedom," you have boxed yourself in like a caged rat.
This reads like a copypasta, are you serious?
Did you come to a linux channel to say why one shouldnt use linux... Pretty sure there are alternatives to most things you mentioned for linux and also pretty sure that no one here will agree that we feel caged using linux. If you want to use windows because those are the apps you know, no problem, no one is forcing you to use linux. But some people actually value owning their pc and controlling what it does. Some people also value the privacy, speed and efficiency linux gives them and they wont mind learning some apps to do what they need.
Stay in the rotten OS that is windows 10 and just dont mess with us. Everyone has a reason for being in the OS they are so use your stupid arguments about being caged when using linux elsewhere. Our opinions are truly opposite to each other
I guess he was just itching to use this copypasta and figured he would try to fit it in here. I said at the beginning of the video that I am not a programmer by trade, then he posts this novel about how he knows I'm not really a programmer. lol
You need serious help man.
Is that your opinion as a TechLead? The Ex-Facebook, Ex-Google, Ex-Husband, (millionaire) TechLead?
This has been one on the worst explanations of tuples.
Alternatively, learn an actually good programming language like C.
As I wrote, C programmers arw scared of Haskell and functional programming.
Yes, C was the first language I really learned to love, back in 1981, but then there wasn't any ML languages for another 10+ years. I do still like C, but it is an old language, and it shows. Just the aliasing problem is a reason to go to well defined languages like Haskell, OCaml and other more modern languages.
@@AndersJackson BS. C is the closest we can get to assembly while still understanding what we write.
The higher the language the more removed one is from the actual hardware. Yours is the kind of thinking that caused the Java AND JavaScript explosions. C+ and all objective languages have been nothing but errors in the wrong direction. Markup has been worse. Nowadays every high school dropout thinks he can program thanks to all the crappy, under performing, shitty languages that use a markup syntax. Haskell, like python is nothing more then a lazy out for people too stupid/lazy to actually program.
Every language that has come after C has done nothing more then make programming more accessible to people that could have never programmed in C. And when it comes to programming I don't what my programs to be written in accessible language, I want them to be written well - and alas, those two paradigms are usually mutually exclusive.
What next, you're going to say using the likes of Sublime text and VS code to learn to code is a good idea?
@@AlucardNoir excuse me. Mind your manner please. You are talking to adults here, so you should probably not use that language.
Yes, I KNOW that C is a glorified C, yes, I have checked output from many compilers, including C. In many different targets, including PDP11 and forward. Yes, I have even made some smal compilers just for fun.
Higher the language, the closer to how humans and mathematics work, closer to actually be able to prove that programs work. Closer to actually be efficient.
Functional programs is MUCH easier to optimize, as we for one doesn't need to take into acount the aliasing mess i C and other Algol family languages.
And you have obviously NO understandig of ML languages nor functional languages. They are WAY easier to optimize.
Yes, C++ is a mess, so are Java and C#. The problem isn't object orientation, it is that these are basically built on top of C. With all faults of being old (around 1970) language with things that looked nice back then, but are awful now. FORTRAN is to C what C is to Haskell. If you looked and written fortran and looked at the generated code, you would know.
So, if you actually want to make yourself a service, you should look at Haskell. You will become a better coder, even if you stay in C.
I do prefer my old trusted Emacs before I use those VisualCode and whatnot. I have used thm, which even convinced me that they are inferiour to Emacs.
But that is just an editor, if people choses to use Notpad to learn to program, I am fine with that.
Programming is not about elitist mambo jumbo like what you seems to think. I am actually sorry for you, in that regarde. But I think you don't know better. And some find meaning being elitsts, and think that makes them a better human and less of an arse.
(Yes, C is a nice language, but it is outdated when it comes to programming languages, and it shows)
@@AndersJackson Firstly, that's a funny first paragraph. Especially considering the care we take to make sure children don't swear. Dunno on what planet you're from but on good 'ol Terra most people that do swear are, how did you put it, adults. Manners, etiquette and taboos can go fuck themselves. Metaphorically of course.
Now, regarding that crap you were spouting about how functional language are easier to optimize. Well, yeah, they are, except most people that program in them don't actually do that. And that's the point. They're easier to pick then C and so people that have no idea how programming works pick them up and start programming under performing crap. That doesn't happen in C because C is a lot less lenient with programmer errors. As for markup languages being easier to optimize... that's a mice fable you're telling there friend, but markup is not synonymous with functional.
As for VS code I only brought it up because most people that do use it do so because of all the ease of life features it brings with it. Features that are great if you are a programmer and don't want to bother closing every bracket but horrid if you're learning a language and become careless and sloppy with your code because the text editor does half of the job for you.
C is the best language in a mono-core world. But how are you going to keep up on a 32-core machine?? :)