Library function to compose a function with itself n times

前端 未结 10 2045
野的像风
野的像风 2020-11-30 03:36

Is there a library function available in Haskell to compose a function with itself n times?

For example I have this function:

func :: a ->         


        
10条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 04:16

    I do not know why you say that iterate is not appropriate. It is perfectly suitable for this purpose. (!! n) . iterate func is the composition of n copies of func.

    (Someone had posted an answer similar to the above code, but he/she seems to have deleted it.)

提交回复
热议问题