From 623b94df5014b8a363ed51d1a878fbdffee68d71 Mon Sep 17 00:00:00 2001 From: Slash Date: Sun, 9 Aug 2015 23:13:10 +0200 Subject: [PATCH] tail recursion fix --- src/Main.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index e261822..cefcad5 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -107,8 +107,8 @@ readFiles (x:xs) = do f <- BS.readFile x iterategc :: [GameComputation] -> Maybe (Int,Int64) -> Maybe Int -> IO [(([Command], Int), Int)] iterategc gcs tlimit mlimit = do rtl <- timeLimit tlimit - rml <- memLimit mlimit - (gcresult rtl rml) + rml <- memLimit mlimit + (gcresult rtl rml) where gcresult True _ = return best gcresult _ True = return best @@ -116,9 +116,9 @@ iterategc gcs tlimit mlimit = do rtl <- timeLimit tlimit then return best else iterategc (applyNtimes gccompperstep itf gcs) tlimit mlimit where - itf gcs1 = map (\x -> advanceGameComputation x) gcs1 - applyNtimes 1 f x = f x - applyNtimes n f x = f (applyNtimes (n-1) f x) + itf gcs1 = map advanceGameComputation gcs1 + applyNtimes 0 _ accum = accum + applyNtimes n f accum = applyNtimes (n - 1) f (f accum) best = map getBestGameComputation gcs timeLimit :: Maybe (Int,Int64) -> IO Bool