Monday, 6 June 2016

Haskell: Check list of tuples has same elements or not.

For example, take a list like [(1, 2), (3, 3), (4, 4), (5, 5), (9, 10)], result should be [False, True, True, True, False]


‘map (\(x,y) -> (x == y))’ return a list of Booleans. If the tuple in list has same elements, then the corresponding positio in the result list is True, else False.
Prelude> map (\(x,y) -> (x == y)) [(1, 2), (3, 3), (4, 4), (5, 5), (9, 10)]
[False,True,True,True,False]
Prelude> 
Prelude> map (\(x,y) -> (x == y)) [('a', 'b'), ('a', 'a'), ('b', 'b'), ('c', 'd')]
[False,True,True,False]


Previous                                                 Next                                                 Home

No comments:

Post a Comment