My task is that I want to create a function that finds any possible "bondings" of a given list and a predicate but I can't find the right solution.
a bonding for ls for binary predicate p is a list of pairs bs :: [ (a,a) ] such that the following conditions hold
- Every element in
lsappears exactly once inmap fst bsand exactly once inmap snd bs - If a pair
(x,y)appears inbsthen bothxandymust appear inls. - If a pair
(x,y)appears inbsthen(y,x)also appears inbs. - If a pair
(x,y)appears inbsthenxdoes not equaly. - If a pair
(x,y)appears inbsthenp x yisTrue.
Furthermore, the function that I thought it will be useful for this problem is the following findBonding :: Eq a => (a -> a -> Bool) -> [a] -> Maybe [(a,a)] such that findBonding p ls takes p as predicate and ls as a list of integers.
For example, findBonding (\x -> \y -> odd(x+y)) [2,3,4,5,6,7] should return Just [(2,3),(3,2),(4,5),(5,4),(6,7),(7,6)]
Is it a good idea to declare findBonding with foldr of the ls (the list) and then p (the predicate) to be the function that should declare which pairs to find and then to loop over every two items to find the correct pairs and to return them as a list of lists.