How do I get the OverloadedStrings language extension working?
Asked Answered
S

1

27

I've enabled overloaded strings, but I can't get them to work:

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

Where do I import the IsString instances for ByteString from? Shouldn't this happen automatically? What am I doing wrong?

Smooth answered 28/9, 2010 at 17:29 Comment(2)
Which version of bytestring are you using?Oared
Although I have a solution now, for the record I have bytestring-0.9.1.5.Smooth
C
29

You need to import the .Char8 modules, such as Data.ByteString.Char8 and Data.ByteString.Lazy.Char8

Capello answered 28/9, 2010 at 17:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.