Haskell程序中的语法错误

时间:2011-06-12 16:45:34

标签: haskell syntax

--Standered Diviation 
module SD where
diviation:: IO ()
diviation = do
            putStrLn "Enter Students Marks"
            marks <- getLine
            let m = ( read marks)::[Float]
            let x = sum' m
            let mean = (fromIntegral x)/(fromIntegral $ length )
            let divia = divi mean length(m) 
            let std = map (^2) divia
            let stdd = xx length(m-1) m
            let final = map sqrt stdd
            let tot = sum final 

            if(m==[])then
                    putStrLn"empty List"
            else do
                    putStrLn("The Standered Divation is" ++ show(tot))


sum' :: (Num a) => [a] -> a
sum' = foldl (+) 0

avg::Float->Float->Float
avg a b = (fromIntegral a)/(fromIntegral b)

divi::Float->[Float]->[Float]
divi a xs = [x-a | x <- xs]

xx::Float->[Float]->[Float]
xx a xs = [x/a|x<-xs]

我得到这样的错误:表达式中的语法错误(意外的`}',可能是由于布局错误) 我试图修复缩进但没有任何效果。你能帮我么。

1 个答案:

答案 0 :(得分:2)

此代码中没有语法错误。这意味着您可能已启用了选项卡。删除程序中的所有选项卡,并用显式空格替换它们。

执行此操作后,您的程序在语法和语法上都是正确的,但存在类型错误。这是一些稍微更惯用的代码:

sum' :: (Num a) => [a] -> a
sum' = foldl' (+) 0

avg  :: Double -> Double -> Double
avg  a b = fromIntegral a / fromIntegral b

divi :: Double -> [Double] -> [Double]
divi a xs = [ x-a | x <- xs]

xx   :: Double -> [Double] -> [Double]
xx   a xs = [ x/a | x <- xs ]

但是你需要处理程序中的其他错误。