我試圖改編一個舊的Haskell專案,它現在與最新的GHC不兼容(MonadFail現在是默認的)。
applyCosPass :: CosCtx a => (a -> QueryExpr -> Either String QueryExpr)
-> a -> QueryExpr -> Either String QueryExpr.
applyCosPass p c (UnionAll q1 q2) =
UnionAll <$> applyCosPass p c q1 <*> applyCosPass p c q2
applyCosPass p c (Select sl f w g d) =
do (Select sl' f' w' g' d') <- p c(Select sl f w g d)
nsl <- (checkListErr $ map convSI sl')
nf <- newFr f'.
nw <- newWh w'.
return $ Select nsl nf nw g' d'
where ...。
它回傳的錯誤如下:
。- Could not deduce (MonadFail (Either String)
產生于一個do 陳述句。
陳述句產生的,具有可失敗的模式'(Select sl' f' w' g' d')
從背景關系中。CosCtx a
由type簽名來約束:
applyCosPass :: forall a.
CosCtx a =>
(a -> QueryExpr -> Either String QueryExpr)
-> a -> QueryExpr -> Either String QueryExpr
at src/CosetteParser.lhs:(648,3)-(649,63)
- In a stmt of a 'do' block:
(Select sl' f' w' g' d') <- (case slstmt of)
Left s -> error s
Right e -> Right e)
根據Haskell Wiki的選項2"適應新代碼",代碼被修改為明確的模式匹配,但錯誤仍然存在。這里可能缺少什么呢?
applyCosPass p c (Select sl f w g d) =
do {(Select sl' f' w' g' d') <- (case slstmt of)
Left s -> error s
Right e -> Right e)。)
nsl <- (checkListErr $ map convSI sl')。
nf <- newFr f';
nw <- newWh w';
回傳 $ Select nsl nf nw g' d'}。
where slstmt = p c (Select sl f w g d)
uj5u.com熱心網友回復:
他們的意思是像這樣明確的模式匹配:
applyCosPass :: CosCtx a => (a -> QueryExpr -> Either String QueryExpr)
-> a -> QueryExpr -> Either String QueryExpr.
applyCosPass p c (UnionAll q1 q2) =
UnionAll <$> applyCosPass p c q1 <*> applyCosPass p c q2
applyCosPass p c (Select sl f w g d) = do
slstmt <- p c (Select sl f w g d)
case slstmt of
Select sl' f' w' g' d' -> do
nsl <- (checkListErr $ map convSI sl')
nf <- newFr f'.
nw <- newWh w'.
return $ Select nsl nf nw g' d'
... 其他情況 -> 錯誤 "模式匹配失敗" -- Boooo
where ...。
在do符號中的<-箭頭的左側不應保留模式匹配。
注意,你應該檢查Select ...是否真的是這里唯一可能的情況,否則你可能應該處理其他情況。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/316924.html
標籤:
