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."); } }
private Initialization <Bind, TR> Map(Sequence <IExpression <Bind, Id, Bind> > environment, IUniverse universe, Class <Bind, Id, ITerm <Bind, Id> > @class, Initialization <Bind, T> initialization) { switch (universe.Polarity) { case Polarity.Forall: switch (@class.Tag) { case Class <Bind, Id, ITerm <Bind, Id> > .Tags.Quantifier: { var quantifier = (Class <Bind, Id, ITerm <Bind, Id> > .Quantifier)@class; var lambda = (Initialization <Bind, T> .Forall.Quantifier)initialization; var returnType = Substitute(environment, quantifier.Dependency, quantifier.Dependent, UseDeclarationF(lambda.Parameter)); var qualifiedBody = new Expression <Bind, Id, T>(universe, returnType, lambda.Body); var dependency = quantifier.Dependency.Fmap(_ => lambda.Parameter); environment = environment.Push(dependency); var body = ConvertF(qualifiedBody.Annotate(environment)); return(new Initialization <Bind, TR> .Forall.Quantifier(lambda.Parameter, body)); } case Class <Bind, Id, ITerm <Bind, Id> > .Tags.Shift: { var shift = (Class <Bind, Id, ITerm <Bind, Id> > .Shift)@class; var @return = (Initialization <Bind, T> .Forall.Shift)initialization; var qualifiedBody = new Expression <Bind, Id, T>(universe.Dual(), shift.Content, @return.Body); var body = ConvertF(qualifiedBody.Annotate(environment)); return(new Initialization <Bind, TR> .Forall.Shift(body)); } default: throw new InvalidProgramException("Should never happen."); } case Polarity.Exists: switch (@class.Tag) { case Class <Bind, Id, ITerm <Bind, Id> > .Tags.Quantifier: { var quantifier = (Class <Bind, Id, ITerm <Bind, Id> > .Quantifier)@class; var pair = (Initialization <Bind, T> .Exists.Quantifier)initialization; var qualifiedLeft = quantifier.Dependency.Fmap(_ => pair.Left); var rightType = Substitute(environment, quantifier.Dependency, quantifier.Dependent, pair.Left); var qualifiedRight = new Expression <Bind, Id, T>(universe, @rightType, pair.Right); var left = ConvertF(qualifiedLeft.Annotate(environment)); var right = ConvertF(qualifiedRight.Annotate(environment)); return(new Initialization <Bind, TR> .Exists.Quantifier(left, right)); } case Class <Bind, Id, ITerm <Bind, Id> > .Tags.Shift: { var shift = (Class <Bind, Id, ITerm <Bind, Id> > .Shift)@class; var delay = (Initialization <Bind, T> .Exists.Shift)initialization; var qualifiedBody = new Expression <Bind, Id, T>(universe.Dual(), shift.Content, delay.Body); var body = ConvertF(qualifiedBody.Annotate(environment)); return(new Initialization <Bind, TR> .Exists.Shift(body)); } default: throw new InvalidProgramException("Should never happen."); } case null: default: throw new InvalidProgramException("Should never happen."); } }
private Continuation <Bind, TR> Map(Sequence <IExpression <Bind, Id, Bind> > environment, IUniverse universe, Class <Bind, Id, ITerm <Bind, Id> > @class, IExpression <Bind, Id, Continuation <Bind, T> > continuation) { switch (universe.Polarity) { case Polarity.Forall: switch (@class.Tag) { case Class <Bind, Id, ITerm <Bind, Id> > .Tags.Quantifier: { var quantifier = (Class <Bind, Id, ITerm <Bind, Id> > .Quantifier)@class; var application = (Continuation <Bind, T> .Forall.Quantifier)continuation.Term; var qualifiedArgument = quantifier.Dependency.Fmap(_ => application.Argument); var argument = ConvertF(qualifiedArgument.Annotate(environment)); return(new Continuation <Bind, TR> .Forall.Quantifier(argument)); } case Class <Bind, Id, ITerm <Bind, Id> > .Tags.Shift: { var shift = (Class <Bind, Id, ITerm <Bind, Id> > .Shift)@class; var extract = (Continuation <Bind, T> .Forall.Shift)continuation.Term; environment = environment .Push(new Expression <Bind, Id, Bind>(universe.Dual(), shift.Content, extract.Identifier)); var qualifiedBody = continuation.Fmap(_ => extract.Body); var body = ConvertF(qualifiedBody.Annotate(environment)); return(new Continuation <Bind, TR> .Forall.Shift(extract.Identifier, body)); } default: throw new InvalidProgramException("Should never happen."); } case Polarity.Exists: switch (@class.Tag) { case Class <Bind, Id, ITerm <Bind, Id> > .Tags.Quantifier: { var quantifier = (Class <Bind, Id, ITerm <Bind, Id> > .Quantifier)@class; var extract = (Continuation <Bind, T> .Exists.Quantifier)continuation.Term; environment = environment .Push(quantifier.Dependency.Fmap(_ => extract.Left)); var rightType = Substitute(environment, quantifier.Dependency, quantifier.Dependent, UseDeclarationF(extract.Left)); environment = environment .Push(new Expression <Bind, Id, Bind>(universe, rightType, extract.Right)); var body = ConvertF(continuation.Fmap(_ => extract.Body).Annotate(environment)); return(new Continuation <Bind, TR> .Exists.Quantifier(extract.Left, extract.Right, body)); } case Class <Bind, Id, ITerm <Bind, Id> > .Tags.Shift: { var shift = (Class <Bind, Id, ITerm <Bind, Id> > .Shift)@class; var force = (Continuation <Bind, T> .Exists.Shift)continuation.Term; return(new Continuation <Bind, TR> .Exists.Shift()); } default: throw new InvalidProgramException("Should never happen."); } case null: default: throw new InvalidProgramException("Should never happen."); } }
private IEnumerable <Bits> SerializeContinuation(Sequence <IExpression <Bind, Id, Bind> > environment, IUniverse universe, Class <Bind, Id, ITerm <Bind, Id> > @class, Continuation <Bind, IEnumerable <Bits> > continuation) { switch (universe.Polarity) { case Polarity.Forall: switch (@class.Tag) { case Class <Bind, Id, ITerm <Bind, Id> > .Tags.Quantifier: { var quantifier = (Class <Bind, Id, ITerm <Bind, Id> > .Quantifier)@class; var application = (Continuation <Bind, IEnumerable <Bits> > .Forall.Quantifier)continuation; foreach (var bit in application.Argument) { yield return(bit); } yield break; } case Class <Bind, Id, ITerm <Bind, Id> > .Tags.Shift: { var shift = (Class <Bind, Id, ITerm <Bind, Id> > .Shift)@class; var extract = (Continuation <Bind, IEnumerable <Bits> > .Forall.Shift)continuation; var binding = SerializeBinding(new Annotated <Bind, Id, Bind>(environment, new Expression <Bind, Id, Bind>(universe.Dual(), shift.Content, extract.Identifier))); foreach (var bit in Encoding.Concatenate(binding, extract.Body)) { yield return(bit); } yield break; } default: { throw new InvalidProgramException("Should never happen."); } } case Polarity.Exists: switch (@class.Tag) { case Class <Bind, Id, ITerm <Bind, Id> > .Tags.Quantifier: { var quantifier = (Class <Bind, Id, ITerm <Bind, Id> > .Quantifier)@class; var extract = (Continuation <Bind, IEnumerable <Bits> > .Exists.Quantifier)continuation; var rightType = Substitute(environment, quantifier.Dependency, quantifier.Dependent, extract.Left); var left = SerializeBinding(new Annotated <Bind, Id, Bind>(environment, quantifier.Dependency.Fmap(_ => extract.Left))); var right = SerializeBinding(new Annotated <Bind, Id, Bind>(environment, new Expression <Bind, Id, Bind>(universe, rightType, extract.Right))); foreach (var bit in Encoding.Concatenate(left, right, extract.Body)) { yield return(bit); } yield break; } case Class <Bind, Id, ITerm <Bind, Id> > .Tags.Shift: { var shift = (Class <Bind, Id, ITerm <Bind, Id> > .Shift)@class; var force = (Continuation <Bind, IEnumerable <Bits> > .Exists.Shift)continuation; yield break; } default: { throw new InvalidProgramException("Should never happen."); } } case null: default: throw new InvalidProgramException("Should never happen."); } }