3 ms·
Exactly, Haskell's "do" notation is essentially defined as a built-in macro, so if you ever want to use "do" notation in a language that doesn't have it built-i
by maxiepoo 5y ago
Exactly, Haskell's "do" notation is essentially defined as a built-in macro, so if you ever want to use "do" notation in a language that doesn't have it built-in you will need to use macros. (Let-binding overloading is essentially do notation in case that's not clear)
- tromp 5y agodo is more syntactic sugar for >>= (monadic bind) than macro. E.g. do s <- readLine "Enter name:" putStr $ "Hello, " ++ s reduces to readLine "Enter name:" >>= (\s -> putStr $ "Hello, " ++ s) But I agree you can use macros to implement syntactic sugar.
- marcosdumay 5y agoMacros are way more powerful than binding, for both the best and the worst. Yes, you can use macros to add do-notation to a language. But you can also use macros to add things like type checks and new conditional statements. You can't add those with do-notation.
- whateveracct 5y ago"do" is also no longer hard-coded. There are multiple language extensions that allow you to change what it desugars to, which is really cool.