这是取一个数字,得到它的阶乘和加倍它,但是因为基本情况如果你输入0它给2作为答案所以为了绕过它我使用了if语句,但是在输入时得到错误解析错误'如果'.真的很感激,如果你们可以帮助:)
fact :: Int -> Int
fact 0 = 1
fact n = n * fact(n-1)
doub :: Int -> Int
doub r = 2 * r
factorialDouble :: IO()
factorialDouble = do
putStr "Enter a Value: "
x <- getLine
let num = (read x) :: Int
if (num == 0) then error "factorial of zero is 0"
else let y = doub (fact num)
putStrLn ("the double of factorial of " ++ x ++ " is " ++ …Run Code Online (Sandbox Code Playgroud)