Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
 private TypeInference(FreshVariableStream fresh, IImmutableList <IContextEntry> context)
 {
     this._state = new InferenceState(fresh, context);
 }
Exemple #4
0
 private TypeInference(InferenceState inference)
 {
     this._state = inference;
 }
Exemple #5
0
 private TypeInference()
 {
     this._state = new InferenceState(new FreshVariableStream(), ImmutableList <IContextEntry> .Empty);
 }