Opened at 2017-11-17T19:03:29Z
Last modified at 2023-06-22T19:34:56Z
#1115 new planned
Monadic nature of backtracking tree-exploring operations
| Reported by: | Ichthyostega | Owned by: | |
|---|---|---|---|
| Priority: | nice | Milestone: | 3release |
| Component: | lumiera | Keywords: | design research architecture sanity performance ongoing |
| Sub Tickets: | #1116, #1117, #1245 | Parent Tickets: | #55, #966 |
Description (last modified by )
Do we need Monads?
Not sure about that one...
It is not clear if an basically imperative state based language like C++ can benefit from Monads.
Even more, it is not clear if »Monads« are a Design Pattern, which means they would pave the way
towards clear, concise, self explanatory and sane code. It could well be, that Monads are rather some
kind of Anti-Pattern -- something which seems obvious and fascinating, yet in fact increases the
code complexity for no good reason.
That being said — it is obvious we have a recurring pattern when it comes to "resolving solutions":
Due to a basic trend in the overall design of Lumiera, at various places we get the task to search for
a solution, or to figure out a binding from given configuration, rather than executing predetermined
hard-wired logic. All these algorithms share the common property that some kind of opaque state
need to be explored and expanded upon, and typically the (highly complex) mechanics of performing
this exploration can (and in fact should) be separated from the specifics of the target domain in question.
To add to this challenge, in most cases we've encountered thus far, it is desirable, or even mandatory
to perform this algorithmic computation demand-driven (pull principle), because this is the only way
to get along with a more-or-less fixed, pre-allocated memory buffer.
From the theoretical side of computer science (or mathematics, you'd might say) we know, that any
computation with these properties (tree expanding, backtracking) can be cast as a combination of
Monads. So the question to investigate and clarify would be, if taking such an approach will
- allow for generic algorithm building blocks, which can be combined more easily than developing the computation logic from scratch each time
- lead to more readable code, which focuses better on the actual point in question
- allows for a clean separation between the »mechanics« of the evaluation and the specifics of the target domain logic
- can be implemented without producing serious overhead (to be clear: garbage collection is not desirable).
Change history (4)
comment:1 by , at 2017-11-17T19:40:43Z
| blockedby: | → 1116, 1117 |
|---|
comment:3 by , at 2023-06-22T19:31:53Z
| blockedby: | 1116, 1117 → 1116, 1117, 1245 |
|---|---|
| blocking: | 55 → 55, 966 |
| Description: | modified (diff) |
| Keywords: | ongoing added |
| Milestone: | 0integration → 3release |
- the initial design, directly based on the »Monads« from functional programming, was a failure and has been retracted now
- yet the second design built around a pipeline builder is able to adapt to various situations and can also integrate monad-like exploration patterns as a special case
So this second design is now renamed to IterExplorer and used to build exploring and backtracking evaluations.
Questions to re-assess later
- can this solution be reconciled with the ranges from the standard library, and with evaluation pipelines?
- can the obnoxious error messages be improved when using appropriate Concepts (C++20)
- how does it behave in terms of performance and code size?
comment:4 by , at 2025-12-25T00:00:00Z
| blockedby: | 1116, 1117, 1245 |
|---|---|
| blocking: | 55, 966 |
| Parent Tickets: | → 55, 966 |
| Sub Tickets: | → 1116, 1117, 1245 |
Migration MasterTickets ⟼ Subtickets-plugin

The first experiences with the design chosen for the new pipeline builder, the
TreeExplorer(#1117) look promising. This second design attempt is a compromise, insofar we do not attempt to build a classic monad structure (as inIterExplorer, which incidentally can be now completely superseded by the new design); rather we mostly stick to the well established functional pipeline pattern, but integrate a "monadic element" in the form of theexpandChildren()operation.TreeExplorerhas the tendency to bloat the executable, both by heavy inlining and the generation of lots of very special nested template instantiations.