foundation icon indicating copy to clipboard operation
foundation copied to clipboard

show returns GHC.Base.String

Open AnthonyJacob opened this issue 9 years ago • 2 comments

λ: :t putStr (show [1..10])

<interactive>:1:9: error:
    - Couldn't match type [Char] with String
      Expected type: String
        Actual type: GHC.Base.String
    - In the first argument of putStr, namely(show [1 .. 10])
      In the expression: putStr (show [1 .. 10])
λ: :t show
show :: Show a => a -> GHC.Base.String

Intended?

Is there some easy workaround for now?

AnthonyJacob avatar Oct 13 '16 08:10 AnthonyJacob

We definitely need a better story for this.

I think the typeclass Show would need to stay, as it is one of the hardcoded class in haskell (deriving Show works on any type), but we need to be smarter about hiding GHC.Base.String from the string. we have a LString (short for List String) to provide the compatibility bridge for example.

Now we need better story for the foundation String:

  1. show should be making foundation String by default:
show :: GHC.Show a => a -> String
show a = fromList $ GHC.show a
  1. We need a default class to print our types natively without going through [Char]. We might even need 2 of these, for example (name made up) to distinguish how Show is currently being used:
class UserShow a where
    pretty :: a -> String    

class DebugShow a where
   debug :: a -> String

vincenthz avatar Oct 15 '16 08:10 vincenthz

Perhaps DebugShow should be implemented generically for most data - you want the true underlying structure in most cases. Perhaps UserShow should be using pretty printing combinators. The existing Show is a weird point in the design space.

ndmitchell avatar Oct 15 '16 12:10 ndmitchell