/// <summary> Allows to clone instances of this type. </summary> protected LinearAPSet(LinearAPSet toClone, string description, bool? appendable) : base(toClone, description, appendable) { this.Associativity = toClone.Associativity; this.PrecedenceComparisonToken = toClone.PrecedenceComparisonToken; this.DomainKind = toClone.DomainKind; }
/// <summary> Adds the specified operator to the respective appendable sets regarding domainKind and associativity, and creates a new precedence token at the specified index in precedences. </summary> /// <param name="index"> The index in workspace.Precedences at which to insert a new EqualPrecedenceOperators set in which to insert the specified operator. Hence 0 is highest precedence (except for operands, which have -1 precedence). </param> public static void Add(Notion @operator, DomainKind domainKind, Associativity associativity, int index = 0) { Contract.Requires(@operator != null); Contract.Requires(0 <= index && index <= PrecedenceElements.Count); if (index != 0) throw new NotImplementedException();//this has to do with the non-set nature of the precedences, since it's actually a list so we need to distinguish insertion from appendage Set newPrecedenceContainer = new LinearAPSet(@operator.Workspace, (IComparable)0);// Precedences.DefinitionSet.Clone("binary |", appendable: true, isConstant: true); Precedences.Append(newPrecedenceContainer); Add(@operator, domainKind, associativity, newPrecedenceContainer); }
static DefaultNotions() { workspace = (Workspace)AppDomain.CurrentDomain.CreateInstance("ASDE.SemanticsEngine", "JBSnorro.Reas.SemanticsEngine.Workspace2").Unwrap(); //defines the only two sets with null parent set. The Unknown = Set.CreateOverarchingOrUnknownSet(workspace, "?", appendable: false, setSelfAsDomain: false); OverarchingSet = Set.CreateOverarchingOrUnknownSet(workspace, "set", appendable: true, setSelfAsDomain: OverarchingSetContainsItself); EmptySet = new Set(workspace, "∅"); var variableSet = new VariableSet(OverarchingSet, "var<set>"); SetDefinition = new GenericSet(variableSet, EmptyCollection<ISet>.ReadOnlyList, variableSet.ToSingletonReadOnlyList(), Variance.Covariant.ToSingletonReadOnlyList(), "set<>"); //AllAppendables is defined by appendable : set<var appendable>, just like set : set<set> (well, actually, set : appendable<set>) //in what set would the variable appendables then be? Could be OverarchingSet: then we have the consistent appendable ⊆ set<var<appendable>> ⊆ var<appendable> ⊆ OverarchingSet //alternatively, I can create it just as appendable : set<set>. I'll do that for now, as it's simpler. //Anyway, this does not impose the constraint that any set appended to appendables is in fact appendable (just like any other constraint isn't implemented at the moment). //Anyway, we can choose the above consistent more convoluted definition of appendables by uncommenting: //var variableAppendableSet = Set.CreateGenericSetParameter(workspace, "var<appendable>", OverarchingSet, appendable: true); //hmmm? //AllAppendables = new GenericSet(SetDefinition, variableAppendableSet.ToSingletonReadOnlyList(), "AllAppendables", appendable: true); //Another alternative, yet less elegant, is to have AllAppendables as singleton (per workspace) type deriving from generic set, such that it can have a variable itself as generic set parameter AllAppendables = new GenericSet(SetDefinition, OverarchingSet.ToSingletonReadOnlyList<ISet>(), "AllAppendables", appendable: true); workspace.Add(SetRelationType.Subset, SetDefinition, OverarchingSet); workspace.Add(SetRelationType.Subset, OverarchingSet, SetDefinition); //defines the sets that will contain ∈, × and → InDefiningSet = Signature.From(Unknown, OverarchingSet, OverarchingSet);//?×set→set CartesianAndSignatureProductType = Signature.From(OverarchingSet, OverarchingSet, OverarchingSet);//set×set→set //defines the notions of ∈, × and → (not their implementations) InDefining = new Notion(InDefiningSet, "∈"); CartesianProduct = new Notion(CartesianAndSignatureProductType, "×"); SignatureProduct = new Notion(CartesianAndSignatureProductType, "→"); NaturalNumbers = new Set(workspace, "Gets the notion representing the natural numbers"); GenericTypeOpeningDelimiterSet = new Set(workspace, "⟨");//Contains the single name that represents the opening delimiter of the special construct in which you can specify type arguments"); GenericTypeClosingDelimiterSet = new Set(workspace, "⟩");//Contains the single name that represents the closing delimiter of the special construct in which you can specify type arguments"); //GenericTypeOpeningDelimiter = new Notion(GenericTypeOpeningDelimiterSet, true, "The type argument/parameter list opening delimiter"); //GenericTypeClosingDelimiter = new Notion(GenericTypeClosingDelimiterSet, true, "The type argument/parameter list closing delimiter"); Booleans = Set.Create(workspace, "Booleans", _ => new Notion(_, "true"), _ => new Notion(_, "false")); BinarySetRelations = Signature.From(OverarchingSet, OverarchingSet, Booleans);//set×set→bool ProperSubset = new Notion(BinarySetRelations, "⊂"); Subset = new Notion(BinarySetRelations, "⊆"); ProperSuperset = new Notion(BinarySetRelations, "⊃"); Superset = new Notion(BinarySetRelations, "⊇"); Intersect = new Notion(CartesianAndSignatureProductType, "∩"); //I believe these two are so far only used in sets (not say integer), hence are in set×set→bool EqualityOperator = new Notion(BinarySetRelations, "="); InequalityOperator = new Notion(BinarySetRelations, "≠"); SetBuilderOpeningBraces = new Set(workspace, "Opening set builder braces. "); SetBuilderClosingBraces = new Set(workspace, "Closing set builder braces. "); SetBuilderEnumerationDelimiters = new Set(workspace, "Enumeration delimiters"); //the set that contains the information on the precedence of linear notations //it is an appendable set of appendable sets of sets: Appendable<Appendable<Set>> //is this the actual set or just its signature? //the operator sets accept all functions of their respective signatures. The LinearAPSet makes sure these functions are transformed into operators //binary operators : set<LHS×RHS→TResult> BinaryOperators = LinearAPSet.Create(Signature.From(new VariableSet(workspace, "LHS"), new VariableSet(workspace, "RHS"), new VariableSet(workspace, "TResult")), DomainKind.Binary); UnaryOperators = LinearAPSet.Create(Signature.From(new VariableSet(workspace, "TOperand"), new VariableSet(workspace, "TResult")), LinearSet.Unary); UnaryPreOperators = LinearAPSet.Create((Signature)UnaryOperators.GenericSetArguments[0], DomainKind.UnaryPrefix); UnaryPostOperators = LinearAPSet.Create((Signature)UnaryOperators.GenericSetArguments[0], DomainKind.UnaryPostfix); //generic operators : ? nothing? NullaryOperators = new LinearAPSet(workspace, "nullary"); workspace.Add(SetRelationType.Subset, UnaryOperators, UnaryPostOperators); workspace.Add(SetRelationType.Subset, UnaryOperators, UnaryPreOperators); Operators = new Set(workspace, "Binary, unary and nullary operators");//Operators is not appendable, even though elements can be appended to it (indirectly). TODO: think about that: hence even a set that is not appendable may not be static workspace.Add(SetRelationType.Subset, BinaryOperators, Operators); workspace.Add(SetRelationType.Subset, UnaryOperators, Operators);//contains unary pre and unary post operators workspace.Add(SetRelationType.Subset, NullaryOperators, Operators); //It is the actual set, but the generic type argument should also be constant. The fact that the generic type argument is specified, is unrelated to appending the generic type argument "as element" (which we don't want to do) //the associativity sets accept all functions of their respective signatures. The LinearAPSet makes sure these functions are transformed into operators AssociativeOperators = new LinearAPSet(workspace, Associativity.Associative); LeftAssociativeOperators = new LinearAPSet(workspace, Associativity.Left); RightAssociativeOperators = new LinearAPSet(workspace, Associativity.Right); UnassociativeOperators = new LinearAPSet(workspace, Associativity.Undefined); //the equal precedence sets accept all functions of operator signature. The LinearAPSet makes sure these functions are transformed into operators. //The function appending to Precedences should do that //Precedences = Operators.CreateSubset("appendable set of operators", isConstant: false).CreateSubset("appendable set of appendable sets of operators", appendable: true, isConstant: true); Precedences = new GenericSet(SetDefinition, Operators.CreateSubset(appendable: true, isConstant: true).ToSingletonReadOnlyList(), "Precedences", appendable: true); PrecedenceElements = new FacadeMapCollection<Notion, Set>((IReadOnlyList<Notion>)workspace.TryGetElements(Precedences), equalPrecOperators => (Set)equalPrecOperators); //THE INNER CONSTRUCT DOESN'T CONSTRUCT AN ACTUAL SET, BUT JUST THE 'TYPE' OF ONE. Does that mean it constructs the canonical one? Well, it refers to the canonical one //AllAppendables it an example of a generic appendable set //the equal precedence operator sets (the elements of Precedences) exemplify a constructed appendable set (which also implies there is a generic appendable set right?) //Precedences is an example of a set containing a reference to a set but not necessarily needing that type (namely Appendable<operators>) // //I could constructing a type always yield the canonical one (i.e. a constant inappendable one), and then you could clone it and set make the clone variable or appendable //only generic sets (i.e. those that have generic parameters) are constructible in this way //then what I now call cloning could in that case also be named constructing: you could then construct some set from the canonical one //however, construct conveys that a new one ie created: by specifying generic argument sets we don't necessarily create a new set since the Set.From method is called //we could adopt "substitute" for constructing generic sets? //we would adopt "adopt" for constructing generic sets? that's better, it doesn't convey necessarily creating a new one //Then cloning it while changing some properties (isConstant, appendable) could then very well be called construct, since it always creates a new one //but suppose that a generic set argument is appendable, then only appendable subsets can be used there (may depend on variance: if it's contravariant, could then also non-appendable sets be used in case an appendable is required? dunno) //but then it seems like adopting a set shouldn't change its appendibility }