Monday, October 13, 2008

A-star in F# Revisited

A light refactoring of the previous. It pulls in the worst offenders where functions really ought to have been nested; and passes the problem-specific parts around as a bunch of functions in a record type Graph<'a,'b>.

This lets me disentangle the generic graph traversal bit from the specific problem, something I was complaining about yesterday.

Updated to F#1.9.9.9 11-Feb-10.

Since units of measure don't apply to int, I couldn't add a proper type discriminator between the metric for the graph and the node indices (let alone the set of swaps that are of type index XOR index in this representation) as integers. I could make the metric a float to distinguish it by type, so I did that instead.

The "no solution" cases that gave warnings have been provided for, and a few other minimal tweaks have gone into pattern matches. There are a few places where I'm still needlessly binding variables in patterns, but I think that is probably just a venal sin at worst :) -- I consider them to be little different from temporaries-for-clarity.

No comments :