Logo

Programming-Idioms

History of Idiom 12 > diff from v123 to v124

Edit summary for version 124 by skeletor:
[Haskell] Original didn't compile under ghc; "Conflicting definitions for `x'". This uses branching to fix it.

Version 123

2020-12-06, 15:14:12

Version 124

2020-12-08, 21:41:56

Idiom #12 Check if list contains a value

Check if list contains a value x.
list is an iterable finite container.

Idiom #12 Check if list contains a value

Check if list contains a value x.
list is an iterable finite container.

Variables
list,x
Variables
list,x
Extra Keywords
array vector member membership
Extra Keywords
array vector member membership
Code
find _ [] = False
find x (x:xs) = True
find x (_:xs) = find x xs
Code
find _ [] = False
find n (x:xs)
  | x == n = True
  | otherwise = find x xs
Comments bubble
For empty list false.
If first element match true.
Check rest of the elements recursively.
Comments bubble
For empty list false.
If first element match true.
Check rest of the elements recursively.