Good Haskell coding style of if/else control block?

后端 未结 8 1687
慢半拍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:47

    The way Haskell interprets if ... then ... else within a do block is very much in keeping with the whole of Haskell's syntax.

    But many people prefer a slightly different syntax, permitting then and else to appear at the same indentation level as the corresponding if. Therefore, GHC comes with an opt-in language extension called DoAndIfThenElse, which permits this syntax.

    The DoAndIfThenElse extension is made into part of the core language in the latest revision of the Haskell specification, Haskell 2010.

提交回复
热议问题