Recursion - To hone a skill, one must practice.

preview_player
Показать описание
Thank you all for watching! If you want to see more of this, consider subscribing!

In this video we will talk about recursion and how Haskell forcing it upon you is an opportunity to practice working with it. We will also look into how lists work in Haskell, and how these two design choices go hand in hand.

Since this video covers a topic that has many strong opinions, I want to make clear that I do not appreciate flaming or irrational discussion in the comments. If you think I or someone else is wrong, be discrete and provide a source if you can.

========================================================

Fonts used:
- Headings: Comfortaa
- Body: Lexend Deca
- Code: Maple Mono

Color scheme: Ayu Mirage

Software used:
- PowerPoint
- Premiere Pro

#haskell #functionalprogramming #programming #tutorial #recursion #lists #code #coding #linkedlists
Рекомендации по теме
Комментарии
Автор

Recursion: If you don’t understand, see Recursion

sarahclark
Автор

Please keep this series going, your teaching style is very good, concise and easy to follow along.

Can't wait for the monads video.

itme_brain
Автор

Never knew I needed Haskell in my life, now I want more.

wackyator
Автор

I have been flirting with getting into Haskell and fp for years now and your excellent teaching style is the sign that now is the time. Thank you very much :)) <3

artursbumbieris
Автор

Just started learning haskell today, and I was doing the practice examples at the end. Finally getting and understanding the 'sorted' function was so exciting! It feels like the kick I got from first learning to code all over again

dublUayaychtee
Автор

I wish these videos existed when I had to learn Haskell for my advanced programming languages course! Great stuff!

netcat
Автор

8:08 IIRC haskell compiler (ghc) will often turn recursive functions into their imperative equivalent, if it's possible. so you can write recursive functions and the compiler will turn them into optimized loops. so saying that they are "always slow" is misleading

qwfp
Автор

You make some incredible content, thanks ! I heard that haskell do some optimisation when compiling the recursion to make it's perforances similar to a classic loop. Rust has this functionality: using a for loop or a chain of higher order functions give the same assembly code.

fabricehategekimana
Автор

These videos are great! Subbed and looking forward to more

Linuxhype
Автор

based haskell user (youre very cool peppi)

Treston-riof
Автор

Keep up the good work! Waiting for more

kamilzielinski
Автор

What do you mean by linked lists resulting in less memory fragmentation? I can't come up with any mechanism or workload by which a linked list would result in less memory fragmentation than an array-based list

krappa
Автор

4:09 > _"UTH, Haskell lists look like this"_

wait, this looks (syntax) & sound (name) like lisp lists.

yash
Автор

There is *lots* of overhead in the for loop you showed to begin with, specifically on the programmer's side! Compare:

int factorial(int n) {
int product=1;
for (int factor=1; factor<=n; factor++)
product*=factor;
return product;
}

factorial :: Int -> Int
factorial n = product [1..n]

Why should the programmer repeatedly explain to the compiler how to iterate through numbers every time they want to handle any sort of sequence? It's even done with the full expectation the compiler will recognize the pattern and discard those details, in order to perform optimization like using CPU flags, unrolling, vectorization etc; which means there's another load of overhead on the compiler's side. And then you still have to elaborate for some of those, like #pragma omp reduction (* : product).

LoneTech
Автор

can someone tell me who graham mutton is i found graham sutton, graham hutton but not a graham mutton.

awabkhan
Автор

This video is so starkly different from the conclusions I've come to in my work experience that it was a little jarring. Great video and I can understand how one would arrive at using recursion more, but based on my work experience I try to avoid recursion at all costs. I have found that recursion tends to tie knots in my code that only get worse over time. I find iterators and their associated for loops to be much more intuitive, and even figured out how to handle trees without recursion by instead building tree-based iterators.

mradult
Автор

Wait, isn't there a massive crashing bug in the factorial code? If i call "factorial (-1)" it will infinitely recurse and never stop. How is this an acceptable coding feature? Surely, the function domain should be limited to unsigned integers (Z+) rather than all Integers?

gregoryfenn
Автор

6:55 I think for the take 0s, doing just `take 0 n = []` here should suffice? Not sure why it needs to be two cases

Edited nvm I paused too fast and jumped the shark lol

opposite
Автор

My solutions to the last exercises:

fibb 0 = 0;
fibb 1 = 1;
fibb n = fibb (n - 1) + fibb (n - 2)

elem2 n [] = False
elem2 n (x:xs) = (x == n) || elem2 n xs


isSorted [] = True
isSorted [x] = True
isSorted (x:y:xs) = x < y && isSorted (y:xs)

ChainOfCommand
Автор

Its funny how Haskel uses church numerals to even go as far as evaluate numbers in a list of N lazily

LordErnie