【问题标题】:How do I get the OverloadedStrings language extension working?如何让 OverloadedStrings 语言扩展工作?
【发布时间】:2010-09-29 01:37:50
【问题描述】:

我启用了重载字符串,但我无法让它们工作:

$ cat overloadedstrings.hs 
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL

lazy :: BL.ByteString
lazy = "I'm a lazy ByteString"

strict :: B.ByteString
strict = "I'm a strict ByteString"

$ ghci
GHCi, version 6.12.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :l overloadedstrings.hs 
[1 of 1] Compiling Main             ( overloadedstrings.hs, interpreted )

overloadedstrings.hs:7:7:
    No instance for (Data.String.IsString BL.ByteString)
      arising from the literal `"I'm a lazy ByteString"'
                   at overloadedstrings.hs:7:7-29
    Possible fix:
      add an instance declaration for
      (Data.String.IsString BL.ByteString)
    In the expression: "I'm a lazy ByteString"
    In the definition of `lazy': lazy = "I'm a lazy ByteString"

overloadedstrings.hs:10:9:
    No instance for (Data.String.IsString B.ByteString)
      arising from the literal `"I'm a strict ByteString"'
                   at overloadedstrings.hs:10:9-33
    Possible fix:
      add an instance declaration for (Data.String.IsString B.ByteString)
    In the expression: "I'm a strict ByteString"
    In the definition of `strict': strict = "I'm a strict ByteString"
Failed, modules loaded: none.

我从哪里导入ByteStringIsString 实例?这不应该自动发生吗?我做错了什么?

【问题讨论】:

  • 您使用的是哪个版本的bytestring
  • 虽然我现在有一个解决方案,但我有 bytestring-0.9.1.5 的记录。

标签: haskell ghc overloaded-strings


【解决方案1】:

需要导入.Char8模块,如Data.ByteString.Char8Data.ByteString.Lazy.Char8

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-20
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 2022-06-18
    • 1970-01-01
    相关资源
    最近更新 更多