Niceties

Note that we can also use our abstraction in the degenerate case where we compute the product of just 1 domain. In that case, however, there is a bijection between the elements of the domain and the integers 1 to n of the encoding. It turns out to be often convenient to be able to map an element of the domain to its corresponding integer rather than to encode it into the singleton containing that integer. For this reason, we add a feature toint to the class:

<DomainProduct features>= <<
toint

For products of 2 or more domains, this feature is not used and is simply set to unit, but for a 1-product it is a dictionary mapping each domain element to its corresponding integer. Here is how we initialize the feature:

<DomainProduct init method, niceties>=
case Domains of [Dom] then 
   ToInt = {NewDictionary}
in 
   self.toint = ToInt
   for K in Dom do 
      case Val2Ints.of [I] then 
         ToInt.K := I
      end 
   end 
else self.toint=unit end


Denys Duchier
Version 1.2.0 (20010221)