haskell - 匹配日期列表的月份
问题描述
我正在尝试编写一个 Haskell 函数,该函数接受日期和月份的列表,并返回列表中有多少日期与给定月份匹配。这是我到目前为止所拥有的,它似乎不起作用
numInMonth :: [(Int,Int,Int)] -> Int -> Int
numInMonth x [] = x
numInMonth x (y:ys)
minList1 (x:xs) = currentMin x xs
currentMax :: Int -> [Int] -> Int
currentMax x [] = x
currentMax x (y:ys)
| x >= y = currentMax x ys
| otherwise = currentMax y ys
maxList1 :: [Int] -> Int
maxList1 (x:xs) = currentMax x xs
解决方案
假设元组是一个日期:
type Day = Int
type Month = Int
type Year = Int
type Date = (Year, Month, Day)
我们可以考虑您想要的逻辑,首先过滤与给定月份匹配的所有日期,然后计算它们:
numInMonth :: [Date] -> Month -> Int
numInMonth dates month = length . filter (\(_, m, _) -> m == month) $ dates
推荐阅读
- bash - MacTerminal 上的 PyFERRET 命令不起作用
- google-apps-script - 如何使用脚本编辑器引用谷歌表格中的不同选项卡?
- c# - DocuSign Connect webhook 不包括 HMAC 标头
- c# - 使用用户上传的文件解析 URL
- reactjs - 带有 useEffect 的自定义钩子(在挂载上)执行了多次
- python - 从离散信号计算 FFT 特征
- javascript - jQuery - 索引不断重置
- asp.net-mvc-4 - 寻找解决 FIPS 兼容错误的方法
- c++ - 为什么 sizeof 在 C++ 中给出不正确的字节数?
- amazon-web-services - 检查 Cloudfront 正在从哪个 AWS 服务端点提取静态文件的任何方法