[Haskell-cafe] Newbie list question
Donald Bruce Stewart
dons at cse.unsw.edu.au
Sun May 27 04:57:09 EDT 2007
junkywunky:
>
> 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)]
You're pattern matching in 'credit' on a list of a single element.
Perhaps you mean to write:
credit :: Bank -> [Person]
credit x = x
or perhaps return just the first element of the list:
credit [] = []
credit (x:xs) = x
You might want to start with one of the tutorials on Haskell programming
listed on haskell.org. The wikibook is quite a good start.
-- Don
More information about the Haskell-Cafe
mailing list