1
我在編寫從元組內的列表中刪除元素的函數時遇到問題。從元組列表中刪除元素
問題是,我想要函數返回元組。但是,使用Data.List
的delete
函數給我一個列表。
代碼:
-- type Value = Int
type Cell = (Int, [Int])
type Board = [Cell]
----------- your solution goes here --------------
-- solvem :: Board -> Board
-- solvem bd = ???
deleteCandidate :: Int -> Cell -> Cell
deleteCandidate cand c1 = delete cand (snd c1) -- This gives me trouble
updateNeighbors :: Cell -> Cell -> Cell
updateNeighbors c1 c2 | isNeighbor c1 c2 = deleteCandidate (head (snd c1)) c2
| otherwise = c2
由於Haskell中的數據是不可變的,我將如何在deleteCandidate
函數返回一個元組?我需要重建一個Cell嗎?