diff options
-rw-r--r-- | src/Plugin/Factorial.hs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/Plugin/Factorial.hs b/src/Plugin/Factorial.hs index 692d20f..97730de 100644 --- a/src/Plugin/Factorial.hs +++ b/src/Plugin/Factorial.hs @@ -23,7 +23,14 @@ factorialAction message = do [] -> return $ Left "I didn't understand" (m:_) -> do let number = last m - return $ Right $ showt $ calculate $ (read number :: Int) + return $ Right $ result (read number :: Integer) + where + result n = case calculate n of + Nothing -> "Input is too large." + Just n -> showt n -calculate :: (Integral a) => a -> a -calculate n = product [1..n] +calculate :: Integer -> Maybe Integer +calculate n + | n <= 0 = Just 0 + | n <= 35000 = Just $ product [1..n] + | otherwise = Nothing |