Idiomatic way to sum a list of Maybe Int in haskell

后端 未结 5 2057
粉色の甜心
粉色の甜心 2021-02-07 07:04

Is there a more idiomatic way to implement the following? I feel like I\'m missing a way to get rid of the lambda, but couldn\'t figure out a way to convert it to point-free. Ma

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-07 07:55

    I think foldM works well here.

    import Control.Monad
    sumMay = foldM (fmap . (+)) 0
    

    I think it's the clearest as it maps (Ba duh duh ching) to what you'd do in pure code.

提交回复
热议问题