It is a haskell code to find the first duplicate element in the list. if you have 2 lists like this:L1 = {1,2,3,4} L2 = {1,2,3,1}then result for 1st would be No duplicate found and result for second should be integer 1.if one list has L3={1,2,1,3,3} answer should still be 1.
I tried doing it but stuck with the condition checking: We will use union datatype.
data Res a = DuplicateFound a | NoDuplicateFound
deriving (Show,Eq)
findDuplicate [] = NoDuplicateFound
findDuplicate (x:xs) = if (condition???)
where
aux x [] = NoDuplicateFound
aux x (y:ys) = if x == y then DuplicateFound x
else aux x ys
else NoDuplicateFound
I know its a pathetic code..please help me to improve it.