Haskell for Imperative Programmers #15 - IO

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 ก.พ. 2025
  • In this video we will finally write "Hello World".

ความคิดเห็น • 46

  • @1Dr490n
    @1Dr490n ปีที่แล้ว +18

    We basically turned Haskell‘s imperative mode on

  • @philipphagenlocher
    @philipphagenlocher  5 ปีที่แล้ว +20

    Correction: At 5:33 I said that the do-notation is the only way of having this sequential evaluation. This is not correct, there is a function (sequence :: [IO a] -> IO [a]) that does the same. I meant that this behavior is not possible in the notation we are used to. We will learn another way of having this effect in a later video.

    • @joshuakb2
      @joshuakb2 3 ปีที่แล้ว

      There are many ways of doing it. For instance, the bind function >>= and >>

    • @NamasteProgramming
      @NamasteProgramming 2 ปีที่แล้ว +1

      You should pin Errata comments so they are easy to find

  • @antonbozhinov
    @antonbozhinov 2 ปีที่แล้ว +10

    Thank you so much for those video series. Best I could find on the internet!

  • @ArmeroPR
    @ArmeroPR 19 วันที่ผ่านมา +1

    The main issue with this language is that most tutorials only focus on the purity of functional programming and a lot of math stuff. If there were more tutorials like this where you show it doing semi useful things then more people would not give up learning it. Haskell is a very useful language.

  • @Chemaclass
    @Chemaclass 4 ปีที่แล้ว +15

    These videos are simply amazing

  • @daryleprice4485
    @daryleprice4485 4 ปีที่แล้ว +3

    Your videos are very helpful. Thank you!

  • @nipasy
    @nipasy ปีที่แล้ว +1

    5:38 "There is no other way of doing it."
    Isn't the "do" notation just syntactic sugar for (a very convoluted) use of "bind"?

    • @0LoneTech
      @0LoneTech 11 หลายเดือนก่อน +1

      Mildly convoluted, yes. Compare (desugared into braces and semicolons form):
      do { action1 ; var1 > action2 >>= \var1 -> let var2 = func var1 in action3 var2
      >>= is the monadic bind operator, and >> simply discards a value like ">>= \ _ ->". The translation is quite direct.

  • @higiniofuentes2551
    @higiniofuentes2551 6 หลายเดือนก่อน

    Thank you for this very useful video!

  • @johnwerner3714
    @johnwerner3714 2 ปีที่แล้ว

    why is main used within the if/then clause at 9:23 ? I excluded it and the program worked well.

    • @minamagdy4126
      @minamagdy4126 ปีที่แล้ว +3

      Did you try multiple inputs? Recursively calling main is to allow the program not to end immediately after the first input, except if said input was "quit".

  • @higiniofuentes2551
    @higiniofuentes2551 6 หลายเดือนก่อน

    Using IO I suppose is the way to work with files, text, binary, CSV, XML, JSON, do you have any video around this?
    Thank you!

  • @ragnadrok7
    @ragnadrok7 3 ปีที่แล้ว +1

    How long before we print hello world
    Yes.

  • @Theloebtit32000
    @Theloebtit32000 3 ปีที่แล้ว +1

    this video is amazing ! thanks a lot !

  • @kahnfatman
    @kahnfatman 3 ปีที่แล้ว +5

    First versions of Haskell did not have IO. Ok... let's make a Webserver in Haskell. :)))))

    • @leana8959
      @leana8959 23 วันที่ผ่านมา

      There's servant which is pretty cool, you write routes in type level and the handlers are type checked against it.

  • @braejan
    @braejan 2 ปีที่แล้ว

    How to handle a IO(Maybe String) ?

  • @farhandikazahrir6657
    @farhandikazahrir6657 4 ปีที่แล้ว +2

    is it possible to print out a boolean? like True or False

    • @philipphagenlocher
      @philipphagenlocher  4 ปีที่แล้ว +5

      Yes it is! The "print" function can do that.
      print :: (Show a) => a -> IO ()
      It will print some datatype that has an instance of Show which booleans do!

  • @moritzschmidt6791
    @moritzschmidt6791 4 ปีที่แล้ว +5

    Vielen Dank für deine Mühe. Bei WEITEM das beste Tutorial auf TH-cam was Haskell angeht. Mein Buch war ganz gut aber ab IO und Monaden konnte ich das weglegen..

  • @colin398
    @colin398 ปีที่แล้ว

    Will having the main function call itself recursively eventually lead to stack overflow?

    • @schwobbel
      @schwobbel ปีที่แล้ว

      the compiler will turn it into a iterative c code, so no recursion, so no stack overflow. correct me if im wrong but i think that thats how it works

    • @colin398
      @colin398 ปีที่แล้ว

      Interesting you mean like tail call optimization or something else?@@schwobbel

  • @Mari-vx5ig
    @Mari-vx5ig 3 ปีที่แล้ว +2

    Is it possible to input a list of Doubles or Integers?

    • @sebastiangudino9377
      @sebastiangudino9377 2 ปีที่แล้ว +1

      You can only input a string from the console. If that's what you are asking. But you can then Interpret that string as you like. For example you could input a comma separated list of numbers. Which you the appropriately split and convert

    • @0LoneTech
      @0LoneTech 11 หลายเดือนก่อน

      This conversion is what Read is for. E.g.: «xs :: [Int] = read "[1,2,3]"» or in an IO do block «xs :: [Int]

  • @iusmann
    @iusmann 4 ปีที่แล้ว

    Brilliant!

  • @rag3r926
    @rag3r926 4 ปีที่แล้ว

    perfect, thank you

  • @obinator9065
    @obinator9065 ปีที่แล้ว

    oh no

  • @SG1guru
    @SG1guru 4 ปีที่แล้ว +22

    So thats a language where you need 15 videos just to learn how to write "Hello world"

    • @pasdenom.9062
      @pasdenom.9062 4 ปีที่แล้ว +12

      And this is still an awesome language.

    • @jbmw16
      @jbmw16 4 ปีที่แล้ว +4

      My thoughts exactly too much details to do something rather simple on every other language

    • @mayabartolabac
      @mayabartolabac 3 ปีที่แล้ว +6

      no not just that you have to wait for *2 MORE VIDEOS* to understand what a monad is
      but WAIT in that monad video, he only shows the applications of monads, and to REALLY learn what a monad is, you have to wait until *VIDEO #36* for his video on category theory!
      haskell is a beautiful language **muah**

    • @Galaf
      @Galaf 3 ปีที่แล้ว +7

      You could learn that as a first thing, so I think your statement should be "to understand what writing 'Hello World' actually does". It's not so different from C where you can learn right away how to write an Hello World but you would miss on pointers IMHO

    • @sebastiangudino9377
      @sebastiangudino9377 2 ปีที่แล้ว +9

      For printing Hello World in C you need to know about the standard library, ASCII, String Literals, Char Pointers, Null Terminated "cstrings", STDIN and String Formating. And yet you can also just write printf("Hello World") and call it a day.
      Haskell is exactly the same. The code in this video just works, regardless of whether you watched 15 videos or 0. But if you want to understand what you are doing you need to understand the concepts you are working with, which takes time and depends entirely on the paradigms
      Heck of you ever learned java you surely know what mindlessly writing "public static void main(String[] args)" on your first day feels. You get astonishingly overwhelmed by this weird, class obsessed jargon filled paradigm. Untill you eventually start getting the concepts one by one and understand that it's actually really intuitive! In general, you can copy and paste something in an instant. But understanding it takes meaningful time

  • @AhmedSaleh-ws3pz
    @AhmedSaleh-ws3pz 3 ปีที่แล้ว +2

    I didn't understand a word!

    • @sebastiangudino9377
      @sebastiangudino9377 2 ปีที่แล้ว +2

      You do realize this is episode 15 of a series, do you?

  • @ddleupriandboast
    @ddleupriandboast 2 วันที่ผ่านมา

    Esoteric nonsense. Change because of change. Functions read the same as variables and numbers and parameters, because? We like to be different. Most of the truly wild choices serve not a single purpose but to confuse. And make it look like more than it really is.