module LAI12 where 

import List

list2cf :: Eq a => [(a,a)] -> a -> a -> Bool
list2cf pairs x y = elem (x,y) pairs

cf2list :: (a -> a -> Bool) -> [a] -> [(a,a)]
cf2list f xs = [ (x,y) | x <- xs, y <- xs, f x y ]

cf2partition :: (a -> a -> Bool) -> [a] -> [[a]]
cf2partition f [] = []
cf2partition f (x:xs) = xblock : cf2partition f rest
  where (xblock,rest) = 
         (x: filter (f x) xs, filter (not.(f x)) xs)

bl :: Eq a => [[a]] -> a -> [a]
bl part x = head (filter (elem x) part)

partition2cf :: Eq a => [[a]] -> a -> a -> Bool
partition2cf part x y = elem x (bl part y)


