Esempio n. 1
0
        private Class <Bind, Id, TR> Map(Sequence <IExpression <Bind, Id, Bind> > environment, IUniverse universe, Class <Bind, Id, T> @class)
        {
            switch (@class.Tag)
            {
            case Class <Bind, Id, T> .Tags.Quantifier:
                var quantifier = (Class <Bind, Id, T> .Quantifier)@class;

                environment = environment.Push(quantifier.Dependency);

                var qualifiedDependent = universe.Qualify <Bind, Id, T>(quantifier.Dependent);

                var dependent = ConvertF(qualifiedDependent.Annotate(environment));

                return(new Class <Bind, Id, TR> .Quantifier(quantifier.Dependency, dependent));

            case Class <Bind, Id, T> .Tags.Shift:
                var shift = (Class <Bind, Id, T> .Shift)@class;

                var qualifiedContent = universe.Dual().Qualify <Bind, Id, T>(shift.Content);

                var content = ConvertF(qualifiedContent.Annotate(environment));

                return(new Class <Bind, Id, TR> .Shift(content));

            default:
                throw new InvalidProgramException("Should never happen.");
            }
        }
Esempio n. 2
0
        private static ITerm <Id, Id> ForallType <Id>(IUniverse universe, Id identifier, Func <ITerm <Id, Id>, ITerm <Id, Id> > dependent)
        {
            var dependency = universe.Qualify <Id, Id, Id>(term: identifier);

            var variable = new Term <Id, Id>(new TermF <Id, Id, ITerm <Id, Id> > .Variable(dependency.Term));

            return(new Term <Id, Id>(new TermF <Id, Id, ITerm <Id, Id> > .Type(new Class <Id, Id, ITerm <Id, Id> > .Quantifier(dependency, dependent(variable)))));
        }
Esempio n. 3
0
        private static Func <Term <Guid>, Term <Guid> > CompileDestructor(IUniverse universe, Class <Guid, Guid, ITerm <Guid, Guid> > @class, Func <Term <Guid>, Term <Guid> > focus, Continuation <Guid, Func <Term <Guid>, Term <Guid> > > continuation)
        {
            switch (universe.Polarity)
            {
            case Polarity.Forall:
            {
                return(arguments =>
                    {
                        var initialization = CompileNegativeDestructor(arguments, @class, continuation);

                        return focus(new Term <Guid> .Constructor(initialization));
                    });
            }

            case Polarity.Exists:
            {
                var qualifiedSelfType = universe.Qualify <Guid, Guid, ITerm <Guid, Guid> >(new Term <Guid, Guid>(new TermF <Guid, Guid, ITerm <Guid, Guid> > .Type(@class)));

                var compiledSelfType = Compile(qualifiedSelfType);

                var selfUniverse = new Term <Guid> .Universe(universe.Rank);

                return(arguments =>
                    {
                        var qualifiedSelf = new Qualified <Guid, Term <Guid> >(selfUniverse, compiledSelfType, focus(null));

                        var cont = CompilePositiveDestructor(arguments, @class, continuation);

                        return new Term <Guid> .Destructor(qualifiedSelf, cont);
                    });
            }

            case null:
            default:
                throw new ArgumentOutOfRangeException("polarity");
            }
        }