jeudi 3 août 2017

How to check if an element exists in list in haskell?

I know this question has been asked earlier, but the answer deviates from the main question.

Here is a method that checks if an element exists in Haskell

elem’ x (y : ys) = if x == y then True else elem’ x ys

What I'm confused about is that in Haskell (y : ys) this adds y to ys, so how does this function really checks if an element exists? Because I don't see any loop here except a recursive call passing the same y to ys.

Please enlighten me.

Aucun commentaire:

Enregistrer un commentaire