Is there a specific reason you use graphics? It seems to me that the many edges are largely fixed and that your nets only change in the positions of the molecules.
Why don't you just use arrays or some other data structure that allows you to focus on molecules and their positions? For example:
import Data.Array data Molecule = H2O | CO2 | NH3 type Grid = Array (Int, Int) (Maybe Molecule) -- creates an empty grid grid :: Int -> Int -> Grid grid mn = array ((0, 0), (m - 1, n - 1)) assocs where assocs = [((i, j), Nothing) | i <- [0 .. m - 1], j <- [0 .. n - 1]] -- swap the molecules at the specified indices swap :: (Int, Int) -> (Int, Int) -> Grid -> Grid swap (i, j) (u, v) grid = grid // [((i, j), grid ! (u, v)), ((u, v), grid ! (i, j))] -- etc.
(If you have good reason to use graphs, I'm certainly completely out of order, in which case I apologize ...)
Stefan holdermans
source share