Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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)


Macros 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.


do 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.


"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.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: