I've been searching before opening a topic but I can not find something like what I need.
It is the case that I have to compare two lists with a certain condition, element by element, but I am incapable. The function has to return a Bool, True if they are the same and False if not.
This is what I have to do: Items that occupy an odd position in the first list should appear in Even position in the second list, but in reverse order. The elements that occupy even position in the first list must appear in odd position within the second list, and in the same order.
Given this, my code is as follows:
separarPorPosicion :: [a] -> ([a],[a])
separarPorPosicion [] = ([],[])
separarPorPosicion xs = (listaPar,listaImpar)
where
listaPar = [ x | (x,y) <- zip xs [1..length xs], even y]
listaImpar = [ x | (x,y) <- zip xs [1..length xs], odd y]
mellizas :: Eq a => [a] -> [a] -> Bool
mellizas [] [] = True
mellizas _ [] = False
mellizas [] _ = False
mellizas xs ys = impar1 == reverse par2 && par1 == impar2
where
par1 = [x | (x,y)<- separarPorPosicion xs]
par2 = [x | (x,y)<- separarPorPosicion ys]
impar1 = [y | (x,y)<- separarPorPosicion xs]
impar2 = [y | (x,y)<- separarPorPosicion ys]
It gives me an error of types that I am unable to solve. Any ideas? Thanks in advance!