[Haskell-cafe] Pattern matching on lazy bytestrings: how does it work?

Helgi Kristvin Sigurbjarnarson helgikrs at gmail.com
Sat Apr 23 09:41:54 CEST 2011


On Fri, Apr 22, 2011 at 11:52:32PM -0700, Tom Brow wrote:
> I noticed today that I can pattern match against lazy bytestrings when using
> the OverloadedStrings extension:
[..]
> 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
> 

According to the haskell report[1] string literals use the overloaded (==)
for pattern matching.

    Matching a numeric, character, or string literal pattern k against a
    value v succeeds if v == k, where == is overloaded based on the type of
    the pattern. The match diverges if this test diverges.

    [1]: http://www.haskell.org/onlinereport/exps.html#sect3.17.2

-- 
Helgi Kristvin Sigurbjarnarson <helgikrs (at) gmail (dot) com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110423/e121dccd/attachment.pgp>


More information about the Haskell-Cafe mailing list