Skip to content

Use String rather than [Char] where possible

Try this in GHCi

Prelude> :t "foo"
"foo" :: [Char]

It would be better to say

"foo" :: String

Why don't we? Because of this in TysWiredIn

stringTy :: Type
stringTy = mkListTy charTy -- convenience only

That is, where GHC needs String is uses stringTy which is just [Char].

How to fix? Two ways:

  1. Make String into a "wired-in type". That's not hard, but it increases the number of wired-in types, which is generally undesirable.
  2. Make String into a "knonw-key name", and look it up in the type environment on the (few) occasions where we need stringTy. That's a little harder -- notably hsLitType would become monadic -- but not difficult.
Trac metadata
Trac field Value
Version 8.6.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information