Composing monad actions with folds

后端 未结 3 713
醉梦人生
醉梦人生 2021-01-19 19:45

Let\'s take a function of type (Monad m) => a -> m a. For example:

ghci> let f x = Just (x+1)

I\'d like to be able to

3条回答
  •  一向
    一向 (楼主)
    2021-01-19 20:34

    I came up with this:

     last $ take n $ iterate (>>= f) $ Just 1
    

    But it also overflows the stack on large numbers of n. I don't have the time right now to look into it more :-(

提交回复
热议问题