15.3.7 Application to Agreement Checking

<Test products of finite domains>=
%% import the domain functor
 
declare [Dom] = {Module.link ['domain.ozf']}  
declare 'export'(make:MakeDomain  
                 product:Product ...) = Dom
 
%% define a single domain
 
declare DomainSpec = [sg pl]  
declare Domain = {MakeDomain DomainSpec}
declare I = {Domain.toIndex sg} {Inspect I}
declare E = {Domain.toElement 0} {Inspect E}
 
%% define a product of domains
 
declare DomainSpecs = [[sg pl] [1 2 3] [masc fem]]
declare Domains = {Map DomainSpecs MakeDomain}
declare Domain = {Product Domains}
 
%% convert vectors to indexes %%%%%%%%%%
                               
for V in  [[sg 1 masc]
           [pl 1 masc]
           [sg 2 masc]
           [pl 2 masc]
           [sg 3 masc]
           [pl 3 masc]
           [sg 1 fem]
           [pl 1 fem]
           [sg 2 fem]
           [pl 2 fem]
           [sg 3 fem]
           [pl 3 fem]]
do 
   {Inspect {Domain.toIndex V}}
end 
 
{Inspect Domains}
                               
%% convert indexes to vectors %%%%%%%%%%
                               
for I in 0..11 do 
    {Inspect {Domain.toElement I}}
end 
 
%% test agreement %%%%%%%%%%%%%%%%%%%%%%%%
                               
declare proc{WaitUntilStable}  %% works only for encapsulated search
           {FD.distribute ff [1]}    
        end  
 
 
declare fun{Agree A1 A2}
           proc{Constraints As}   
              FD1 FD2   
              FD1 :: {Map A1 Domain.toIndex}
              FD2 :: {Map A2 Domain.toIndex}
              FD1 = FD2
              {WaitUntilStable}
              Inds = {FD.reflect.dom FD1}
           in  
              As = {Map Inds Domain.toElement}
           end  
        in  
           {Search.all Constraints 1 _}.1
        end  
{Inspect 'agreement intersection'}                               
{Inspect {Agree
          [[sg 2 masc] [pl 3 masc] [pl 3 fem]]
          [[sg 2 masc] [pl 3 fem]  [pl 2 fem]]}}


Denys Duchier, Claire Gardent and Joachim Niehren
Version 1.3.99 (20050412)