Learn You a Haskell shows the delete
function.
delete: deletes first occurrence of item
ghci> delete 'h' "hey there ghang!"
"ey there ghang!"
Please critique my implementation.
delete' :: (Eq a) => a -> [a] -> [a]
delete' y xs = delete'' y xs []
where delete'' _ [] _ = []
delete'' d (a:as) acc
| a == d = reverse acc ++ as
| otherwise = delete'' d as (a:acc)
I don't like the fact that I'm using the :
operator, but then calling reverse
and acc ++ as
.
Also, I don't know how to capture the first pattern match of delete''
with a single pattern match and guards alone.