C# Language Ideas from Planning Domain Modeling #3071
Replies: 26 comments 6 replies
-
What are the semantics of these "features"? how do they relate? what's the benefit of having them? why do we need them? all I see is text. |
Beta Was this translation helpful? Give feedback.
-
Planning domains include more than types, interfaces and delegates. The semantics include first-class:
Predicates, Numeric Fluents and Object FluentsPredicates, numeric fluents and object fluents can be used in a number of scenarios including, but not limited to, .NET logic programming. In the syntax, above, one can see the getter and setter on predicate "F2". With this feature, custom functionality can be provided for obtaining a value from or assigning a value to the predicate, fluent or object fluent. This is referred to in publications as semantic attachments [1][2][3]. ActionsLooking at action definitions, C# language ideas include adding more optional sections to method definitions. One idea for so doing involves code contracts. In issue dotnet/roslyn#119 , C# syntactic expressiveness for
References[1] Dornhege, Christian, Patrick Eyerich, Thomas Keller, Sebastian Trüg, Michael Brenner, and Bernhard Nebel. "Semantic attachments for domain-independent planning systems." In Nineteenth International Conference on Automated Planning and Scheduling. 2009. [2] Hertle, Andreas, Christian Dornhege, Thomas Keller, and Bernhard Nebel. "Planning with Semantic Attachments: An Object-Oriented View." In ECAI, vol. 242, pp. 402-407. 2012. [3] Katz, Michael, Dany Moshkovich, and Erez Karpas. "Semi-Black Box: Rapid Development of Planning Based Solutions." In Thirty-Second AAAI Conference on Artificial Intelligence. 2018. |
Beta Was this translation helpful? Give feedback.
-
I don't think pointing the issue to a bunch of papers written on the subject are going to help. We need concrete examples of where all of this syntax will be used to solve problems in C# programs, why existing syntax is not sufficient to solve those problems and how this new syntax addresses those short comings. You can start with an explanation as to how and why this proposal is different and better than method contracts. This proposal looks much more complicated than method contracts which despite having a champion and being discussed for several years seems to be no closer to actually being implemented as a language feature. |
Beta Was this translation helpful? Give feedback.
-
Method contracts are presently being discussed in issue #105 . I prefer the syntax:
to the syntax:
The two can be said to map to one another, however. One concern with respect to some of the method contract syntax utilized in ongoing discussions is readability when defining lambda expressions. I think that this is more readable:
|
Beta Was this translation helpful? Give feedback.
-
i'm not sure what the purpose of this issue is. Is this a proposal for changes to c#?
I think concerns about the syntax for contracts should be given to those proposals. Note that syntax is usually the last thing figured out for complex language topics |
Beta Was this translation helpful? Give feedback.
-
I was hoping to open a discussion issue rather than a specific proposal issue. Perhaps a variety of new C# programming language features can be thought of when considering the modeling of planning domains. The method contracts syntax topic was an example. |
Beta Was this translation helpful? Give feedback.
-
What is a planning domain? Why would it benefit from language changes instead of just apis? |
Beta Was this translation helpful? Give feedback.
-
Example Planning Domain and ProblemHere is a STRIPS example of a planning domain definition [2]:
With a domain, we can define a problem. Here is an example of a problem definition:
The example domain definition describes or models a world with: robots, grippers, balls, rooms. It defines three actions: move, pick and drop. The gist is that robots can be in rooms, move between rooms, pick things and and drop things with their grippers. The example problem definition describes a specific initial situation: there are two rooms (rooma, roomb), two balls (ball1, ball2), two grippers (left, right), the robot is in a room (rooma), the grippers are empty, ball1 is in rooma, ball2 is in roomb. The example problem definition also describes a goal: that a specific ball (ball1) be in a specific room (roomb). The planner processes the domain and the problem and outputs a plan. In the example, the output involves a robot moving around, using its grippers... picking up a ball, moving to a room, dropping a ball. The example domain and problem, while illustrative, don't showcase the newest features of PDDL. A concise history of the PDDL language (versions 1.2, 2.1, 2.2, 3.0 and 3.1) is available here: https://planning.wiki/ref . There also exist various successors / variants / extensions to PDDL. A number of PDDL examples are available at: https://github.com/potassco/pddl-instances . PDDL and Visual Studio CodeInterestingly, there is language support for PDDL in Visual Studio Code. The project by Jan Dolejsi is available here: https://marketplace.visualstudio.com/items?itemName=jan-dolejsi.pddl . One can define domains and problems in Visual Studio Code and easily connect to planner services which, at the push of a button, provide solutions or plans. The default such service is http://planning.domains which also allows developers to author planning domains and problems on its website: http://editor.planning.domains/ . Making Planning Domain Modeling More ApproachableSome opine that planning domain modeling could be made more approachable. There is a learning curve to using PDDL and users intuitively understand other modern programming languages such as C#. Regardless of the language used, preconditions and effects are described as the most difficult aspect of writing planning domains for new users [1]. .NETWere a new or existing .NET language to support planning domain modeling scenarios, there would be to consider first-class: types, constants, predicates, numeric fluents, object fluents, constraints, rules and actions. Some of these constructs could convenience or facilitate other .NET languages, e.g. logic programming languages. Adding the aforementioned constructs could be CLI/CLR topics or class library topics. PDDL supports union types which is why issue #399 is relevant. Beyond parsing PDDL (and/or a new language) into a useful runtime model, one can ask: could a planning domain be comprised of contents from multiple files or modules? Could planning domain contents "compile to" or be stored in modular, reusable .NET assemblies? References[1] Katz, Michael, Dany Moshkovich, and Erez Karpas. "Semi-Black Box: Rapid Development of Planning Based Solutions." In Thirty-Second AAAI Conference on Artificial Intelligence. 2018. |
Beta Was this translation helpful? Give feedback.
-
It looks to me tthat planning domain modeling would be better served by creating a DSL that compiles to CIL or C# rather than extension of C# itself. If you think that a specific feature could have broad applicability (like union types you've mentioned), why not open a separate issue for it? |
Beta Was this translation helpful? Give feedback.
-
I'm not really seeing what this has to do with C#. Are tehre specific changes you are asking for in particular? Can you distill this down at all? |
Beta Was this translation helpful? Give feedback.
-
The above language in the rough-draft sketch can be described as a C#-based DSL. When one bases a DSL on C#, in addition to the DSL being approachable to most software developers, one can refer to existing C# projects and files when eventually working on code editor and IDE integration (e.g. https://github.com/dotnet/csharp-tmLanguage for syntax highlighting). Those are good recommendations with respect to compiling the new DSL to CIL or transpiling it to C#. Presently, in the aforementioned software library project, PDDL and new DSL both parse into the same object model which includes its own custom type system. Transpiling from PDDL to the new DSL should be readily implementable. As PDDL and the new DSL include union types, issue #399 is relevant. That is, if .NET supported intersection and union types, the new DSL (as well as a number of other languages) could more readily compile to CIL. Distilling, some specific ideas for C#/.NET:
|
Beta Was this translation helpful? Give feedback.
-
What are these things? |
Beta Was this translation helpful? Give feedback.
-
Boolean PredicatesIn a strongly-typed logical model, a predicate can be modeled as having zero or more typed parameters and, when provided with arguments, results in a compound expression. Let For example, we can define
Depending upon how we want to address time, we might also choose to define
Numeric FluentsA numeric fluent is where the compound expression is, instead of Boolean, numeric. For example,
Object FluentsAn object fluent is where the compound expression is, beyond Boolean or numeric, of an arbitrary type from the domain or model. Adding Custom Getters and SettersNext, we can add getters and setters to indicate that a particular predicate provides custom procedures for getting the value of a compound expression or assigning a value to it. This is based on “semantic attachments” [1][2].
There should be a means of efficiently checking whether a predicate defines custom procedures for its getter and setter. Related Topic: Multidimensional PropertiesA somewhat related topic could be multidimensional properties: https://docs.microsoft.com/en-us/cpp/dotnet/how-to-use-properties-in-cpp-cli?view=vs-2019#multidimensional-properties . Using multidimensional properties, a C++/CLI example:
or, using static multidimensional properties:
TerminologyThe terminology “compound” comes from Prolog syntax and semantics. The terminology “numeric fluent” and “object fluent” are from the history of the PDDL language. The terminology “semantic attachments” comes from Weyhrauch [1] to describe the attachment of an interpretation to a predicate symbol using an external procedure. References[1] Weyhrauch, Richard W. "Prolegomena to a theory of mechanized formal reasoning." Artificial intelligence 13, no. 1-2 (1980): 133-170. |
Beta Was this translation helpful? Give feedback.
-
I don't really see why you would need anything special here as this looks to be basically identical to what .net and c# already have with delegates |
Beta Was this translation helpful? Give feedback.
-
Predicates, numeric fluents and object fluents more closely resemble properties than either methods or delegates as one can both get values from and assign values to compound expressions. When one defines custom getters and setters, this makes sense:
but so does this:
With respect to ideas for C#, we can add multidimensional properties to the list.
.NET and C++/CLI support multidimensional properties. Multidimensional properties can occur in .NET assemblies. It appears that C# doesn’t yet support the scenario – one can’t yet utilize multidimensional properties (other than indexers) in C#. See also: issue #471 where "multidimensional properties" are referred to as "indexed properties". P.S.: The LINQ expression tree model and the dynamic language runtime could also be relevant in the context of multidimensional properties or indexed properties. Developers would expect to be able to utilize any new C# syntax with the |
Beta Was this translation helpful? Give feedback.
-
You can do that with both delegates and methods. :)
this is already supported in C# today. |
Beta Was this translation helpful? Give feedback.
-
That is interesting that this can be achieved in C# today. Could you provide an example, hyperlink or gist? |
Beta Was this translation helpful? Give feedback.
-
Sure! ref bool P(int x, int y, int z) { ... }
// ...
P(1, 2, 3) = true; |
Beta Was this translation helpful? Give feedback.
-
Alternatively, just use indexers, and the user can write: P[1, 2, 3] = true; Supported since C# 1.0. Nice and simple and easy to understand. |
Beta Was this translation helpful? Give feedback.
-
Thank you. It looks like one can achieve predicates, numeric fluents and object fluents in various ways in C#. In addition to the "()" brackets, I also like the "[]" brackets. With "[]" brackets, source code might be more readable with simultaneous uses of predicates and methods. A reason that multidimensional or indexed properties could be useful for predicates involves storing them in assemblies. Similar to extension methods, one of a number of ways that a set of predicates could be stored in an assembly for use across .NET languages resembles:
Languages with support for first-class predicates could, then, find these metadata-described predicates in assemblies and provide them for developers. Some metadata attributes would be useful for ensuring that static properties of static types were, indeed, predicates. Other metadata would be useful (e.g. upon getters and setters) for differentiating kinds of predicates or for describing their implementation details. |
Beta Was this translation helpful? Give feedback.
-
Note, this is possible today in C#, just slightly annoying for the library author (not hte consumer). Today, you can write: public static class Domain
{
public static CarryingThingy Carrying => new CarryingThingy(this);
public struct CarryingThingy
{
private readonly Domain _domain;
internal CarryingThingy(Domain domain) => _domain = domain;
public bool this[Robot r, Ball b]
{
get { return (bool)_domain.Database.Query("Namespace.Domain.Carrying", r, b); }
set { _domain.Database.Store("Namespace.Domain.Carrying", r, b, value); }
}
}
} consumer can then write: |
Beta Was this translation helpful? Give feedback.
-
If you're generating this (which seems to be the case with Note: this approach has practically no overhead at runtime. .net core is great at just eliding all of this. so This approach of typesafe struct wrappers is super common and performant in .net. |
Beta Was this translation helpful? Give feedback.
-
This feels like this could be done by you using Roslyn Analyzers: https://docs.microsoft.com/en-us/visualstudio/code-quality/roslyn-analyzers-overview?view=vs-2019 You can define your own attributes and encode whatever semantics you want for them. you tehn write an analyzer to catch misuses of them. :) |
Beta Was this translation helpful? Give feedback.
-
Thanks again. There are now multiple possibilities for storing sets of predicates, numeric fluents and object fluents in .NET assemblies. Interestingly, logical rules could be added to |
Beta Was this translation helpful? Give feedback.
-
The using static directive is interesting with both approaches. With the approach that @CyrusNajmabadi shared, one can explore first-class predicates in C# today: using System;
using System.Runtime.CompilerServices;
using static Namespace.Domain;
namespace Namespace
{
public interface IKnowledgebase
{
object Query(string predicate, params object[] tuple);
void Store(string predicate, object value, params object[] tuple);
/* ... */
}
public class Domain
{
public class Robot { }
public class Ball { }
static IKnowledgebase s_storage = null;
public static _CarryingPredicate Carrying
{
get
{
return new _CarryingPredicate(s_storage);
}
}
public struct _CarryingPredicate
{
public _CarryingPredicate(IKnowledgebase kb)
{
this.m_kb = kb;
}
readonly IKnowledgebase m_kb;
public bool this[Robot r, Ball b]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return (bool)m_kb.Query("Namespace.Domain.Carrying", r, b); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set { m_kb.Store("Namespace.Domain.Carrying", value, r, b); }
}
}
}
public class Consumer
{
public void foo(Robot robot, Ball ball)
{
if (Carrying[robot, ball]) // first-class predicates
{
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
For those interested in these topics, I've started some new sketches on these topics which are available here: w3c-cg/planning#28 . The new sketches are of a C/C++/C#/Java/JavaScript-inspired language with more first-class language constructs including: templates, types, operators, predicates, rules, expressions, graphs, constraints, preferences, and attributes/decorators. The language being sketched there isn't one intended for being compiled to a DLL or JAR, or to assembly code. It is, instead, intended for being transpiled into a Semantic Web format, e.g., TriG. Planners and solving algorithms, would, as envisioned, load input resources in this format (e.g., from a compressed archive file and/or from a number of Web resources). Interestingly, transpiling allows first-class attributes and decorators to be able to update, to add to, the output graphs of other language constructs during the process of transpiling. This feature is introduced in the sketch available here: w3c-cg/planning#28 (comment) . In the sketch, an example attribute or decorator is defined, The language sketches are a work in progress and there remains much work to be done. Maybe these sketches can inspire some new C#/.NET features. Comments, feedback, questions, are welcomed either here or there! |
Beta Was this translation helpful? Give feedback.
-
Introduction
I am working on a .NET library with which to develop automated planning software. In the course of the project, I was creating an object model to parse PDDL planning domains and problems into. Planning domains include: types, constants, predicates, numeric fluents, object fluents, constraints, rules and actions.
While working on that object model for planning domains and problems, I started creating a new modeling / programming language. The new language is based on C#. It is a work in progress.
I'd like to share a rough-draft sketch of the new language in hopes that it might inspire some new C# and .NET features.
Rough-draft Sketch
Related Issues
#399 - Discussion: Union and Intersection types
Beta Was this translation helpful? Give feedback.
All reactions