<p dir="ltr">Hi Josenildo.</p>
<p dir="ltr">I would personally rewrite your code to something like this:</p>
<p dir="ltr">import Data.Maybe (fromMaybe)<br>
import System.IO (hFlush, stdout)<br>
import Text.Read (readMaybe)</p>
<p dir="ltr">readDef :: a -> String -> a<br>
readDef def = fromMaybe def . readMaybe</p>
<p dir="ltr">isAtLeast :: [a] -> Int -> Bool<br>
isAtLeast ls n<br>
| n <= 0 = True<br>
| null ls = False<br>
| otherwise = isAtLeast ls (n-1)</p>
<p dir="ltr">execNTimes :: Int -> [a] -> IO ()<br>
execNTimes n lst<br>
| n <= 0 = return()<br>
| do<br>
(from, to, quit) <- getCmds<br>
if quit<br>
then let z = slice from to xs<br>
m = foldl lcm 1 z in<br>
print $ m `mod` modVal<br>
else execNTimes (n-1) $ update from to lst<br>
execNTimes (n-1) lst<br>
where<br>
modVal :: Integer<br>
modVal = 1000000007<br>
getCmds :: IO (Int, Int, Bool)<br>
getCmds = do<br>
putStr "Enter command: "<br>
hFlush stdout<br>
cmds <- words <$> getLine<br>
if not $ cmds `isAtLeast` 3<br>
then do<br>
putStrLn "Too few commands"<br>
getCmds<br>
else let from = readDef 0 (cmds !! 1) :: Int<br>
to = readDef 0 (cmds !! 2) :: Int<br>
quit = head cmds == "Q" in<br>
if from < 0 || to >= length lst || from > to<br>
then do<br>
putStrLn "Invalid range"<br>
getCmds<br>
else (from, to, quit)</p>
<p dir="ltr">Do note that the above code is untested, and that it's written on a mobile phone.</p>
<p dir="ltr">I don't know what your intentions with the code are, so I added some error messages and variable names that you might want to change.</p>
<p dir="ltr">About 'xs':<br>
xs is frequently used to mean "rest of list". I would recommend using ls or lst instead to name the whole list.</p>