我是Haskell的初学者,在HDBC中我似乎不能从SqlValues中获取字符串。在ghci中:
*Main> import Database.HDBC
*Main Database.HDBC> toSql "test"
SqlString "test"
*Main Database.HDBC> fromSql $ toSql "test"
<interactive>:3:1: error:
• Non type-variable argument
in the constraint: Convertible SqlValue a
(Use FlexibleContexts to permit this)
• When checking the inferred type
it :: forall a. Convertible SqlValue a => a
*Main Database.HDBC> :set -XFlexibleContexts
*Main Database.HDBC> fromSql $ toSql "test"
<interactive>:5:1: error:
• Ambiguous type variable ‘a0’ arising from a use of ‘print’
prevents the constraint ‘(Show a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance [safe] Show SqlValue
-- Defined in ‘Database.HDBC.SqlValue’
instance [safe] Show SqlError
-- Defined in ‘Database.HDBC.Statement’
instance (Show b, Show a) => Show (Either a b)
-- Defined in ‘Data.Either’
...plus 45 others
...plus 184 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In a stmt of an interactive GHCi command: print it发布于 2018-02-17 01:24:02
编译器无法推断出要打印的东西的类型。您可以添加类型注释(如错误消息所示)以使其工作:
Prelude Database.HDBC> fromSql $ toSql "test" :: String
"test"https://stackoverflow.com/questions/48831640
复制相似问题