prg-titech / pbatakjava

Version polymorphic implementation of BatakJava
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Polymorphic hash example #30

Closed ansharlubis closed 1 year ago

ansharlubis commented 1 year ago

With monomorphic BatakJava, we can easily make sure that hash values aren't mixed up with the wrong versions by specifying the versions.

However, the Dir class must have the ability to use different versions of Hash.

public class Dir ver 1 «V» {
  public String[] getFiles() {
    String[] files = new String[1];
    files[0] = "a";
    return files;
  }
  public boolean exists(HashValue#V# h) {
    String[] fs = this.getFiles();
    // we can also reinforce hash with a specific version
    Hash#V# hash = new Hash#V#();
    for (int i = 0; i < fs.length; i++) {
      if (hash.match(fs[i], h)) {
        return true;
      }
    }
    return false;
  }
}
ansharlubis commented 1 year ago

I found some issues with method declarations not included in the result.

Solution: Abstract all the type access except for class instances' access