-- Sergio Antoy, Fri Oct 20 22:01:56 PDT 2006 -- example of non-deterministic programming -- find a donor for a blood transfusion to a patient -- Updated by Michael and Sergio on Fri Mar 4 08:43:51 PST 2011 -- updated Wed Jul 5 19:52:44 PDT 2017 -- import List import SetFunctions import Test.EasyCheck -- execute with: curry check blood data BloodTypes = Ap | An | ABp | ABn | Op | On | Bp | Bn 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 has "John" = ABp has "Doug" = ABn has "Lisa" = An donorTo x | give_to (has y) == has x && x /= y = y where y free receipientFrom x | receive_from (has y) == has x & x /= y = y where y free allDonorTo x = sortValues (set1 donorTo x) allReceipientFrom x = sortValues (set1 receipientFrom x) people = [ "John", "Doug", "Lisa" ] test1 = zip people (map allDonorTo people) -=- [("John",["Doug","Lisa"]),("Doug",["Lisa"]),("Lisa",[])] test2 = zip (map allReceipientFrom people) people -=- [([],"John"),(["John"],"Doug"),(["Doug","John"],"Lisa")]