RosettaCodeData/Task/Jump-anywhere/Haskell/jump-anywhere-6.hs
2023-07-01 13:44:08 -04:00

12 lines
404 B
Haskell

import Control.Applicative
import Control.Monad.Trans.Maybe
gcdFProg2 = forever mainLoop <|> putStrLn "Exiting"
where
mainLoop = putStrLn "Enter two integers, or zero to exit" >>
runMaybeT process >>=
maybe empty (\r -> putStrLn ("GCD: " ++ show r))
process = gcd <$> (lift readLn >>= exitOn 0) <*> lift readLn
exitOn n x = if x == n then empty else pure x