Reputation: 433
I have a type problem with this function
type Store = [(String, Float)]
evalParser :: String -> Store -> Float -- Boring function who returns a Float
programme :: Store -> IO()
programme store = do
putStr "@EvmInteractif:$> "
instruction <- getLine
putStrLn (show instruction)
if (estCommande (instruction) == True) then
do
res <- evalParser instruction store
putStrLn "TODO: execution de la commande"
programme store
And at the line of res's affectation I have this error :
Couldn't match expected type IO Float' with actual type
Float'
In the return type of a call of `evalParser'
In a stmt of a 'do' block: v <- evalParser expr store
Can someone tell me the rigth syntax please ? Thanks
Upvotes: 1
Views: 551
Reputation: 45826
evalParser
is pure, you don't need to use do notation to call it. To shimmy fix it, you could just wrap it in a return
to stick it in the IO Monad:
res <- return $ evalParser instruction store
To avoid the wrapping/unwrapping altogether though, just don't treat it as an impure value from the start:
let res = evalParser instruction store
Upvotes: 2