不在haskell中编译printf

时间:2015-03-12 21:21:12

标签: haskell

伙计们请告诉我为什么这不是编译

putStrLn("The average number of fans for the films of " ++ actor ++ " is : " ++ printf "%.2f\n" (show(countAveFans actor testDatabase))

它很简单,但我不能想为什么它不起作用。我尝试将整个事物转换为字符串并打印出2小数点。谢谢

1 个答案:

答案 0 :(得分:7)

您需要向RealFloat提供String而不是printf,因此请取消对show的调用:

putStrLn $ "The average number of fans for the films of " ++ actor ++ " is : " ++ (printf "%.2f\n" $ countAveFans actor testDatabase)