surrounding quotes w/ newtypes of Text/String

Short description

Currently, strings and chars are interpolated without surrounding quotes (which is a very good thing). It would be nice to have the same behaviour for types which are newtypes of Text/String/Char.

Longer description

Consider this code:

let foo :: Text
    foo = "foobar"
 in putTextLn [i|result: #{foo}|]

Later, one might decide to introduce a newtype for foo:

newtype Foo = Foo Text
  deriving newtype (Show)

Now, this slightly modified code still compiles, but it includes (usually unwanted) surrounding quotes:

let foo :: Foo
    foo = Foo "foobar"
 in putTextLn [i|result: #{foo}|]

Possible solutions

  • Detect if a type is Coercible Text (or Coercible String etc.), and remove quotes if that is the case.
  • Introduce further variations of i which only accept types which are Coercible Text etc.
  • Emit appropriate warnings (is that even possible?) if a newtype of Text etc. is interpolated.

I am happy to help implementing something like this, but as I have close to zero knowledge of TH, it might take some time.

Edited by amesgen