首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Haskell中从HDBC转换SqlValue?

如何在Haskell中从HDBC转换SqlValue?
EN

Stack Overflow用户
提问于 2018-02-17 01:04:06
回答 1查看 103关注 0票数 1

我是Haskell的初学者,在HDBC中我似乎不能从SqlValues中获取字符串。在ghci中:

代码语言:javascript
复制
*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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-17 01:24:02

编译器无法推断出要打印的东西的类型。您可以添加类型注释(如错误消息所示)以使其工作:

代码语言:javascript
复制
Prelude Database.HDBC> fromSql $ toSql "test" :: String
"test"
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48831640

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档