View Single Post
Old Oct 24th, 2006, 4:29 AM   #3
magnus.therning
Programmer
 
Join Date: May 2006
Location: Cambridge, UK
Posts: 36
Rep Power: 0 magnus.therning is on a distinguished road
You need some parentheses around the list pattern:

getelem 0 (x:xs) = x
getelem n (x:xs) = getelem (n - 1) xs

By terminating on 0 you have made the function count elements from 0, rather than from 1 (as was suggested in the original post). I think starting from 0 is a better choice though :-)
__________________
Don't comment bad code - rewrite it.
- The Elements of Programming Style (Kernighan & Plaugher)
magnus.therning is offline   Reply With Quote