haskel check if number appears only once in the list

I want check if number appears only once in the list. I  wrote following code, but i don't know how to check if number already was there.
once :: [Int] -> Int -> Bool
once [] n = False
once (x:xs) n
  | x == n  = True
  | otherwise  = once xs n

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If the list is unorderd you have no chance, to implement it that  way. You have to run over the list over and over again and check it again and again. Howerver if you'd write it like this

It does work differently. there is a predicate applied to  the list checking if the element matches the searchedItem,  this elements are collected in another list and then I just  see if this  list has the length 1,which means the element in the list exactly once.

onceInList :: (Eq a) => [a] -> a -> Bool
onceInList aList item = length (filter (\el -> el = item) aList) == 1

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sorry for the  follow up the el = item must be == sorry. a copy+paste error.
static86Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.