Good Haskell coding style of if/else control block?

后端 未结 8 1688
慢半拍i
慢半拍i 2021-01-31 09:15

I\'m learning Haskell in the hope that it will help me get closer to functional programming. Previously, I\'ve mostly used languages with C-like syntax, like C, Java, and D.

8条回答
  •  Happy的楠姐
    2021-01-31 09:46

    You will see a bunch of different indentation styles for Haskell. Most of them are very hard to maintain without an editor that is set up to indent exactly in whatever style.

    The style you display is much simpler and less demanding of the editor, and I think you should stick with it. The only inconsistency I can see is that you put the first do on its own line while you put the other dos after the then/else.

    Heed the other advice about how to think about code in Haskell, but stick to your indentation style.

提交回复
热议问题