From fcdda74a4dbbe515c0aad3f428fda3a46990c848 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 27 Dec 2014 20:59:56 +1100 Subject: toInt improved --- src/Grasp/Types/Instruction.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/Grasp') diff --git a/src/Grasp/Types/Instruction.hs b/src/Grasp/Types/Instruction.hs index e618222..f00d2df 100644 --- a/src/Grasp/Types/Instruction.hs +++ b/src/Grasp/Types/Instruction.hs @@ -32,5 +32,10 @@ toFloat :: Instruction -> Maybe Float toFloat (Instruction i) = readMaybe i toInt :: Instruction -> Maybe Int -toInt (Instruction i) = readMaybe i +toInt (Instruction i) = do + f <- (readMaybe :: String -> Maybe Float) i + let g = round f + h = fromIntegral g + r <- if (f == h) then Just g else Nothing + return r -- cgit