mercredi 23 septembre 2020

What's wrong with my code? Trying to find an element in a list

This code should tell you whether or not an element a is in a list. What is wrong with this code?

istEnthalten:: a -> [a] -> Bool
istEnthalten elem [] = False
istEnthalten elem (x:xs) = if elem == x
  then True
  else istEnthalten elem xs

I know this one works:

istEnthalten :: a -> [a] -> Bool
istEnthalten elem [] = False
istEnthalten elem (x:xs)
      | elem == x = True
      | otherwise = contains elem xs

but what`s wrong with the first one?

Aucun commentaire:

Enregistrer un commentaire