Created
June 13, 2012 05:16
-
-
Save kazu-yamamoto/2921996 to your computer and use it in GitHub Desktop.
String vs ByteString vs Text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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