case x of
Cond expr stmt -> do
checkExprType expr Bool
processStmt env stmt
return env
AnotherCond expr stmt -> do
checkExprType expr Bool
processStmt env stmt
return env
如何消除此复制粘贴?
答案 0 :(得分:4)
你可以制作一个本地定义,它是expr
和stmt
的函数:
-- I assume this is all inside a 'do' block
let conditionalLike expr stmt = do
checkExprType expr Bool
processStmt env stmt
return env
case x of
Cond expr stmt -> conditionalLike expr stmt
AnotherCond expr stmt -> conditionalLike expr stmt