2010-09-28 59 views
24

我已经启用重载字符串,但我不能让他们的工作:如何使OverloadedStrings语言扩展工作?

$ 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. 

从哪里进口IsString实例为ByteString而来?这不应该自动发生?我究竟做错了什么?

+0

'bytestring'您使用的是哪个版本? – kennytm 2010-09-28 17:33:52

+1

虽然我现在有一个解决方案,对于记录我有bytestring-0.9.1.5。 – dave4420 2010-09-28 18:11:49

回答

28

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