The stopLoss function causes the following error:
Could not deduce (Text.Printf.PrintfType (m a0))
arising from the ambiguity check for `stopLoss'
from the context (Monad m,
Text.Printf.PrintfType (m b),
Text.Printf.PrintfType (m a))
bound by the inferred type for `stopLoss':
(Monad m, Text.Printf.PrintfType (m b),
Text.Printf.PrintfType (m a)) =>
Float -> Float -> Float -> m b
Possible fix:
add an instance declaration for (Text.Printf.PrintfType (m a0))
When checking that `stopLoss'
has the inferred type `forall (m :: * -> *) a b.
(Monad m, Text.Printf.PrintfType (m b),
Text.Printf.PrintfType (m a)) =>
Float -> Float -> Float -> m b'
Probable cause: the inferred type is ambiguous
The function:
stopLoss qty pb lossRate = do
let t = qty * pb * (1 + sxf)
printf "Stop Loss at: %.2f\n" ((pb - (t * lossRate) / qty) :: Float)
printf "Lost Money: %.2f\n" ((t * lossRate) :: Float)
Any suggestion is appreciated!
The type of
printfisPrintfType r => String -> r. The following instances ofPrintfTypeare available:(The last one is just to make
printfbehave like if it is polyvariadic.)Here
stopLossis a polymorphic function; the typeIO ()can’t be inferred automatically, and GHC is assuming that the function works for any monad. So, GHC is complaining that the instance ofPrintfTypefor a generic monad does not exist.Providing a type signature like
Float -> Float -> Float -> IO ()should help.