<div dir="ltr"><div><div><div><div><div>Hi Simon and all,<br><br></div>thanks for the quick response. I somehow suspected it was connected to that...<br><br></div>The mildly surprising effect of adding/leaving out the OverloadedString pragma however made me scratch my head a little, since the following code (w/o pragma) does typecheck just fine (without annotating :: String):<br>import  Data.Char (isAlphaNum)<br>main = <br>    print $ check str<br>  where<br>    check   = all (\x -> x `elem` valid || isAlphaNum x)<br>    valid   = "$_-"             -- :: String<br>    str     = "foo_bar123"   -- :: String<br><br></div>I guess without that pragma, the string literals already imply t ~ [] for Foldable t.<br></div><br>Thanks again for the answer, the behaviour I described is to be expected then.<br></div>Michael<br><div><div><br><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-07-30 23:24 GMT+02:00 Simon Peyton Jones <span dir="ltr"><<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div link="#0563C1" vlink="#954F72" lang="EN-GB">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">I think it’s because of the newly generalised Foldable stuff.  In 7.10, after huge discussion (<a href="https://ghc.haskell.org/trac/ghc/wiki/Prelude710" target="_blank">https://ghc.haskell.org/trac/ghc/wiki/Prelude710</a>)
 we have<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">elem :: (Eq a, Foldable t) => a -> t a -> Bool<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">all :: Foldable t => (a -> Bool) -> t a -> Bool<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">And there is no way to tell what ‘t’ you mean.  Lists?  Trees?  Who knows!<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Simon<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" lang="EN-US">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" lang="EN-US"> ghc-devs [mailto:<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@haskell.org</a>]
<b>On Behalf Of </b>Michael Karg<br>
<b>Sent:</b> 30 July 2015 22:05<br>
<b>To:</b> ghc-devs<br>
<b>Subject:</b> Typechecker / OverloadedStrings question 7.8 vs. 7.10<u></u><u></u></span></p>
</div>
</div><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm">
Hi devs,<u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm">
in the followin snippet:<br>
<br>
{-# LANGUAGE OverloadedStrings #-}<br>
import  Data.Char (isAlphaNum)<br>
import  Data.ByteString.Char8 as BS (all)<br>
main = <br>
    print $ check str<br>
  where<br>
    check = BS.all (\x -> x `elem` valid || isAlphaNum x)  -- Line 7<br>
    valid   = "$_-"                     -- :: String                      -- Line 8<br>
    str      = "foo_bar123"<u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
GHC 7.10 fails with the following errors (whereas 7.8 compiles without complaining):<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm">
<br>
ghc --make "Testcase.hs"<br>
[1 of 1] Compiling Main             ( Testcase.hs, Testcase.o )<br>
Testcase.hs:7:31:<br>
    No instance for (Foldable t0) arising from a use of ‘elem’<br>
    The type variable ‘t0’ is ambiguous<br>
   (...)<br>
<br>
Testcase.hs:8:15:<br>
    No instance for (Data.String.IsString (t0 Char))<br>
      arising from the literal ‘"$_-"’<br>
    The type variable ‘t0’ is ambiguous<br>
    (...)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Uncommenting the -- :: String type annotation (line 8) makes the snippet acceptable to the typechecker however.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm">
So Foldable [] and  [Char] should be possible to infer, given the evidence of 'isAlphaNum x', as obviously happens with GHC 7.8. My question is, how or why does the 7.10 typechecker behave differently? Is this intentional, or does this qualify for a trac ticket?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Thanks for looking into this,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm">
Michael<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:12.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
PS: The ByteString part is just there since the snippet is taken out of one of my projects. The following (modified) code only typechecks on 7.10 with both type annotations uncommented:<br>
<br>
{-# LANGUAGE OverloadedStrings #-}<br>
import  Data.Char (isAlphaNum)<br>
main = <br>
    print $ check str<br>
  where<br>
    check   = all (\x -> x `elem` valid || isAlphaNum x)<br>
    valid     = "$_-"               -- :: String<br>
    str        = "foo_bar123"    -- :: String<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
The errors here are (1) no instances for Foldable and (2) no instances for IsString.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
</div>
</div></div></div>
</div>
</div>

</blockquote></div><br></div>