[Haskell-cafe] Pattern matching on lazy bytestrings: how does it work?
Tom Brow
tebrow at gmail.com
Sat Apr 23 08:52:32 CEST 2011
I noticed today that I can pattern match against lazy bytestrings when using
the OverloadedStrings extension:
import Data.ByteString.Char8 ()
>
> import Data.ByteString.Lazy.Char8
>
>
>> f :: ByteString -> Bool
>
> f "abc" = True
>
> f _ = False
>
>
>> main = do
>
> print $ f $ fromChunks ["abc"]
>
> print $ f $ fromChunks ["a","bc"]
>
>
When I run the above, I get:
True
>
> True
>
>
Given that pattern matching is based on data constructors, how is it
possible that (Chunk "abc Empty) and (Chunk "a" (Chunk "bc" Empty)) match
the same pattern?
Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110422/fd10f47a/attachment.htm>
More information about the Haskell-Cafe
mailing list