我有一个需要迭代的 Data.Sequence。问题在于它是有状态的,并且序列可能会由于所述迭代而增长。
data Chart = Chart {
charts :: M.Map Int (Seq.Seq RState), --map from position to list of chart states
...
} deriving (Show)
processChartSeq :: Int -> Int -> State Chart ()
processChartSeq chtIndx stIndx = do s <- get
let seq = fromJust $ M.lookup chtIndx (charts s)
rstate = Seq.index seq stIndx
processState rstate
when (stIndx < Seq.length seq) (processChartSeq chtIndx (stIndx+1))
所以我用显式递归来做这件事,但它看起来很笨重。此外,这似乎是一件很平常的事情。我重新发明了哪些常见的一元控制结构,很糟糕?