<div dir="ltr"><div><br></div><div>​Thanks, Paolino. I will study this.</div><div><br></div><div>I'll explain my larger goal. Probably should have started with that.<br></div><div><br></div><div>I'm writing algorithms to optimize data structures by backtracking search.</div><div><br></div><div>More specifically, I'm optimizing musical compositions. <br></div><div><br></div><div>But I have several possible representations of a composition and I'd like to swap them in and out.</div><div><br></div><div>I also have several ideas for a search algorithm. The search will function kind of like a chess program, adding notes to the composition one at a time and looking ahead N notes, then using some kind of fitness evaluation function to find the best "next move."</div><div><br></div><div>There are variations on this algorithm possible. The fitness function will be computed by summing the fitness from "evaluation units" which, individually, look at only one aspect of good music. Together they have a more comprehensive view. I can easily try variations on the search by adding or removing "evaluation units".</div><div><br></div><div>For another source of variation, I may use a fully deterministic algorithm, or I may use some pseudorandomness in choosing what paths to search, in various combinations.</div><div><br></div><div>So how do I write a search algorithm when I don't know the type of the data structure or the evaluation units?</div><div><br></div><div>My idea was to create a typeclass, Comp, parameterized on the the composition data structure ('comp'), the data type of a single "move" or step to be added, ('step'), and the type of an evaluation units ('eu').</div><div><br></div><div>class Comp comp eu step | comp -> eu, comp -> step where</div><div>  listPossibleSteps :: comp -> [step]</div><div>  addStep :: comp -> step -> comp</div><div>  evalComp :: eu -> comp -> comp</div><div><br></div><div>This should offer all the necessary computations to implement backtracking search of many flavors.<br></div><div><br></div><div>There's a lot more to how I want to implement this algorithm, mainly that I want to log "analytics" to be able to examine its behavior, so that's where the ReportLog data type and State (or possibly Writer) monad came into it, but never mind that for now. I'm probably not even on the right track with this much.</div><div><br></div><div>D</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>