title: How can I implement the unification algorithm in a language like Java or C#?
body: <p>I'm working through my AI textbook I got and I've come to the last homework problem for my section:</p>
  
  <p>"Implement the Unification Algorithm outlined on page 69 in any language of your choice."</p>
  
  <p>On page 69, you have the following pseudo-code for the unification algorithm:</p>
  
  <pre><code>function unify(E1, E2);
      begin
          case
              both E1 and E2 are constants or the empty list:
                  if E1 = E2 then return {}
                  else return FAIL;
              E1 is a variable:
                  if E1 occurs in E2 then return FAIL
                   else return {E2/E1}
              E2 is a variable
                  if E2 occurs in E1 then FAIL
                      else return {E1/E2}
              either E1 or E2 are empty then return FAIL
              otherwise:
                  begin
                      HE1 := first element of E1;
                      HE2 := first element of E2;
                      SUBS1 := unify(HE1, HE2);
                      if SUBS1 := FAIL then return FAIL;
                      TE1 := apply(SUBS1, rest of E1);
                      TE2 := apply(SUBS1, rest of E2);
                      SUBS2 := unify(TE1, TE2);
                      if SUBS2 = FAIL then return FAIL;
                           else return composition(SUBS1, SUBS2)
                  end
              end
          end
  </code></pre>
  
  <p>Now, I understand the general concept of unification but I have absolutely no idea how I would even begin to implement this in a language like Java or C#.  </p>
  
  <p>I'm not even sure what the method signature would look like.  What type of variables would it take?  I'm fairly certain I need to return lists to represent predicate calculus constructs but that is a guess.</p>
  
  <p>For example, when it says "E1 is a variable", well, if I'm passing it into the Unify method, how could it be anything but?  I could check for null but would that be different than "empty list"?</p>
  
  <p>Can anyone help me or point me in the right direction for implementing the Unificaiton algorithm in C# or Java?</p>