--to test this load into cabal repl and run "testMain" and start
--the worker in another terminal cabal repl with "main"

replaceGenomes :: Population -> [Genome] -> Population
replaceGenomes pop gns = map (\(a,b,c,d,gs) -> (a,b,c,d,replace gs gns)) pop
  where
    replace :: [Genome] -> [Genome] -> [Genome]
    replace [] _ = []
    replace g [] = g
    replace (x:xs) gs = fndMatch x gs : replace xs gs
    fndMatch :: Genome -> [Genome] -> Genome
    fndMatch x [] = x
    fndMatch x (g:gs)
      | x `eq` g = g
      | otherwise = fndMatch x gs
    eq (Genome _ x y) (Genome _ x1 y1) = x == x1 && y == y1
replaceGenomes :: Population -> [Genome] -> Population
replaceGenomes pop gns = map (\(a,b,c,d,gs) -> (a,b,c,d,replace gs gns)) pop
  where
    replace :: [Genome] -> [Genome] -> [Genome]
    replace [] _ = []
    replace g [] = g
    replace (x:xs) gs = fndMatch x gs : replace xs gs
    fndMatch :: Genome -> [Genome] -> Genome
    fndMatch x [] = x
    fndMatch x (g:gs)
      | x `eq` g = g
      | otherwise = fndMatch x gs
    eq (Genome _ x y) (Genome _ x1 y1) = x == x1 && y == y1
replaceGenomes pop gns = map (\(a,b,c,d,gs) -> (a,b,c,d,replace gs gns)) pop
  where
    replace :: [Genome] -> [Genome] -> [Genome]
    replace [] _ = []
    replace g [] = g
    replace (x:xs) gs = fndMatch x gs : replace xs gs
    fndMatch :: Genome -> [Genome] -> Genome
    fndMatch x [] = x
    fndMatch x (g:gs)
      | x `eq` g = g
      | otherwise = fndMatch x gs
    eq (Genome _ x y) (Genome _ x1 y1) = x == x1 && y == y1