Kelsey Abreu
Kelsey Abreu

Reputation: 1124

return the rest of a list in Haskell recursion

Hey guys so I'm trying to create a simple program to delete the first occurence of a element then return the rest of the list. It's been a while and I'm wondering why I'm getting this parse error on line 8

module deleteFirst where
deleteFirst :: (Eq a) => a ->[a] -> [a]

deleteFirst toDelete [] = []
deleteFirst toDelete (a:as) =
    if(toDelete == a) then as
    else a:(deleteFirst toDelete as)

Any input? Thanks guy

Upvotes: 0

Views: 145

Answers (2)

Landei
Landei

Reputation: 54584

You got the answer, but I'd like to point out another solution:

deleteFirst x xs = u ++ (drop 1 v) where (u,v) = break (==x) xs

Upvotes: 2

Daniel Wagner
Daniel Wagner

Reputation: 152837

The parse error is on column 8, not line 8, and it is because module names must start with an upper case letter.

Upvotes: 7

Related Questions