Reputation: 1409
I am having this issue the function calculate accepts IO a type and I already have a function that return the same thing but it accepts a as her type. Below is my code. I have been searching around the web for some time but i couldn't manage to fix my error.Tahnks in advance for your help.
pureCalculate :: Expr (Double -> Double -> Double) -> Map.Map String Double -> Double
calculate :: IO(Expr (Double -> Double -> Double)) -> Map.Map String Double -> IO Double
calculate expr args =
do let x = pureCalculate expr args
return x
Upvotes: 1
Views: 157
Reputation: 54058
I believe you want to do something like
calculate ioexpr args = do
expr <- ioexpr
return $ pureCalculate expr args
In order to use a value wrapped in the IO
monad, you first have to extract it using <-
notation, or you can use other functions like fmap
to map a function to the contents.
If you wanted to use fmap
in this case, you could do something like
calculate ioexpr args = fmap (\expr -> pureCalculate expr args) ioexpr
Which is equivalent to
calculate ioexpr args = fmap (`pureCalculate` args) ioexpr
or
calculate ioexpr args = fmap (flip pureCalculate args) ioexpr
Upvotes: 6