title: Can a super class return a subclass? For example for a Marry function?
body: <p>Say I have a method where I want to have with the return type the same as the class. e.g. <code>Cat:Marry(Cat y)</code> or <code>Dog:Marry(Dog y)</code> but I don't want a cat to marry a dog!</p>
  
  <p>Is there a programming language that lets me express this and gives a compile time error if you try and marry a cat and a dog? e.g.</p>
  
  <pre><code>class Animal{
      void Marry(Animal X){
        Console.Write(this+" has married "+X);
     }
  }
  class Cat:Animal{}
  class Dog:Animal{}
  </code></pre>
  
  <p>Thus I want <code>(new Cat()).Marry(new Cat())</code> to be allowed but not <code>(new Cat()).Marry(new Dog())</code></p>
  
  <p>In other words I want the argument type of Marry to match its class. Do any languages do this? (without having to write more than one Marry function?) I am envisaging something like this:</p>
  
  <pre><code>void Marry(caller X){
      Console.Write(this+" has married "+X);
  }
  </code></pre>