我正在尝试在 48 小时内完成为自己编写计划中的练习。我需要帮助来简化几个功能。
data LispVal = Number Integer
| String String
| Bool Bool
isNumber :: [LispVal] -> LispVal
isNumber [] = Bool False
isNumber [(Number _)] = Bool True
isNumber ((Number _):xs) = isNumber xs
isNumber _ = Bool False
isString :: [LispVal] -> LispVal
isString [] = Bool False
isString [(String _)] = Bool True
isString ((String _):xs) = isString xs
isString _ = Bool False
isNumber
和isString
函数有很多共同的结构。我该如何分解这种通用结构?