-- give_to is a many-to-many relation -- receive_from inverts the relation give_to -- The pattern produces the inverse by narrowing import Control.Search.SetFunctions data BloodTypes = Ap | An | ABp | ABn | Op | On | Bp | Bn deriving (Eq, Ord) -- donor `give_to` receipient give_to Ap = Ap ? ABp give_to Op = Op ? Ap ? Bp ? ABp give_to Bp = Bp ? ABp give_to ABp = ABp give_to An = Ap ? An ? ABp ? ABn give_to On = Ap ? An ? ABp ? ABn ? Op ? On ? Bp ? Bn give_to Bn = Bp ? Bn ? ABp ? ABn give_to ABn = ABp ? ABn receive_from (give_to x) = x give_to'set x = set1 give_to x receive_from'set x = set1 receive_from x -- all the donors for ABn main = sortValues (receive_from'set ABn)