[Haskell-cafe] Newbie list question

Donald Bruce Stewart dons at cse.unsw.edu.au
Sun May 27 05:12:03 EDT 2007


junkywunky:
> 
> 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:
> 

Right, you mean to write a list filter. List comprehensions are useful
for this:


    credit xs = [ p | p@(a,b,c) <- xs, c >= 0 ] 

or maybe:

    credit xs = filter ok xs
        where
            ok (a,b,c) = c >= 0

-- Don


More information about the Haskell-Cafe mailing list