
Hi. Using normal String type I can define a pattern like:
let foo "baz" = 777 foo "baz" 777
But if I want to use ByteString, what should I do? This seems impossible, since ByteString data constructor is not available. Thanks Manlio Perillo

On Tue, Mar 10, 2009 at 3:28 PM, Manlio Perillo
This seems impossible, since ByteString data constructor is not available.
You can use view patterns, per http://www.serpentine.com/blog/2009/01/11/fun-with-haskell-view-patterns/

Hello Manlio, Wednesday, March 11, 2009, 1:28:13 AM, you wrote:
Using normal String type I can define a pattern like:
But if I want to use ByteString, what should I do? This seems impossible, since ByteString data constructor is not available.
for numeric types, it works via Num instances. we have now IsString type, may be it provides the same feature? i.e., are you tried? :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

manlio_perillo:
Hi.
Using normal String type I can define a pattern like:
let foo "baz" = 777 foo "baz" 777
But if I want to use ByteString, what should I do? This seems impossible, since ByteString data constructor is not available.
-XOverloadedStrings e.g. {-# LANGUAGE OverloadedStrings #-} import qualified Data.ByteString.Char8 as C isMatch :: C.ByteString -> Bool isMatch "match" = True isMatch _ = False main = print . map isMatch . C.lines =<< C.getContents

Don Stewart ha scritto:
manlio_perillo:
Hi.
Using normal String type I can define a pattern like:
let foo "baz" = 777 foo "baz" 777
But if I want to use ByteString, what should I do? This seems impossible, since ByteString data constructor is not available.
-XOverloadedStrings
Perfect, thanks. Is this supported by other Haskell implementations, or planned for Haskell'? Manlio

manlio_perillo:
Don Stewart ha scritto:
manlio_perillo:
Hi.
Using normal String type I can define a pattern like:
let foo "baz" = 777 foo "baz" 777
But if I want to use ByteString, what should I do? This seems impossible, since ByteString data constructor is not available.
-XOverloadedStrings
Perfect, thanks.
Is this supported by other Haskell implementations, or planned for Haskell'?
Not as far as I know. It was added to GHC just over 2 years ago, http://article.gmane.org/gmane.comp.lang.haskell.cvs.all/31022 and isn't terribly widely used. Probably ByteString literals are the current main use (along with interesting EDSL applications, which was the original motivation afaik). -- Don

Don Stewart ha scritto:
[...]
-XOverloadedStrings Perfect, thanks.
Is this supported by other Haskell implementations, or planned for Haskell'?
Not as far as I know. It was added to GHC just over 2 years ago,
http://article.gmane.org/gmane.comp.lang.haskell.cvs.all/31022
and isn't terribly widely used. Probably ByteString literals are the current main use (along with interesting EDSL applications, which was the original motivation afaik).
Ok, thanks. In my case it just makes the code nicer; it is not a critical feature. Manlio

Don Stewart ha scritto:
[...] {-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as C
isMatch :: C.ByteString -> Bool isMatch "match" = True isMatch _ = False
main = print . map isMatch . C.lines =<< C.getContents
What is the reason why instance declarations for IsString class are not defined for available ByteStrings? I need to define it by myself. Thanks Manlio Perillo

manlio_perillo:
Don Stewart ha scritto:
[...] {-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as C
isMatch :: C.ByteString -> Bool isMatch "match" = True isMatch _ = False
main = print . map isMatch . C.lines =<< C.getContents
What is the reason why instance declarations for IsString class are not defined for available ByteStrings?
I need to define it by myself.
They're exported from Data.ByteString.Char8

Don Stewart ha scritto:
manlio_perillo:
Don Stewart ha scritto:
[...] {-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as C
isMatch :: C.ByteString -> Bool isMatch "match" = True isMatch _ = False
main = print . map isMatch . C.lines =<< C.getContents
What is the reason why instance declarations for IsString class are not defined for available ByteStrings?
I need to define it by myself.
They're exported from Data.ByteString.Char8
Then there is something I'm missing. Your code does not compile. Thanks Manlio Perillo

manlio_perillo:
Don Stewart ha scritto:
manlio_perillo:
Don Stewart ha scritto:
[...] {-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as C
isMatch :: C.ByteString -> Bool isMatch "match" = True isMatch _ = False
main = print . map isMatch . C.lines =<< C.getContents
What is the reason why instance declarations for IsString class are not defined for available ByteStrings?
I need to define it by myself.
They're exported from Data.ByteString.Char8
Then there is something I'm missing. Your code does not compile.
Sure it does: $ ghci A.hs GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( A.hs, interpreted ) Ok, modules loaded: Main. *Main> :t main main :: IO () You should give any error message, and the steps you took that lead to the error when making a bug report. -- Don

Am Mittwoch, 11. März 2009 17:09 schrieb Manlio Perillo:
Don Stewart ha scritto:
manlio_perillo:
Don Stewart ha scritto:
[...] {-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as C
isMatch :: C.ByteString -> Bool isMatch "match" = True isMatch _ = False
main = print . map isMatch . C.lines =<< C.getContents
What is the reason why instance declarations for IsString class are not defined for available ByteStrings?
I need to define it by myself.
They're exported from Data.ByteString.Char8
Then there is something I'm missing.
A recent enough bytestring package. Compiles and works with 0.9.1.4
Your code does not compile.
Thanks Manlio Perillo
Cheers, Daniel
participants (5)
-
Bryan O'Sullivan
-
Bulat Ziganshin
-
Daniel Fischer
-
Don Stewart
-
Manlio Perillo