我正在尝试编译简单的代码片段。
main = (putStrLn . show) (Right 3.423)
编译导致以下错误:
No instance for (Show a0) arising from a use of `show'
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Show Double -- Defined in `GHC.Float'
instance Show Float -- Defined in `GHC.Float'
instance (Integral a, Show a) => Show (GHC.Real.Ratio a)
-- Defined in `GHC.Real'
...plus 42 others
In the second argument of `(.)', namely `show'
In the expression: putStrLn . show
In the expression: (putStrLn . show) (Right 3.423)
当我从 ghci 执行相同的代码段时,一切都按预期工作。
Prelude> let main = (putStrLn . show) (Right 3.423)
Prelude> main
Right 3.423
所以问题是发生了什么?