Should do-notation be avoided in Haskell?

前端 未结 7 1860
时光说笑
时光说笑 2020-11-29 01:32

Most Haskell tutorials teach the use of do-notation for IO.

I also started with the do-notation, but that makes my code look more like an imperative language more th

相关标签:
7条回答
  • 2020-11-29 02:10

    do notation is just a syntactic sugar. It can be avoided in all cases. However, in some cases replacing do with >>= and return makes code less readable.

    So, for your questions:

    "Shall we avoid the Do statement in any case?".

    Focus on making your code clear and better readable. Use do when it helps, avoid it otherwise.

    And I had another question, why most tutorials will teach IO with do?

    Because do makes IO code better readable in many cases.

    Also, the majority of people who starts learning Haskell have imperative programming experience. Tutorials are for beginners. They should use style that is easy to understand by newcomers.

    0 讨论(0)
提交回复
热议问题