-1
我使用下面的haskell代碼來捕捉錯誤,同時使用getLine在int中讀取。 CheckInt函數被調用時出現類型不匹配錯誤。請讓我知道我應該在哪裏修改類型。預期類型不匹配haskell
import System.Exit
import Control.Exception
funSeq n = do
if (n<4) then 1 else floor $ (fromIntegral (funSeq (n-1) + funSeq (n-2))) * ((fromIntegral.funSeq) (n-3)/(fromIntegral.funSeq) (n-4))
myFunc ('N':'T':'H':' ': restOfString) = do
checkInt restOfString
let num = (read restOfString :: Int)
if (num < 0) then showError else print (funSeq (num))
main = do
putStrLn "Enter the code: "
code <- getLine
myFunc code
main
checkInt :: String -> IO()
checkInt str = catch (seq (read str :: Int) $ return()) showError
showError :: SomeException -> IO()
showError _ = do
putStrLn("ERR")
exitSuccess
當問這樣的問題時,總是__指出錯誤__,指向該行。 – chi