這個問題在這里已經有了答案: 庫函式與自身組成一個函式 n 次 10 個答案 11 天前關閉。
我想將步進單元 a 重復 b 次。我怎樣才能做到這一點?
play :: Generation -> Int -> Maybe Generation
play a b
| b < 0 = Nothing
| b == 0 = (Just a)
| otherwise = Just (stepCells a) -- do it b times
uj5u.com熱心網友回復:
正如 Noughtmare 在他們的評論中所建議的那樣,iterate是解決這個問題的好方法。但是,您也可以使用手動遞回來做到這一點:
play :: Generation -> Int -> Maybe Generation
play a b
| b < 0 = Nothing
| b == 0 = (Just a)
| otherwise = play (stepCells a) (b - 1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/474046.html
