3 ms·
Perhaps you misunderstand what this is doing? Or perhaps I misunderstand what you mean. If all you want is to take some kind of search function or backtracking
by setra 10y ago
Perhaps you misunderstand what this is doing? Or perhaps I misunderstand what you mean.
If all you want is to take some kind of search function or backtracking system that generates a stream of results then combining the sub branches is trivial. If you represent a stream as a list and use something like Haskell that is lazy, then all you have to do is literally combine the streams.
myStreamGenerator1 p1 ++ myStreamGenerator2 p2
if you want a different search strategy you can intersperse.
concat . intersperse (mySG1 p1) (mySG2 p2)
the cases being DFS and BFS
- misja111 10y agoWith backtracking you typically have some kind of pruning stragegy. That means keeping track of your best result so far and dont go into branches where it is clear that they can never beat your current winner anymore. So you cannot simply concatenate the results of the subbranches, each new branch needs to be aware of what has been found so far. That can quickly become ugly in pure FP, that's why people have been looking for solutions that do that in an elegant way, e.g. using Monads.
- setra 10y agoPruning can be implemented by just not computing a part of a stream based on some predicate. If you want some kind of global state of the current results then you just pass around the current calculated states. Pure FP has many simple solutions for passing around state.