Strange behavior with OverloadString and default rules

Continuing the discussion from OverloadedStringDefault proposal:

I tried to use ExtendedDefaultRules. In my project, there is about 14 (something :: Text) needed resolve type ambiguity. I understood that my wish of being able to set Text as a default can be solved by using ExtendedDefaultRules and default (Text).

So after removing one of the ::Text and verifiied it didn’t compile anymore, I set ExtendedDefaultRules on the top of the file and to my surprise, now it is compiling, even though I didn’t set the default to Text.

Is that normal behavior ?

By the way, I can’t find in GHC manual about this default (...). Could someone point it out for me please ?

The unit type () and the list type [] are added to the start of the standard list of types which are tried when doing type defaulting

The documentation says this:

Haskell’s defaulting mechanism (Haskell Report, Section 4.3.4) is extended to cover string literals, when OverloadedStrings is specified. Specifically:

  • Each type in a default declaration must be an instance of Num or of IsString.
  • If no default declaration is given, then it is just as if the module contained the declaration default( Integer, Double, String).
  • The standard defaulting rule is extended thus: defaulting applies when all the unresolved constraints involve standard classes or IsString; and at least one is a numeric class or IsString.

So perhaps it is just choosing String by default and it works? But this doesn’t seem to depend on ExtendedDefaultRules

Indeed. The code parse a csv file and then pattern match on the value. Both String and Text work in that case. The ambiguity, forcing me to chose was actually a good thing LoL.