Calculate all possible solutions. Working state!

This commit is contained in:
JanUlrich 2021-12-01 16:58:27 +01:00
parent 7392a865d3
commit 477c60f841
3 changed files with 21 additions and 9 deletions

View File

@ -13,9 +13,6 @@
<textarea id="fj-input">
class Test extends Object{}
</textarea>
<!-- let rec recursive_monster = fun x ->
{ thing = x;
self = recursive_monster x } -->
</div>
<div id="right">
<pre><div id="ast-output"></div></pre>
@ -27,10 +24,6 @@
<script type="text/javascript" src="highlight.min.js"></script>
<script type="text/javascript" src="target/scala-2.13/fj-typeinference-fastopt/main.js"></script>
<br/>
<p>
Hint: The type inference algorithm processes one class at a time and starts with the first declared class.
Classes can therefore only use methods from classes declared before them.
</p>
<p>Credit: the CSS style sheet of this page was shamelessly stolen from <a href="https://github.com/LPTK/simple-algebraic-subtyping">the Simple-sub demo page</a>.</p>
<p>Credit: the layout of this page was shamelessly stolen from <a href="https://github.com/LPTK/simple-algebraic-subtyping">the Simple-sub demo page</a>.</p>
</body>
</html>

View File

@ -47,7 +47,7 @@ object Unify {
val eqSet = it.get
val rulesResult = applyRules(fc)(eqSet.flatten)
val step2Result = step2(rulesResult, fc)
while(step2Result.hasNext() && results.isEmpty){
while(step2Result.hasNext()){
val substResult = substStep(step2Result.nextProduct().flatten)
substResult match{
case UnchangedSet(eq) => if(isSolvedForm(eq)){

View File

@ -78,4 +78,23 @@ class IntegrationTest extends FunSuite {
val result = FJTypeinference.typeinference(input )
println(result.map(it => Main.prettyPrintAST(it._2)))
}
test("functionClass") {
val input = "class SameType<A extends Object, B extends Object> extends Object{\nA a;\nA b;\nB c;\nget(){return this.c;}\n}\nclass Function<A extends Object, B extends Object> extends Object{\nA ret;\nB param;\napply(a){\nreturn new SameType(this.param, a, this).get().ret;\n}\n\n}"
val result = FJTypeinference.typeinference(input )
println(result.map(it => Main.prettyPrintAST(it._2)))
}
/*
Additional Tests:
class Test extends Object{
m(a, b){return a;}
m(a,b){return b;}
}
class Test2 extends Object{
test(a){return new Test().m(this,a);}
}
*/
}