[Haskell-cafe] Pattern matching with OverloadedLists

Alejandro Serrano Mena trupill at gmail.com
Fri Nov 6 15:38:22 UTC 2015


You need to write `toList` in both branches:

f (toList -> ('9':_)) = 1
f (toList -> ('1':_)) = 2

2015-11-06 16:20 GMT+01:00 Vlatko Basic <vlatko.basic at gmail.com>:

> Hello Cafe,
>
> wiki for OverloadedLists says that
>
> g  [x,y,z]  =  ...
>
> is treated as
>
> g  (toList->  [x,y,z])  =
>
>
> Shouldn't this work? Both 'f's should be treated the same.
>
> f :: Text -> Int
> f (toList -> ('9':_)) = 1   -- OK
> f                 ('1':_)  = 2   -- Couldn't match expected type ‘Text’
> with actual type ‘[Char]’
>
> (OverloadedStrings is also on)
>
> Am I missing something?
>
> br,
> vlatko
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20151106/1282bff1/attachment.html>


More information about the Haskell-Cafe mailing list