-- 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 import List import SetFunctions infix 4 =/= 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 x =/= y = (x == y) =:= False 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 = set1 donorTo x allReceipientFrom x = set1 receipientFrom x people = [ "John", "Doug", "Lisa" ] test1 = map allDonorTo people test2 = map allReceipientFrom people