In Haskell, how can you compare two lists to check if they are equal? Also the order shouldn't matter.
Example:
[1,2] = [2,1]
I tried all (flip elem [1,2,3]) [2,1]
, but this returns true
...
Thanks.
If your lists have always same size then just A == B . Also if your lists don't have the same size, just as == bs tells you if they are equal. @Ingo @mort's "working" solution treats, for example, [1,2,3] and [1,2,3,4] as equal, there (==) would not.
Something like this?
import Data.List (sort)
areEqual a b = sort a == sort b
OUTPUT:
*Main> areEqual [1,2] [2,1]
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With