how to create a function that checks if two lists are equal without using the operator (==)?

Asked

Viewed 84 times

0

iguais:: [Int]->[Int]->Bool
iguais [] [] = True
iguais [] _ = False
iguais _ [] = False
iguais (x:xs) (z:zs)

this is the code, I only did so far. Someone can help me?

  • iguais a b = not (a /= b) Okay, okay, I guess this isn’t what you wanted...

  • no, actually I want a recursive call.

  • x == z && iguais xs zs on your last line? (or not( x /= z) && iguais xs zs )

  • 1

    It’s neither worth it == to make the comparison of x == z ?

1 answer

0

I tried that:

iguais :: [Int] -> [Int] -> Bool
iguais [] [] = True
iguais [] (_:_) = False
iguais (_:_) [] = False
iguais (x:xs) (x:ys) = iguais xs ys
iguais _ _ = False -- Se chegar aqui eh porque nao deu match na idefinicao de cima

But I got the following mistake Conflicting definitions for ‘x’. I found out that is not possible: https://stackoverflow.com/a/1179394/858412

Browser other questions tagged

You are not signed in. Login or sign up in order to post.