GHC: Ticket #1974: length "foo" doesn't work with -XOverloadedStrings
http://ghc.haskell.org/trac/ghc/ticket/1974
<p>
The extensions to the defaulting rule for -XOverloadedStrings aren't sufficient to make <tt>length "foo"</tt> typecheck without an annotation. The reason is that we end up with a constraint <tt>IsString [a]</tt>, and we would somehow have to decide to instantiate a to Char to get the hoped-for behaviour.
</p>
<p>
It would be nice if this could be made to work (perhaps just with -XExtendedDefaultRules), if a solution can be found without too much hacking.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/1974
Trac 1.0.7ganeshWed, 12 Dec 2007 12:01:37 GMTcc set
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:1
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:1
<ul>
<li><strong>cc</strong>
<em>lennart.augustsson@…</em> added
</li>
</ul>
TicketsimonpjWed, 12 Dec 2007 14:34:07 GMT
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:2
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:2
<p>
Fair enough. Would you care to specify the new defaulting rule? The starting points are:
</p>
<ol start="0"><li><a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/interactive-evaluation.html#extended-default-rules">http://www.haskell.org/ghc/docs/latest/html/users_guide/interactive-evaluation.html#extended-default-rules</a>
</li><li><a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class-extensions.html#overloaded-strings">http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class-extensions.html#overloaded-strings</a>
</li></ol><p>
In particular, (1) requires the constraints to be of form (C a), where 'a' is a type variable; whereas you want it to be of form (C ty), where ty is a type. You probably want the type to have at most one free variable, to avoid complicated interactions between defaults.
</p>
<p>
But what if the constraints are <tt>(IsString [a], Eq a)</tt>. Then to try a candidate default type, say <tt>[Char]</tt> we presumably match <tt>[a]</tt> against <tt>[Char]</tt>, and everything works out. But if the <tt>(Eq a)</tt> was first, we might try matching <tt>a</tt> against <tt>[Char]</tt>, which doesn't work. So perhaps each candidate type must be matched against each constraint (and if the match succeeds, try to solve the constraints under that substitution)?
</p>
<p>
If you write the spec, I'm pretty sure it'll be easy enough to implement.
</p>
<p>
Simon
</p>
TicketiglooFri, 14 Dec 2007 15:23:35 GMTmilestone set
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:3
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:3
<ul>
<li><strong>milestone</strong>
set to <em>6.10 branch</em>
</li>
</ul>
<p>
Once <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/1877" title="task: Change the meaning of -fextended-default-rules (closed: fixed)">#1877</a> is fixed, having the behaviour set by ExtendedDefaultRules won't do what you want (assuming you want to be able to do this in source files rather than at the GHCi prompt).
</p>
TicketsimonmarTue, 30 Sep 2008 15:37:44 GMTarchitecture changed
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:4
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:4
<ul>
<li><strong>architecture</strong>
changed from <em>Unknown</em> to <em>Unknown/Multiple</em>
</li>
</ul>
TicketsimonmarTue, 30 Sep 2008 15:52:09 GMTos changed
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:5
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:5
<ul>
<li><strong>os</strong>
changed from <em>Unknown</em> to <em>Unknown/Multiple</em>
</li>
</ul>
TicketiglooMon, 13 Apr 2009 17:44:51 GMTmilestone changed
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:6
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:6
<ul>
<li><strong>milestone</strong>
changed from <em>6.10 branch</em> to <em>6.12 branch</em>
</li>
</ul>
TicketiglooFri, 30 Apr 2010 16:41:12 GMTmilestone changed
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:7
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:7
<ul>
<li><strong>milestone</strong>
changed from <em>6.12 branch</em> to <em>6.12.3</em>
</li>
</ul>
TicketiglooSat, 19 Jun 2010 17:49:48 GMTpriority, milestone changed; failure set
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:8
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:8
<ul>
<li><strong>priority</strong>
changed from <em>low</em> to <em>normal</em>
</li>
<li><strong>failure</strong>
set to <em>None/Unknown</em>
</li>
<li><strong>milestone</strong>
changed from <em>6.12.3</em> to <em>_|_</em>
</li>
</ul>
TicketparcsFri, 07 Sep 2012 01:49:42 GMT
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:9
http://ghc.haskell.org/trac/ghc/ticket/1974#comment:9
<p>
Have you considered changing the instance declaration from
</p>
<pre class="wiki">instance IsString String where
</pre><p>
to
</p>
<pre class="wiki">instance (a ~ Char) => IsString [a] where
</pre><p>
This new instance will make <tt>length "foo"</tt> happily typecheck, but it will also overlap with other <tt>IsString</tt> instances of the form <tt>[T]</tt>. (Though I don't think such instances are common in practice.)
</p>
Ticket