Infinite Data Structures: To Infinity & Beyond! - Computerphile

Infinite data structures sound impossible. Professor Graham Hutton shows how laziness can win them over.
EXTRA BITS: • EXTRA BITS: Infinity &...
/ computerphile
/ computer_phile
This video was filmed and edited by Sean Riley.
Computer Science at the University of Nottingham: bit.ly/nottscomputer
Computerphile is a sister project to Brady Haran's Numberphile. More at www.bradyharan.com

Пікірлер: 482

  • @BatteryAcid1103
    @BatteryAcid11035 жыл бұрын

    I feel like I just watched a 15 minute commercial for Haskell..

  • @RedwoodRhiadra

    @RedwoodRhiadra

    5 жыл бұрын

    That describes every one of Hutton's videos on this channel.

  • @Vekkq

    @Vekkq

    5 жыл бұрын

    try it. ;)

  • @recklessheroism2885

    @recklessheroism2885

    5 жыл бұрын

    That describes every conversation with every Haskell programmer I've ever had

  • @TheSpacecraftX

    @TheSpacecraftX

    5 жыл бұрын

    All of this guy's videos are like that.

  • @robchr

    @robchr

    5 жыл бұрын

    It's free :-)

  • @fogglee
    @fogglee5 жыл бұрын

    For anyone interested, this can be done in C# with IEnumerable and the keyword 'yield'. Essentially you can "describe" a list and a function will yield the next value on demand.

  • @piotrarturklos
    @piotrarturklos5 жыл бұрын

    One of the most clear explanations of anything that I've ever heard.

  • @bernardo013

    @bernardo013

    5 жыл бұрын

    I don't know why this comment has me laughing so hard lolol, but I couldn't agree more.

  • @bchertel

    @bchertel

    5 жыл бұрын

    Professor Hutton is a fantastic teacher. The Lambda Calculus video is another prime example of his comprehension of the concepts and how to convey the knowledge effectively.

  • @Giacr45

    @Giacr45

    5 жыл бұрын

    Unfortunately in the end they made a huge mistake. They claim to have implemented the Sieve while the algorithm implemented is just smart trial division (the Sieve does no modulo operation. It uses a prime to rule out known *composites*, while the algorithm here simply checks for each number if it is a multiple of a prime we found before which is asymptotically slower). This shows how subtle mistakes can be in math&computer science and make tons of other people fall for them even when explained slowly and clearly.

  • @Xnoob545

    @Xnoob545

    5 жыл бұрын

    Agreed

  • @piotrarturklos

    @piotrarturklos

    5 жыл бұрын

    @@Giacr45 Is it slower because of the time complexity of modulo operation which is higher for arbitrarily large numbers? Or is it slower because it checks every number for being a multiple of every smaller prime? I believe the answer to the second question is negative, so it leaves the first one. I don't have time to analyse further but it does appear that it might be a problem for infinite sequences.

  • @tomiplaz
    @tomiplaz5 жыл бұрын

    Simple and beautiful. Also, this professor is a joy to listen to. He gives very clear and concise explanations.

  • @smuecke
    @smuecke5 жыл бұрын

    It’s a pleasure to listen to Prof. Hutton, he speaks clearly, well-structured and without ever saying “um” or anything. Also I love your videos on Haskell, it’s an elegant language that deserves a broader audience!

  • @themeeman

    @themeeman

    5 жыл бұрын

    Hes got quite a gift, I don't even think hes reading from a script

  • @morgansearle3912

    @morgansearle3912

    5 жыл бұрын

    True, but his accent is making me so curious, it's like Scottish-adjacent or something and I can't wrap my head around it

  • @michaelsommers2356

    @michaelsommers2356

    5 жыл бұрын

    @@morgansearle3912 'Hutton' is a toponymic surname from Scotland, specifically from Berwickshire. That, of course, doesn't mean that he is from there, just his name is.

  • @BenjaminGoldberg1

    @BenjaminGoldberg1

    5 жыл бұрын

    How do you know he doesn't edit out his "um"s?

  • @haskellhutt

    @haskellhutt

    5 жыл бұрын

    I’m from Glasgow, but have spent some time in Australia, Sweden, The Netherlands, and England, so my accent is a bit all over the place! But I hope it still sounds a bit Scottish :-)

  • @StevieRZ
    @StevieRZ5 жыл бұрын

    "infinite list of twin primes" - do you have a secret proof you're keeping hidden from us all?

  • @aka5

    @aka5

    5 жыл бұрын

    yes, just let the program run forever.

  • @StevieRZ

    @StevieRZ

    5 жыл бұрын

    :')

  • @aliedperez

    @aliedperez

    5 жыл бұрын

    @@aka5 and make sure you're using very wide integers :-)

  • @aaronsmicrobes8992

    @aaronsmicrobes8992

    5 жыл бұрын

    @@aliedperez if you use the Integer type instead of Int, it uses arbitrarily wide integer values. Perfect for infinity, so long as you have enough RAM.

  • @mdogboy

    @mdogboy

    5 жыл бұрын

    I have discovered a truly marvelous proof of this, which this margin is too narrow to contain.

  • @martixbg
    @martixbg5 жыл бұрын

    As a classical programmer, this is blowing my mind and making me wanna pick up Haskell.

  • @MrTortsen

    @MrTortsen

    5 жыл бұрын

    They have a browser-based tutorial directly on the Haskell landing page. Fills around 1/2h.

  • 5 жыл бұрын

    just learn the functional part of Java :)

  • @zitt4147

    @zitt4147

    5 жыл бұрын

    ​@ That is just as cool as it is horrible when you think of all those function objects and garbage collection

  • @user-tx4wj7qk4t

    @user-tx4wj7qk4t

    3 ай бұрын

    ​@@zitt4147literally who cares Christ you're making CRUD apps

  • @harriehausenman8623
    @harriehausenman86235 жыл бұрын

    Very understandable english, clear presentation and formidable examples!

  • @davidefara5983
    @davidefara59835 жыл бұрын

    This video was extremely enjoyable and interesting. Prof. Hutton was extremely clear and concise in his explanation. Hope to see more content from him. Thank you for this video. It kind of made me want to try to approach functional programming once more.

  • @twistedsim
    @twistedsim5 жыл бұрын

    Professeur Graham, you are such a great presentator ! It makes this video very enjoyable to watch. Thank you.

  • @davide12397
    @davide123975 жыл бұрын

    This makes me want to learn Haskell SO MUCH!

  • @framegrace1

    @framegrace1

    5 жыл бұрын

    One does not simply learn Haskell

  • @Masterplan79th

    @Masterplan79th

    5 жыл бұрын

    @@framegrace1 One does simply learn Haskell, check out the book "Learn you a Haskell for great good"

  • @kleavenae

    @kleavenae

    5 жыл бұрын

    You can do exactly this with Java. Check Stream API. Update: I was wrong. I couldn't implement this in Java. The Stream API has a lot of deficiency. You can do this in Scala though. Or in Java using the jOOL library.

  • @qzbnyv

    @qzbnyv

    5 жыл бұрын

    @@Masterplan79th One just bashes one's head repeatedly against the compiler's type checker until it compiles. But once it does, it runs ;)

  • @FF_Fanatic

    @FF_Fanatic

    5 жыл бұрын

    @@kleavenae You should be able to. Streams include the filtering etc. and the starting infinite stream can be generated via Stream.iterate, e.g., Stream.iterate(1, i -> i + 1) for [1..]. I'd expect most stream/sequence/range libraries across langauges nowadays to handle infinite streams, just through a method other than Haskell's inherent laziness.

  • @stirnermax11
    @stirnermax114 жыл бұрын

    I'm learning a bit of Haskell with the help of the book "Programming in Haskell", can you imagine how surprised i was when i realized the man in the video IS the Graham Hutton author of the book?! Btw i strongly recommend his book, a very clear and fun introduction to Haskell. As other people in the comment section I would definitely enjoy to see more videos with the professor

  • @haskellhutt

    @haskellhutt

    4 жыл бұрын

    Glad you are enjoying the book Mario :-)

  • @MartinLeggewie
    @MartinLeggewie5 жыл бұрын

    Thank you very much for this video about this very elegant way of programming in a functional language. And kudos to Mr Hutton for his friendly, relaxed, controlled, and - most important - understandable way of explaining this topic.

  • @lemonprime7889
    @lemonprime78895 жыл бұрын

    I'm really enjoying Brady's editing in this one.

  • @Not.Your.Business

    @Not.Your.Business

    5 жыл бұрын

    you mean Sean's editing...

  • @mikeg9b
    @mikeg9b5 жыл бұрын

    I love the videos with Graham Hutton and Haskell.

  • @benoitb.3679
    @benoitb.36793 жыл бұрын

    This was supremely interesting, thank you. I'm glad others have picked up on his excellent presentation too.

  • @mateja176
    @mateja1765 жыл бұрын

    Brilliant video, we'd like more!

  • @andreaaristokrates9516
    @andreaaristokrates95165 жыл бұрын

    Thank you for showing this, it's really neat and I hope I might one day find a use for this, hopefully in chemistry, which I study; but at least my brain will have one more concept to play around with.

  • @Micetticat
    @Micetticat5 жыл бұрын

    Fantastic introduction to Haskell!

  • @PanicProvisions
    @PanicProvisions5 жыл бұрын

    Great video, glad I've watched it.

  • @wliaputs
    @wliaputs5 жыл бұрын

    For those who don't understand list comprehension, the sieve program can be written as follows using filter instead: primes = sieve [2..] sieve (p:ps) = p : sieve (filter (\x -> x `mod` p /= 0) ps)

  • @paprika5487
    @paprika54875 жыл бұрын

    Functional programming is a wondrous thing, isn't it?

  • @Pat315

    @Pat315

    2 жыл бұрын

    Bro it's like four lines of code. Take your cringe elsewhere.

  • @suponjubobu5536

    @suponjubobu5536

    Жыл бұрын

    @@Pat315 The wondrous thing is that it takes four lines of code to do what C would take 20 to do, with much uglier syntax, and no polymorphic re-usability for the code creating laziness.

  • @stopper0203

    @stopper0203

    11 ай бұрын

    @@Pat315 Haskell is the mathematicians language

  • @Pat315

    @Pat315

    11 ай бұрын

    @@suponjubobu5536 stop being such a virgin

  • @nahco3994
    @nahco39945 жыл бұрын

    This should definitely be cross-posted to the Numberphile channel.

  • @AndrewSmithDev
    @AndrewSmithDev5 жыл бұрын

    this was great. I'd love to see more videos with actual code

  • @kyoung21b
    @kyoung21b5 жыл бұрын

    This is enough to turn someone into an intuitionist !

  • @amaarquadri
    @amaarquadri3 жыл бұрын

    With an object oriented programming language using the sieve of eristothanes and making it dynamically increase as more output is required would be way more complicated. This is awesome!

  • @saugatpaudel8777
    @saugatpaudel87775 жыл бұрын

    'Just search for the obvious thing' 😂😂

  • @casperes0912
    @casperes09125 жыл бұрын

    This is the first time I've thought Haskell looks elegant.

  • @GhekoLeap
    @GhekoLeap5 жыл бұрын

    Whoever edited the thumbnail made a huge mistake. Buzz Lightyear's ICONIC balaclava covers his entire head. Not just his neck. Nice try.

  • @Faramik2000

    @Faramik2000

    5 жыл бұрын

    Real buzz friends represent

  • @preferredimage

    @preferredimage

    5 жыл бұрын

    If that's what you are taking away from this video, you may have missed the point of this video.... :)

  • @peteranderson037

    @peteranderson037

    5 жыл бұрын

    @@preferredimage It may not be the only thing in this video, but it is the most important thing.

  • @Thegamecheats

    @Thegamecheats

    5 жыл бұрын

    @@preferredimage without buzz lightyear there is no hascall there are no dreams

  • @AlexKnauth
    @AlexKnauth5 жыл бұрын

    Laziness is awesome! I’ve used it to make minimax game tree searches in a much more natural way than I would otherwise. Separating control from data really helps in those situations

  • @afr0z
    @afr0z2 жыл бұрын

    It looks like Haskell is pretty efficient for writing codes for numerical computation. In 2 line you wrote Sieve of Eratosthenes

  • @bman77717
    @bman777175 жыл бұрын

    "The first step is to write down the infinite list all the way up to infinity." Yeah, lemme just do that real quick. *never gets to step 2*

  • @snbeast9545
    @snbeast95455 жыл бұрын

    2:32 So no proof that 1 + 2 + 3... = -1/12?

  • @Bratjuuc

    @Bratjuuc

    4 жыл бұрын

    I don't think you're gonna believe me, but 1 +2 +3+... does not equal to -1/12. In fact, this sum doesn't equal to any number, because it diverges

  • @jogiff

    @jogiff

    3 жыл бұрын

    Артём Мухамед-Каримов МПБ-802 based and redpilled

  • @weirdwordcombo
    @weirdwordcombo5 жыл бұрын

    I know C# copied the functional languages here but Haskel really reminds me of LINQ and enumerables in C#, except without the pureness and elegance. But nevertheless kind of shocking how I intuitively understood all the programming without ever once having written Haskell.

  • @up4life108

    @up4life108

    5 жыл бұрын

    Alot of functional concepts are adapted in other languages. Even monads which are irritating for most newcomers in Haskell are actually quite deeply built in to languages such as javascript (async/await)

  • @Abhothra
    @Abhothra5 жыл бұрын

    More like this please that was very interesting. (Even in a language which I don't "Speak" as it were)

  • @dynamicgecko1213
    @dynamicgecko12135 жыл бұрын

    I am just fascinated by how practical Haskell is. I always thought of it as an old, assembly-like language. Now I want to learn more haskell or see if python can do this as well.

  • @Games-mw1wd

    @Games-mw1wd

    5 жыл бұрын

    Melih Durmaz Don't confuse Haskell with Pascal...

  • @antonlindstrand8062
    @antonlindstrand80625 жыл бұрын

    This was actually really cool!

  • @fuzzblob
    @fuzzblob5 жыл бұрын

    Wow! Its fascinating how many languages really constrain what programmers can even think about.

  • @robertkelleher1850
    @robertkelleher18503 жыл бұрын

    It would have been nice if he would have explained how the lazy evaluation and recursion actually works together. He simply stated "it removes all of the multiples of 2." No it doesn't. It removes them when it needs to, but he completely glossed over that part.

  • @MichaelLikvidator
    @MichaelLikvidator5 жыл бұрын

    Was so impressed. Decide to implement it in python: def inf_numbers(start_with): while True: yield start_with start_with += 1 def sief(iterator): prime = next(iterator) yield prime while True: yield next(sief(i for i in iterator if i%prime!=0)) primes = sief(inf_numbers(2)) list(islice(primes, 1000)) UPD: After reasonable comments code become simpler from itertools import islice, count def sief(iterator): prime = next(iterator) yield prime yield from sief(i for i in iterator if i%prime!=0) primes = sief(count(2)) list(islice(primes, 10)) But this version will work slower and because of yield from instruction will fail to get more than 1500 primes due to fact of maximum recursion. Where first sief implementation will work well on bigger size of iterations.

  • @khai96x

    @khai96x

    5 жыл бұрын

    Too complicated! This one is simpler: def sieve (prime = None, *rest): if not prime: return [] return [prime, *sieve(*[x for x in rest if x % prime != 0])] primes = sieve(*range(2, 30))

  • @MichaelLikvidator

    @MichaelLikvidator

    5 жыл бұрын

    @@khai96x Yep, your simpler, but my implementation aimed to use infinite generator, I can iterate through it forever, and it used lazy evaluation as in original code on haskell, where yours code will be evaluated on passing into function.

  • @khai96x

    @khai96x

    5 жыл бұрын

    @@MichaelLikvidator Fair enough, but your code can still be simplified: Remove 'while True', use 'yield from'

  • @MichaelLikvidator

    @MichaelLikvidator

    5 жыл бұрын

    @@khai96x Thnx

  • @slash_me

    @slash_me

    5 жыл бұрын

    Also, python already has inf_numbers, it's called range

  • @harleyspeedthrust4013
    @harleyspeedthrust40133 жыл бұрын

    I absolutely love functional programming. Definitely my favorite paradigm

  • @kadirgunel5926
    @kadirgunel59262 жыл бұрын

    This was great.

  • @Rchals
    @Rchals5 жыл бұрын

    That's why I love python generators and list comprehension

  • @Axman6

    @Axman6

    5 жыл бұрын

    Ricard Miras I believe these are both features inspired by Haskell.

  • @shaylempert9994

    @shaylempert9994

    5 жыл бұрын

    Exactly what I thought

  • @wliaputs

    @wliaputs

    5 жыл бұрын

    List comprehension is inspired by math

  • @noder8867

    @noder8867

    4 жыл бұрын

    @@wliaputs Yeah but I mean, the entirety of functional programming is based on mathematical functions so that goes without saying. List comprehensions correspond more precisely with the set generator notation.

  • @ishdx9374
    @ishdx93743 жыл бұрын

    2:15 note that most of the time is actually spent on outputting into stdout, so its a lot quicker

  • @recklessroges
    @recklessroges5 жыл бұрын

    This is my favourite Prof Hutton video to date. (Daaaay'm Haskell is elegant. Its so sexy that it feels impossible.)

  • @bagelmanb
    @bagelmanb5 жыл бұрын

    would it be possible to do a video explaining how haskell is actually able to keep track of these things in execution? As it runs through the infinite execution, what is it actually storing in the (finite) physical memory? If you left the program running for a long enough time, would it eventually run into errors from the finite physical constraints of the hardware it was running on?

  • @musikSkool
    @musikSkool5 жыл бұрын

    I made my sieve in C++ a few years ago, I did double prime steps to reduce the processing needed, and used a list of booleans to save on ram usage. In about a second or two I could output a file with a list of all the primes up to 100,000,000. This looks like fun, but when you want speed you really need to tweak the process on a lower level.

  • @Games-mw1wd

    @Games-mw1wd

    5 жыл бұрын

    Note that Haskell boxes integers and uses bigints by default. Both of these slow the program down. There is a data type called Word representing machine-precision integers, and there are also GHC-specific options for unboxed integers. It's not pretty, but you can do low-level stuff. That kind of speed isn't the default, but it is possible.

  • @randall172

    @randall172

    5 жыл бұрын

    why not just build a dedicated chip that computes primes, that would be faster than any software solution on consumer chips

  • @musikSkool

    @musikSkool

    5 жыл бұрын

    If you really needed a list of primes, I'm sure someone has a few gigabyte file somewhere with a really really long list. The question becomes how fast do you want to search it, and how many Primes do you need stored in RAM for very fast access. I smell a new type of encryption that requires computers with a list of 200 GB of primes in system memory, because it needs to lookup and sum millions of primes to decode messages. An SSD would be way too slow to decode a message. One method, add a bunch of padding to a 1 kb message to get it to 100 kb. Convert it to a number. Start subtracting very very big primes. Make a list of the primes you subtracted from it. To decode you would need to be able to look up primes by their location in the list. Example decoded message: "this is a secret" Example coded message: 2, 3, 4, 12, 21, 25, 88, 143, 2975, 10278, 172193, To decode you take the second prime, 3rd prime, 4th prime etc, and add them all together, then convert from a number to a string with a simple perfect hash function.

  • @rhclash
    @rhclash5 жыл бұрын

    Except that this is *not* the sieve of Eratosthenes, because he uses mod, i. e. division. Do it with pen and paper and you will never divide anything. Division makes this algorithm a different and more expensive one.

  • @evanbelcher
    @evanbelcher5 жыл бұрын

    Damn I haven't looked at Haskell before but it's easy to see how optimized it is for this type of work. Really cool language!

  • @rkpetry
    @rkpetry5 жыл бұрын

    *_...do you compose your programs in UTF∞..._* *_...I recall hearing that a Honeywell machine did infinite-byte-strings, ca 1970's..._* *_..."eager...lazy" translates to "greedy...nongreedy" in Amer. JavaScript RegExp..._* *_...((do the Brits calls it, 'Kavascript...Avascript...' I prefer just "script" anyway))..._*

  • @Rebel_Guy
    @Rebel_Guy5 жыл бұрын

    If he goes into the function recursively how come he doesn't get a stack overflow eventually?

  • @axelluktargott

    @axelluktargott

    5 жыл бұрын

    "tail call optimization". The compiler (or interpreter in this case) converts it to a loop under the hood

  • @Axman6

    @Axman6

    5 жыл бұрын

    Axel Ulmestig there’s no specific optimisation in Haskell for tail calls, all calls to functions are simply jumps to that function, which gives tail call optimisation for free if the function called in the tail is a recursive call. This means you get the same “optimisation” in mutually recursive loops too, f x = ... g y; g x = ... f y is no different to direct recursion.

  • @Games-mw1wd

    @Games-mw1wd

    5 жыл бұрын

    Alex Mason I don't think that's entirely true. For example, in the function f x = sqrt (exp x) It would be ok to jump to sqrt but not to exp. If you jumped to exp, you would never call sqrt, so you would return the wrong thing unless you remembered to jump back at the end, which requires a call stack.

  • @Axman6

    @Axman6

    5 жыл бұрын

    Games14159 GHC’s implementation of Haskell does not use a call stack, it uses a stack of evaluations - you’re forgetting that Haskell is lazy, so the evaluation is actually sqrt , so sqrt will jump to exp and push its computation onto the stack of evaluations to perform after exp has been evaluated. If you look at the code produced by GHC, there are no call or ret instructions generated for Haskell functions. We have a stack, but it is not a call stack.

  • @Games-mw1wd

    @Games-mw1wd

    5 жыл бұрын

    Alex Mason So it’s not exactly a call stack, and it’s not the processor’s stack; it’s a stack of computations. TIL, thanks!

  • @drakeblood4
    @drakeblood45 жыл бұрын

    Oh dope I actually used the Sieve of Eratosthenes in a Discrete Structures class for doing some simple public key decrypting.

  • @williammorton8555
    @williammorton85555 жыл бұрын

    Curious, what about time complexity when using an infinite set? What happens when I want prime numbers (not pseudoprime ) of n bits, n>100 ?

  • @p0gr
    @p0gr3 жыл бұрын

    will the twin result in all the primes getting generated twice, or is the zip with tail smart enough to use the same list?

  • @maxmusterman3371
    @maxmusterman33715 жыл бұрын

    very nice

  • @superscatboy
    @superscatboy5 жыл бұрын

    Videos like this make me want to learn Haskell, but then I wonder what I'd ever use that knowledge for.

  • @benjaminclehmann
    @benjaminclehmann5 жыл бұрын

    Infinite Data Structures are quite practical... Yeah, for a problem which is fundamentally infinite, in circumstances where infinite runtime is acceptable. In other words, if you already have to deal with infinity, more infinity doesn't hurt. I'm disappointed that it doesn't pose any of the use cases of infinite data structures on a less conventional problem for them, such as a finite problem.

  • @MadocComadrin

    @MadocComadrin

    5 жыл бұрын

    Benjamin Lehmann You can get more practical. If you have a stream of data that you can only process online, and you're not sure how long it will be, you can express transformations on the entire stream in a similar way.

  • @zoikles1
    @zoikles15 жыл бұрын

    How long does the program run before the macbook runs out of memory?

  • @ekaingarmendia
    @ekaingarmendia5 жыл бұрын

    I just realized that I love Haskell

  • @yodyl9811
    @yodyl98115 жыл бұрын

    What I dont understand is, the language was not able to close the search for values below 100 since it didn't know there are not going to be any more values below 100 since the list goes on and on. So how can it move on from dividing by 2 in the last example to dividing by 3? How does it know there are no more values that can be divided by 2?

  • @MadocComadrin

    @MadocComadrin

    4 жыл бұрын

    It never actually completes the first pass of dividing by two. It does just enough--one element at a time--to get the elements you need. That's part of how the lazy evaluation works.

  • @soniablanche5672
    @soniablanche56725 жыл бұрын

    You can do that in any programming language. The trick is to not generate the list internally unless the user calls a function on the list.

  • @mytech6779
    @mytech67795 жыл бұрын

    Lazy evaluation is convenient for specific cases but it should be noted that it will substantially slow a program that repeatedly uses the same data structure, in fact lazyness/eagerness in a language is analogous to the larger choice of interpret/pre-compile. When I say repeatedly I mean millions or billions of iterations, recursions, or general laps around a loop, which is something that would likely be encountered more often in programs that would choose a fully pre-compiled language than in programs that would choose an on-demand interpreted language.

  • @timh.6872

    @timh.6872

    5 жыл бұрын

    Haskell can be compiled, but does suffer performance and stable ABI problems even when compiled. I think the solution to this is to discover a parallel to DeMorgan's laws for actually infinite structures and arbitrarily large finite structures that would allow for some "conjunctive normal form" where all the infinity is at the outermost level and each "step" can be eagerly evaluated while the OS manages the laziness with a scheduling algorithm.

  • @user-tx4wj7qk4t

    @user-tx4wj7qk4t

    3 ай бұрын

    What in the world are you talking about and what is your obsession with performance

  • @user-tk2jy8xr8b
    @user-tk2jy8xr8b4 жыл бұрын

    The cooler thing is that `tak 5 [1..]` doesn't even evaluate the values of the list, it evaluates to something like [_, _, _, _, _] where each _ is a delayed computation which is resolved by the `show` function when you print the list into the console

  • @hz916
    @hz9165 жыл бұрын

    What is the O() of this program?

  • @poke_champ
    @poke_champ5 жыл бұрын

    immediately when i saw his face I said, "Its this Haskell dude again oh no"

  • @Furiends
    @Furiends5 жыл бұрын

    It's important to understand that "infinite" data structures can never be totally evaluated hints why they only work with lazy evaluation. Further the juxtaposition of infinite and data structures only makes any sense in languages where function and structure are the same thing called purely functional. Normally data structure is separate from function so lazy evaluation is accomplished with generators instead. However purely functional languages trade off random access for procedural access. It would seem Haskel would be the holy grail for complicated 3d rendering but this procedural trade off would make them excruciatingly slow. Which is why imperative object-oriented is best for game design. You can have both extremely complex data structures while also maintaining random access.

  • @user-tx4wj7qk4t

    @user-tx4wj7qk4t

    3 ай бұрын

    Completely wrong, you don't know that functional has entirely different data structures that have data sharing and is far better at parallelism. Also almost no games require anything close to cutting edge

  • @luisandraschnik3001
    @luisandraschnik30012 жыл бұрын

    Python code, Haskell inspired : from itertools import count, islice def factors(x): yield from (i for i in range(1, x + 1) if x % i == 0) def is_prime(x): yield list(factors(x)) == [1, x] def primes(n_first): yield from islice((i for i in count(2) if is_prime(i)), n_first) for prime in primes(100000): print(prime)

  • @doougle
    @doougle5 жыл бұрын

    Why does the sieve program not hang trying to remove every number divisible by two the way the earlier program hung looking for numbers less than 100?

  • @vp4744

    @vp4744

    5 жыл бұрын

    Because the list keeps feeding it successive numbers, where as in the former, the list stops at 100.

  • @Envergure
    @Envergure5 жыл бұрын

    What causes that wavy banding in the sunlight in the window?

  • @Dust599
    @Dust5995 жыл бұрын

    Haskell!! shudder, I still have nightmare about this language, and I studied it 20 years ago!!!

  • @Bratjuuc

    @Bratjuuc

    4 жыл бұрын

    What happened?

  • @insertoyouroemail
    @insertoyouroemail5 жыл бұрын

    chills

  • @dxutube
    @dxutube5 жыл бұрын

    Brilliant

  • @sudharshantr8676
    @sudharshantr86763 жыл бұрын

    at 13:47 how did takeWhile statement take a finite amount of time to find the numbers less than 100 from an infinite list and at 3:22 filter operation failed to submit the answer of all numbers in the infinite list less than 100 in finite amount of time?

  • @MeesyIce

    @MeesyIce

    2 жыл бұрын

    takeWhile runs as long as a Boolean is True in this case (

  • @lazerbrainzz
    @lazerbrainzz5 жыл бұрын

    lol let’s try summing infinity. I love you!

  • @SlipperyTeeth
    @SlipperyTeeth5 жыл бұрын

    Fun fact, this is technically a proof about the Riemann Hypothesis. You just have to show if it's for or against.

  • @Raobledoesstuff
    @Raobledoesstuff5 жыл бұрын

    Hey guys!! I really love your videos but I’ve got hearing comprehension issues so they’re hard for me to understand. If it’s not too much to ask, could you guys possibly add subtitles? I’m a computer science major and I’d really love to be able to fully enjoy your videos!!

  • @haskellhutt

    @haskellhutt

    5 жыл бұрын

    Subtitles for the main video and extra bits are now up. It takes a few days for these once the videos come out as they are done by hand.

  • @HebaruSan
    @HebaruSan5 жыл бұрын

    In C#, define your function as returning IEnumerable and then use "yield return" to send back the values. (Yes, Haskell's way is way better. But some of these ideas are starting to leak out into the mainstream.)

  • @Axman6

    @Axman6

    5 жыл бұрын

    There's a heck of a lot of Haskellers working on various C# things at Microsoft and Microsoft Research - Linq is famously inspired by haskell's use of Monads.

  • @jrgenolsen3290
    @jrgenolsen32902 жыл бұрын

    why cant you make a playlist with Graham Hutton :( they are not grouped!

  • @dustinking2965
    @dustinking29655 жыл бұрын

    I don't think I would have understood most of this if I hadn't used Lisp (for head/tail), Python (for generators), and been exposed to pattern matching in Erlang or Prolog. I didn't quite follow the syntax of sieve, even though I've implemented it before in other languages.

  • @kingsgard3000
    @kingsgard30005 жыл бұрын

    how does the program know, that it finishes searching primes less than 100 at 13:43 but does not know, if it finishes searching all numbers less than 100 at 03:16? isn't it contradictory?

  • @VinceOfAllTrades

    @VinceOfAllTrades

    5 жыл бұрын

    The "takewhile" terminates upon reaching its condition, so as soon as it hits a single item in the list >100 it's done. If the list weren't sorted, it most likely wouldn't give a complete answer.

  • @bluekeybo
    @bluekeybo5 жыл бұрын

    Why did the program stop when using takeWhile

  • @pedrovasconcelos8260

    @pedrovasconcelos8260

    5 жыл бұрын

    takeWhile stops when the condition fails so it terminates even with the infinite list; filter tries to find all values that satisfy the condition

  • @bluekeybo

    @bluekeybo

    5 жыл бұрын

    @@pedrovasconcelos8260 Thanks!

  • @Vallee152
    @Vallee1523 жыл бұрын

    I was expecting the two line program for generating all the primes out of the infinite list to get stuck dividing numbers by 2

  • @joansalazar5884

    @joansalazar5884

    3 жыл бұрын

    Yes, I dont understand why that didnt happen?

  • @Dorumin

    @Dorumin

    3 жыл бұрын

    Why would it get stuck? It's merely a filter on top of a map, it's generating one list of factors per number and if it's higher than two it's not a prime, I don't see a possibility for an infinite loop to get stuck on (besides the infinite counter iterator, of course)

  • @robertkelleher1850

    @robertkelleher1850

    3 жыл бұрын

    @@Dorumin Which, although explained well, is kind of unseen here. The trick is lazy evaluation. Haskell hides that. Sometimes explicit is better than implicit.

  • @Dorumin

    @Dorumin

    3 жыл бұрын

    @@robertkelleher1850 Which is why i love Rust iterators, that have a very clean implementation and it's always completely transparent. Just a next() method

  • @grainfrizz
    @grainfrizz5 жыл бұрын

    2:30 should've given us -1/12

  • @shiroyasha_007

    @shiroyasha_007

    5 жыл бұрын

    Daniel Astillero Numberphile crossover alert.

  • @Delta8Raven

    @Delta8Raven

    5 жыл бұрын

    Numberphile's proof of it was wrong (specifically the very first identity they stated was wrong, from which they derived everything else). Unsurprisingly the sum of all natural numbers doesn't actually converge.

  • @shiroyasha_007

    @shiroyasha_007

    5 жыл бұрын

    Debated

  • @lachlankuhr806

    @lachlankuhr806

    5 жыл бұрын

    Analytical continuation provides us the result of -1/12

  • @shami1kemi1

    @shami1kemi1

    5 жыл бұрын

    Ehh... the analytic continuation thing is the sort of deal where you cannot apply the form of the zeta-function defined for x over 1 for inputs less than or equal to 1. I.e. we don't know if the zeta function applied to -1 actually looks like 1+2+3+4+..., which would be suggested by zeta(x) = 1^-x + 2 ^ -x + ..., but that definition only works for x > 1. Besides, the sum of all natural numbers clearly diverges.

  • @FlameRat_YehLon
    @FlameRat_YehLon5 жыл бұрын

    C# is lazy when using IEnumerables and yields, and thus same thing could be done. The only down side is that it doesn't come with most functional programming list operations so you have to either write your own, or just download a library from nuget. And, it's kinda less clean to look at.

  • @Architector_4
    @Architector_45 жыл бұрын

    ...I was looking at Python and getting scared of weird funny one-liners it has. This makes me even more scared.

  • @Scorpionwacom
    @Scorpionwacom5 жыл бұрын

    Big respect for the white screen!

  • @gooball2005

    @gooball2005

    5 жыл бұрын

    dark theme rules

  • @jamma246
    @jamma2464 жыл бұрын

    Haskell is fantastic.

  • @STDrepository
    @STDrepository5 жыл бұрын

    Every coding test involves prime numbers but I've been programming for like 10 years and I have never once needed a prime number.

  • @233kosta
    @233kosta5 жыл бұрын

    This here c/c++/matlab n00b is in awe of Haskell!

  • @user-fr2mw3sj2x
    @user-fr2mw3sj2x4 жыл бұрын

    When he typed in sum [1..] i was kinda expecting to see -1/12 😐

  • @maximilianrpm2927

    @maximilianrpm2927

    3 жыл бұрын

    the operation was interrupted. It will print -1/12, If you give it enough time, that is infinite time

  • @mykhailoyeromenko9167
    @mykhailoyeromenko91673 жыл бұрын

    Will primes evaluate twice in the example with twins primes?

  • @haskellhutt

    @haskellhutt

    3 жыл бұрын

    The list 'primes' will be computed once, and shared between the two uses in the twin primes example.

  • @BrianWoodruff-Jr
    @BrianWoodruff-Jr5 жыл бұрын

    So I tried his code on my Raspberry Pi. Here's my primes.hs file: primeslow = filter ( ->[x | x

  • @homrbrewlogic5399
    @homrbrewlogic53995 жыл бұрын

    Do a video about modern cpu architecture

  • @kariboo84
    @kariboo845 жыл бұрын

    please give me that last digit of PI !

  • @dp121273

    @dp121273

    5 жыл бұрын

    It's of course 8 (infinity rotated 90° ;-) )

  • @kariboo84

    @kariboo84

    5 жыл бұрын

    @@dp121273 "Or does it ?" an easy javascript answer should be : PI[PI.length-1] or console.log('Trust me bro, it\'s',Math.floor(Math.random()*10))

  • @MaZeeT

    @MaZeeT

    5 жыл бұрын

    42 ofc

  • @kariboo84

    @kariboo84

    5 жыл бұрын

    @@MaZeeT try{420}catch(421){do{69}while(42)}

  • @sergheiadrian

    @sergheiadrian

    5 жыл бұрын

    [0..9] choose one...

  • @leocelente
    @leocelente5 жыл бұрын

    I still don't understand why the part in brackets that filters all multiples of n didn't take an infinite time to run.

  • @Yamahapsr200

    @Yamahapsr200

    5 жыл бұрын

    Because it doesn't :D well - at least not at any given time. It only ever filters one number at a time and passes it to the next command (or the console, at last) and only after that all finished doing whatever it wants to do, it takes the next number into concideration :)

  • @Peterwhy

    @Peterwhy

    5 жыл бұрын

    Because of laziness :D Say I want to have the 3rd prime (primes !! 2), and I define sieve (p:ps) = p : sieve [x | x

  • @Axman6

    @Axman6

    5 жыл бұрын

    I wish more students learning Haskell would go to this effort - lazy evaluation becomes completely obvious once you step through the definitions of the functions and look at what is being evaluated at each step. Gold star! 🌟

  • @CptColCool
    @CptColCool4 жыл бұрын

    You forgot the Amazon link to his Haskell book!

  • @dhuvsgg7553
    @dhuvsgg75535 жыл бұрын

    does anyone know how to sum infinite series in haskell

  • @timh.6872

    @timh.6872

    5 жыл бұрын

    I imagine there's a library somewhere, but no language I know of has any kind of analysis as a built in concept, which is what you need to do infinite sums. Specifically you need a continuous metric space with an algebra containing a sum-like operation to be able to think about infinite sums. At that point, you have a notion of open sets and arbitrarily small nonzero distances, and so can describe convergence. Then we can describe the potential sum of a stream of sums as an algebraic/coalgebraic homomorphism from streams of "numbers" to our numbers that satisfies some of the properties we want. I suspect that any setup that strays too far from the complex numbers will fall apart because of the uniqueness of analytic fumctions on open subsets of the complex plane. That's what gives us the potential for assigning values to nonconvergent infinite sums.

  • @papi_no_pop
    @papi_no_pop5 жыл бұрын

    Would love to see some Computerphile on a language like R

  • @vp4744

    @vp4744

    5 жыл бұрын

    Waste of time.

  • @Theraot
    @Theraot5 жыл бұрын

    5:24 and the truth will set you free

  • @awiewahh
    @awiewahh5 жыл бұрын

    You know what? Haskell is neat.