I’m new to Haskell and need some help on this situation. I have the following list
-- 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)]
My requirement is to get the amount corresponding to the account number, e.g., for 001 it should give 100.
The function I wrote was this
--Function to check the balance of a person
checkBalance :: bankAccounts -> AcNo -> Amnt
checkBalance dbase number = Amnt|(AcNo, Name, City, Amnt) <- dbase, AcNo==number}
The second line is where im stuck at which gives the error message
Syntax error in input (unexpected `|')
I’d like to have some help on this. Thanx.
Recall that names of Haskell types begin with capital letters, so the type of
checkBalanceshould beIn your question, you seem to aim at using a list comprehension, but you don’t have the syntax quite right.
This definition is fine if an account is in
dbasebut blows up when it isn’t.
A better type for
checkBalanceisto represent the general case, i.e.,
dbasemay or may not containnumber.