Skip to content

Instantly share code, notes, and snippets.

@kazu-yamamoto
Created June 13, 2012 05:16
Show Gist options
  • Save kazu-yamamoto/2921996 to your computer and use it in GitHub Desktop.
Save kazu-yamamoto/2921996 to your computer and use it in GitHub Desktop.
String vs ByteString vs Text
{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import Data.ByteString.Char8 ()
import Data.Text (Text)
import qualified Data.Text as T
foo :: String -> Int
foo [] = -1
foo "zoo" = -2
foo ['g','o','o',_] = 8
foo xs = length xs
bar :: ByteString -> Int
bar "" = -1
bar "zoo" = -2
bar bs
| "goo" `B.isPrefixOf` bs = 8
| otherwise = B.length bs
baz :: Text -> Int
baz "" = -1
baz "zoo" = -2
baz ts
| "goo" `T.isPrefixOf` ts = 8
| otherwise = T.length ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment