我是Haskell的新手,在这种情况下需要一些帮助。我有以下列表从超过2个元素的元组列表中检索元素(Haskell)
-- create a type for bank account
type AcNo = String
type Name = String
type City = String
type Amnt = Int
type AcInfo = [(AcNo, Name, City, Amnt)]
-- function to get the data of bank accounts to a list of tuples
bankAccounts :: AcInfo
bankAccounts = [("oo1", "Sahan", "Colomb", 100),("002", "John", "Jafna", 200)]
我的要求是获得对应账号的金额,例如,对于001它应该给100
我写的功能是这样的
--Function to check the balance of a person
checkBalance :: bankAccounts -> AcNo -> Amnt
checkBalance dbase number = Amnt|(AcNo, Name, City, Amnt) <- dbase, AcNo==number}
第二行是我卡在哪里给出错误信息
Syntax error in input (unexpected `|')
我想对此有所帮助。感谢名单。
非常感谢您提供的帮助。是的。目前我只专注于dbase中的账户。我将试验你提到的类型。再次感谢。 –