type NI = Int
type Age = Int
type Balance = Int
type Person = (NI, Age, Balance)
type Bank = [Person]
sumAllAccounts :: NI -> Bank -> Int
sumAllAccounts n l = filter niMatch l
where niMatch n (a,_,_)
| n == a = True
| otherwise = False
Run Code Online (Sandbox Code Playgroud)
当我运行此功能时,我得到一个类型错误
couldnt match type (Person, t0, t1) -> Bool with Bool
Run Code Online (Sandbox Code Playgroud)
但是当我把它自己的功能放在哪里时它起作用
personNIMatchs :: NI -> Person -> Bool
personNIMatchs n (a,_,_)
| n == a = True
| otherwise …
Run Code Online (Sandbox Code Playgroud) 我有一个包含整数的元组列表.
[(123,123,123),(123,123,123),(123,123,123)]
Run Code Online (Sandbox Code Playgroud)
我想得到列表中所有第二个值的总和,例如;
[(_,123,_),(_,123,_),(_,123,_)]
Run Code Online (Sandbox Code Playgroud)
123 + 123 + 123
我想我应该使用折叠,但我不确定