示例#1
0
 public override Type Infer(Environment env, Substitution subst)
 {
     try
     {
         var function = Function.Infer(env.Local(), subst);
         var argument = Argument.Infer(env.Local(), subst);
         var result   = new TypeVariable();
         function.Unify(new FunctionType(argument, result), subst);
         return(result.Perform(subst));
     }
     catch (StackedException ex)
     {
         ex.Push("In an application expression: " + this);
         throw;
     }
 }
示例#2
0
        public override Type Infer(Environment env, Substitution subst)
        {
            var constructor = env.Constructors[Constructor];

            if (constructor.Arity != Arguments.Count)
            {
                throw new PatternArgumentCountException(constructor.Arity, Arguments.Count);
            }

            Type self = new TypeVariable();

            var list = Arguments.Select(arg => arg.Infer(env, subst)).ToList();

            var whole = list.Reverse <Type>().Aggregate(self, (res, arg) => new FunctionType(arg, res));

            whole.Unify(constructor.Type.Instantiate(), subst);
            return(self.Perform(subst));
        }
示例#3
0
        public override Type Infer(Environment env, Substitution subst)
        {
            try
            {
                var  value  = Value.Infer(env.Local(), subst);
                Type result = new TypeVariable();
                foreach (var pattern in Patterns)
                {
                    pattern.Unify(value, result, env, subst);
                }

                return(result.Perform(subst));
            }
            catch (StackedException ex)
            {
                ex.Push("In a match expression: " + this);
                throw;
            }
        }