Reputation: 536
--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]
i get a error like this : Syntax error in expression (unexpected `}', possibly due to bad layout) i tried fixing indents but nothing worked. can you please help me.
Upvotes: 0
Views: 173
Reputation: 137937
There's no syntax error in this code. So that means you probably have tabs enabled. Remove all tabs in your program, and replace them with explicit spaces.
Once you do this, your program is syntactically and grammatically correct, but has type errors. Here's some slightly more idiomatic code:
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 ]
But you'll need to work on the other errors in your program.
Upvotes: 2