Haskell: Function application with $

后端 未结 4 1679
滥情空心
滥情空心 2021-01-11 15:00

In the following snippet, you can see my two collatz functions I wrote in Haskell. For the recursive application I used parentheses in the first example (collatz) to get the

4条回答
  •  一向
    一向 (楼主)
    2021-01-11 15:04

    As @missingno stated, it's an operator precedence problem. You could rewrite it like this

    collatz' n | even n    = n : (collatz' $ n `div` 2)
               | otherwise = n : (collatz' $ n * 3 + 1)
    

    But that obviously doesn't buy you much, because you still have parenthesis.

提交回复
热议问题