--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 len = (read (length(m)))::Float
let divia = divi mean l
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" ++ show(tot))
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]
我找不出這個程序有什麼問題。是這樣表示haskell程序問題(類型錯誤)
ERROR file:.\SD.hs:11 - Type error in application
*** Expression : read (length m)
*** Term : length m
*** Type : Int
錯誤你們可以請點我出的問題在這個方案,謝謝 *不匹配:[字符]
你不能在'Int'上調用'read',這是'length'返回的結果。 'read'用於字符串。 – 2011-06-12 17:18:15
你也沒有真正使用這個值'len'。所以只要刪除行'let len =(read(length(m)):: Float' – 2011-06-13 19:08:32