Learning Haskell: How to remove an item from a List in Haskell
Posted
by BM
on Stack Overflow
See other posts from Stack Overflow
or by BM
Published on 2010-01-19T22:04:54Z
Indexed on
2010/06/06
2:22 UTC
Read the original article
Hit count: 848
haskell
Trying to learn Haskell. I am trying to write a simple function to remove a number from a list without using built-in function (delete...I think). For the sake of simplicity, let's assume that the input parameter is an Integer and the list is an Integer list. Here is the code I have, Please tell me what's wrong with the following code
areTheySame :: Int -> Int-> [Int]
areTheySame x y | x == y = []
| otherwise = [y]
removeItem :: Int -> [Int] -> [Int]
removeItem x (y:ys) = areTheySame x y : removeItem x ys
© Stack Overflow or respective owner