I have this function:
onData :: IO ([Float]) -> IO ()
onData vals =
do
let res = liftM fsum vals
putStrLn " * Processing ... "
putStrLn res
putStrLn " * Sum : "
putStrLn " * Done Processing"
return ()
fsum :: [Float] -> Float
fsum [] = 0
fsum (x:xs) = x + fsum(xs)
And this function, I am getting an error at the ‘fsum’ call. What am I missing? I just want the value returned.
HaskellParseData.hs:20:14:
Couldn't match expected type `[Char]' with actual type `IO Float'
Expected type: String
Actual type: IO Float
In the first argument of `putStrLn', namely `res'
In a stmt of a 'do' expression: putStrLn res
liftM fsum valshas typeIO Float. You’re giving it a name withlet res = ..., but later trying to use it as aFloat. You should bind it instead, producing aFloatas desired, using<-:It would be more idiomatic for
onDatato take a[Float]instead; you can sequence the action that produces this data elsewhere. Then you could simply use: