2011-10-21 28 views
1

这里是模块 - Number1.hs不在范围:数据构造IsTriangle

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

+1

附: '如果出现错误,则返回True'否则False'与'something'相同 – user102008

回答

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 
+0

现在我有一个错误 - '没有实例'。 –

+0

你传入的变量不是数字,它们是字符列表。我将粘贴正确的代码到我原来的答案中。 –

+0

谢谢。但它什么都没有返回。对于考试'> Main1 3 4 5' - 没有结果 –

相关问题