[Haskell-cafe] Newbie list question

junkywunky junkywunky at hotmail.com
Sun May 27 05:06:43 EDT 2007


That's the thing. I want to return a list of people who are not overdrawn.
Something like:

type NI = Int
type Age = Int
type Balance = Int
type Person = (NI, Age, Balance)
type Bank = [Person]

credit :: Bank -> [Person]
credit [(a,b,c)] = [(a,b,c)] if c >= 0 
			then [(a,b,c)] 
			else error "overdrawn customer"

except this doesn't work with things like:

credit [(1,2,3),(4,5,6)] 

or

credit [(1,2,3),(4,5,6),(7,8,-9)] 


Andrew Coppin wrote:
> 
> junkywunky wrote:
>> type Person = (NI, Age, Balance)
>> type Bank = [Person]
>>
>> credit :: Bank -> [Person]
>> credit [(a,b,c)] = [(a,b,c)]
>>
>> This code works when I type in:
>>
>> credit [(1,2,3)]
>>
>> but doesn't work when I type in:
>>
>> credit [(1,2,3),(4,5,6)]
>>
>> Any help?
>>
>> Thanks in advance.
>>   
> 
> The expression [(1,2,3),(4,5,6)] doesn't match the pattern [(a,b,c)].
> 
> Now, since Bank and [Person] are actually the exact same type and the 
> credit function actually does nothing, you could simply write
> 
>   credit x = x
> 
> (Or, for that matter, credit = id.) It would then work for both examples.
> 
> I presume that the idea is that the credit function will eventually do 
> something - in that case, it might be helpful to say exactly what you 
> want it to actually do.
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 

-- 
View this message in context: http://www.nabble.com/Newbie-list-question-tf3823011.html#a10823244
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list