Opened 10 years ago

Last modified 5 years ago

#1974 new feature request

length "foo" doesn't work with -XOverloadedStrings

Reported by: ganesh Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.8.1
Keywords: Cc: lennart.augustsson@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


The extensions to the defaulting rule for -XOverloadedStrings aren't sufficient to make length "foo" typecheck without an annotation. The reason is that we end up with a constraint IsString [a], and we would somehow have to decide to instantiate a to Char to get the hoped-for behaviour.

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.

Change History (9)

comment:1 Changed 10 years ago by ganesh

Cc: lennart.augustsson@… added

comment:2 Changed 10 years ago by simonpj

Fair enough. Would you care to specify the new defaulting rule? The starting points are:


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.

But what if the constraints are (IsString [a], Eq a). Then to try a candidate default type, say [Char] we presumably match [a] against [Char], and everything works out. But if the (Eq a) was first, we might try matching a against [Char], 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)?

If you write the spec, I'm pretty sure it'll be easy enough to implement.


comment:3 Changed 10 years ago by igloo

Milestone: 6.10 branch

Once #1877 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).

comment:4 Changed 9 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:5 Changed 9 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:6 Changed 8 years ago by igloo

Milestone: 6.10 branch6.12 branch

comment:7 Changed 7 years ago by igloo

Milestone: 6.12 branch6.12.3

comment:8 Changed 7 years ago by igloo

Milestone: 6.12.3_|_
Priority: lownormal
Type of failure: None/Unknown

comment:9 Changed 5 years ago by parcs

Have you considered changing the instance declaration from

instance IsString String where


instance (a ~ Char) => IsString [a] where

This new instance will make length "foo" happily typecheck, but it will also overlap with other IsString instances of the form [T]. (Though I don't think such instances are common in practice.)

Note: See TracTickets for help on using tickets.