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;
            }
        }
Ejemplo n.º 2
0
        public Type Infer(Environment env)
        {
            var subst = new Substitution();
            var ret   = Infer(env, subst);

            ret.Perform(subst);
            env.Perform(subst);
            return(ret);
        }
Ejemplo n.º 3
0
        private Tuple <Type, LazyValue> Evaluate(string input)
        {
            var parser     = new Parser.Parser(input);
            var expression = parser.Result;
            var local      = _env.Local();
            var type       = expression.Infer(local);
            var value      = expression.Evaluate(local);

            _env = local;
            return(Tuple.Create(type, value));
        }
Ejemplo n.º 4
0
 protected void AddToEnvironment(Environment env)
 {
     foreach (var clause in Clauses)
     {
         clause.PrepareValueEnvironment(env);
     }
     foreach (var clause in Clauses)
     {
         clause.AddValueToEnvironment(env);
     }
 }
Ejemplo n.º 5
0
 public override Type Infer(Environment env, Substitution subst)
 {
     try
     {
         var annotated = Type.Parse(env, subst, true);
         var inferred  = Body.Infer(env, subst);
         annotated.Unify(inferred, subst);
         return(annotated.Perform(subst));
     }
     catch (StackedException ex)
     {
         ex.Push("In an annotated pattern: " + this);
         throw;
     }
 }
Ejemplo n.º 6
0
        public override Type Infer(Environment env, Substitution subst)
        {
            try
            {
                foreach (var clause in Clauses)
                {
                    clause.PrepareTypeEnvironment(env, subst);
                }
                foreach (var clause in Clauses)
                {
                    clause.AddTypeToEnvironment(env, subst);
                }

                return(TypeDefaults.Unit);
            }
            catch (StackedException ex)
            {
                ex.Push("In a def-expression: " + this);
                throw;
            }
        }
Ejemplo n.º 7
0
 public Program()
 {
     _env = new Environment();
 }
Ejemplo n.º 8
0
 public override Type Infer(Environment env, Substitution subst)
 {
     return(new CharacterType());
 }
Ejemplo n.º 9
0
 public override LazyValue Evaluate(Environment env)
 {
     return(new CharacterValue(Value));
 }
Ejemplo n.º 10
0
 public override bool Match(LazyValue value, ref Environment env)
 {
     return(Body.Match(value, ref env));
 }
Ejemplo n.º 11
0
 public abstract Type Infer(Environment env, Substitution subst);
Ejemplo n.º 12
0
 public abstract LazyValue Evaluate(Environment env);
Ejemplo n.º 13
0
 public override LazyValue Evaluate(Environment env)
 {
     AddToEnvironment(env);
     return(Defaults.Unit);
 }
Ejemplo n.º 14
0
 public override Type Infer(Environment env, Substitution subst)
 {
     return(new FloatingType());
 }
Ejemplo n.º 15
0
 public override LazyValue Evaluate(Environment env)
 {
     throw new NotImplementedException();
 }