public static IType Infer(InferenceState initial, ITerm term) { var inference = new TypeInference(initial).Infer(term, out var result); Console.WriteLine($"Final: {inference}"); var normalized = inference._state.Context.Normalize().Apply(result); return(normalized); }
public InferenceState Unify(out IImmutableList <InferenceState> states) { var state = this; states = ImmutableList.Create(state); while (state.Context.Any(e => e is IConstraint)) { var prefix = state.Context.TakeWhile(e => !(e is IConstraint)); var eqAndSuffix = state.Context.SkipWhile(e => !(e is IConstraint)); if (eqAndSuffix.First() is IConstraint constraint) { state = new InferenceState(state.Fresh, constraint.Solve(prefix.ToImmutableList(), eqAndSuffix.Skip(1).ToImmutableList())); } else { throw new Exception("Should never get here: said there was a constraint, but then didn't find it."); } states = states.Add(state); } return(state); }
private TypeInference(FreshVariableStream fresh, IImmutableList <IContextEntry> context) { this._state = new InferenceState(fresh, context); }
private TypeInference(InferenceState inference) { this._state = inference; }
private TypeInference() { this._state = new InferenceState(new FreshVariableStream(), ImmutableList <IContextEntry> .Empty); }