Division in Haskell

后端 未结 2 343
深忆病人
深忆病人 2020-12-15 15:49

I\'m making a function in Haskell that halves only the evens in a list and I am experiencing a problem. When I run the complier it complains that you can\'t perform division

2条回答
  •  醉梦人生
    2020-12-15 16:36

    I should add that using map would simplify the code.

    HalfIfEven n
      | even n = n `div` 2
      | otherwise = n
    
    halfEvens = map halfIfEven
    

提交回复
热议问题