[Haskell-beginners] Re: Empty list Exception

Sean Bartell wingedtachikoma at gmail.com
Sun May 24 15:35:10 EDT 2009


When you use filter in this case, it's checking for users that are the same
as ("Joao Claudino", "1240", 2). There aren't any in the list, so filter
returns []. You can't use head on [], because there's no first element.

Other notes about your code:

   - if x then True else False is the same as just x.
   - The otherwise case for userRegistration can never be reached.


I would write it more like this:

checkUser user userList = elem user userList

userRegistration user list
    | checkUser user list = list
    | otherwise = user:list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090524/c593ff74/attachment.html


More information about the Beginners mailing list