Haskell Search Control

Suppose you are writing a program that searches for exponentially large or infinite space: gameplay, theoretical testing, optimization, etc., where you cannot search the entire space, and the quality of the results largely depends on the choice of parts. This search within the available resources.

In an impatient language, this is conceptually straightforward: the language allows you to specify the order of evaluation, and you use this to control which parts of the search space to evaluate in the first place. (In practice, this tends to become messy and complicated because your code layout for controlling output is mixed up with the definition of the problem, which is one of the reasons I'm interested in how to do this in a lazy language. Conceptually straightforward.)

In a lazy language like Haskell, you cannot do that. I can imagine two ways to do this:

  • Write down the code, which depends on the exact evaluation order, which is selected by the current version of the compiler you use, with the optimization flags used, so that everything happens in the correct order. This will likely lead to maintainability problems.

  • Write the code that writes the code, in particular, write the code that converts the definition of the problem along with a set of heuristics into a sequence of instructions in an impatient language that indicates the exact order in which everything should be done. This seems to make sense if you are willing to pay upfront costs.

Are there any other recommended ways to do such things?

+4
source share
2 answers

A typical way to do this in a lazy language is to define the search space as a (possibly infinite) data structure and then write any strategy that you want to use to navigate this structure individually. Thus, you control the strategy used, but it does not depend on the definition of the problem.

+5
source

You can make parts of your haskell-based code based on rigorous evaluation

http://www.haskell.org/haskellwiki/Performance/Strictness

+1
source

All Articles