Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Add Hack type definitions #2

Open
jesseschalken opened this issue Jan 17, 2017 · 2 comments
Open

Add Hack type definitions #2

jesseschalken opened this issue Jan 17, 2017 · 2 comments

Comments

@jesseschalken
Copy link

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>;
}
@ezzatron
Copy link
Contributor

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.

@jesseschalken
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants