The “Hello, world” program we wrote so far is just pure function application, purely functional programming! Wow… I thought the first few lectures would be pretty boring as is the same with learning other languages. :t putStrLn # putStrLn :: String -> IO () That is, the type of putStrLn is String -> IO (). But wait, if it doesn’t cause side effect, how come it can print words onto the screen? Well, it turns out that print takes an argument, “Hello, world!” in this case, and returns an IO () which takes care of the side effecting. This doesn’t look any different to other programming languages, but the mind blowing thing is, putStrLn is actually not causing any side effect. In Haskell, you don’t need brackets for function application, so here’s goes the classic hello-world example: putStrLn "Hello, world!" # Hello, world!
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |