php-lcs icon indicating copy to clipboard operation
php-lcs copied to clipboard

Add Hack type definitions

Open jesseschalken opened this issue 8 years ago • 2 comments

For usage with Hack, a .hhi file containing this somewhere in the repo should suffice:

<?hh // decl

namespace Eloquent\Lcs;

interface LcsSolverInterface<T> {
  public function longestCommonSubsequence(
    array<T> $sequenceA,
    array<T> $sequenceB,
  ): array<T>;
}

class LcsSolver<T> implements LcsSolverInterface<T> {
  public function __construct(?(function(T, T): bool) $comparator = null);
  public function comparator(): (function(T, T): bool);
  public function longestCommonSubsequence(
    array<T> $sequenceA,
    array<T> $sequenceB,
  ): array<T>;
}

jesseschalken avatar Jan 17 '17 07:01 jesseschalken

That's pretty cool! Do you know if there's any way to write an automated test that checks that this definition is correct? I don't have any experience with Hack, but I'm happy to update the HHVM Travis build for this repo.

ezzatron avatar Jan 17 '17 10:01 ezzatron

I suppose you could write a unit test in Hack that passes the type checker using the .hhi file and also runs correctly on HHVM against the PHP code. That would effectively test that the type definition and PHP code correspond.

jesseschalken avatar Jan 17 '17 11:01 jesseschalken