这是模块 - Number1.hs
module Number1(isTriangle) where
isTriangle x y z = if x*x+y*y >= z*z then True
else False
这是主程序Main1.hs
import System.Environment
import Number1
main = do
args<-getArgs
let a = args !! 0
let b = args !! 1
let c = args !! 2
if (IsTriangle a b c) then return(True)
else return(False)
ghc --make Main1.hs
答案 0 :(得分:3)
当您在Main1.hs中拨打isTriangle
时,请使用大写字母'I'来调用它。
确保您的大小写匹配,因为Haskell区分大小写,并确保函数以小写字符开头,因为这是强制性的。
修改 - 整理其他错误
Main1.hs:
import System.Environment
import Number1
main :: IO()
main = do
args<-getArgs
{- Ideally you should check that there are at least 3 arguments
before trying to read them, but that wasn't part of your
question. -}
let a = read (args !! 0) -- read converts [Char] to a number
let b = read (args !! 1)
let c = read (args !! 2)
if (isTriangle a b c) then putStrLn "True"
else putStrLn "False"
Number1.hs:
module Number1(isTriangle) where
{- It's always best to specify the type of a function so that both you and
the compiler understand what you're trying to achieve. It'll help you
no end. -}
isTriangle :: Int -> Int -> Int -> Bool
isTriangle x y z = if x*x+y*y >= z*z then True
else False