public void Parse(Environment outer, Environment env, Type result, Substitution subst)
        {
            try
            {
                var fullType = Arguments.Select(arg => arg.Parse(env, subst)).Reverse().Aggregate(
                    result,
                    (res, cur) => new FunctionType(cur, res)
                    ).Perform(subst).Generalize(outer);

                var constructor = new DataConstructor(fullType, Name, result, Arguments.Count);

                Func <ImmutableList <LazyValue>, LazyValue> function =
                    arguments => new DataValue(constructor, arguments.ToList());

                for (var i = 0; i < Arguments.Count; ++i)
                {
                    var backup = function;
                    function = arguments => new FunctionValue(arg => backup(arguments.Add(arg)));
                }

                outer.Bind(Name, constructor);
                outer.Bind(Name, fullType);
                outer.Bind(Name, function(ImmutableList.Create(new LazyValue[] {})));
            }
            catch (StackedException ex)
            {
                ex.Push("In a data type constructor declaration: " + ex);
                throw;
            }
        }
Exemplo n.º 2
0
        internal static RigidTypeException Create(string name, Type type)
        {
            var sb  = new StringBuilder();
            var tpp = new TypePrettyPrinter();

            type.PrettyPrint(tpp, sb, 0);
            return(new RigidTypeException(name, sb.ToString(), tpp));
        }
Exemplo n.º 3
0
        internal static OccursCheckException Create(Type lhs, Type rhs)
        {
            var sb1 = new StringBuilder();
            var sb2 = new StringBuilder();
            var tpp = new TypePrettyPrinter();

            lhs.PrettyPrint(tpp, sb1, 0);
            rhs.PrettyPrint(tpp, sb2, 0);
            return(new OccursCheckException(sb1.ToString(), sb2.ToString(), tpp));
        }
Exemplo n.º 4
0
 public void BindType(string name, Type type)
 {
     Types = Types.SetItem(name, type);
 }
Exemplo n.º 5
0
 public void Bind(string name, Type type)
 {
     ValueTypes = ValueTypes.SetItem(name, type);
 }