我正在尝试计算在银行内拥有账户的两个年龄段的人/客户的总余额。我可以让它显示符合要求的人员列表。
这些是构造函数
type NI = Int
type Age = Int
type Balance = Int
type Person = (NI, Age, Balance)
type Bank = [Person]
这是银行
rbs :: Bank
rbs = [ (1, 73, 1000)
, (2, 18, -50)
, (3, 60, 190)
, (4, 26, 300)
, (5, 24, 456)
, (6, 32, 7500)
, (7, 41, -46)
, (8, 59, -850)
, (9, 44, 348)
, (10, 66, -1000)
, (11, 37, 20000)
, (12, 29, -245)
, (13, 55, 3090)
]
这是我递归检查银行的代码
equityA' :: Bank -> (Int, Int) -> Bank
equityA' ((n,a,b):xs) (0,0) = error "No ages were selected"
equityA' [] (x,y) = []
equityA' ((n,a,b):xs) (f, s) = if (f <= a) && (s >= a) then (n,a,b) : equityA' xs (f, s)
else equityA' xs (f, s)
如果我运行equityA' rbs (40,50) 输出将是[(7,41,-46),(9,44,348)]
我正在努力做的是打印出这些人的总余额。我有一些代码,但被困在实际的计算部分。
检查总数的代码。
equityAge :: Bank -> (Int, Int) -> Int
equityAge ((n,a,b):xs) (0,0) = error "No ages were selected"
equityAge [] (x,y) = 0
equityAge ((n,a,b):xs) (f, s) =
如果有任何帮助,我将不胜感激。