#2875: Correct SYB's representation of Char
-----------------------------+----------------------------------------------
Reporter:  dreixel           |          Owner:                  
    Type:  proposal          |         Status:  new             
Priority:  normal            |      Component:  libraries/base  
 Version:  6.10.1            |       Severity:  normal          
Keywords:                    |       Testcase:                  
      Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple
-----------------------------+----------------------------------------------
 SYB uses `DataRep` to represent datatypes:

 {{{
     -- | Public representation of datatypes
     data DataRep = AlgRep [Constr]
                  | IntRep
                  | FloatRep
                  | StringRep
                  | NoRep
 }}}


 I believe that `StringRep` should be `CharRep`. Note that `IntRep` is used
 for the primitive `Int` and `Integer` datatypes, `FloatRep` for `Float`
 and `Double`, and `StringRep` (apparently) for `Char`. `String`, however,
 is represented as `AlgRep [[],(:)]`:

 {{{
     *Main> dataTypeOf 'p'
     DataType {tycon = "Prelude.Char", datarep = StringRep}
     *Main> dataTypeOf "p"
     DataType {tycon = "Prelude.[]", datarep = AlgRep [[],(:)]}
 }}}


 This makes sense, since `String` is not a primitive datatype. But it
 causes the apparently wrong behavior:

 {{{
     *Main> fromConstr (mkStringConstr (dataTypeOf "a") "ab") :: String
     "*** Exception: mkStringConstr
     *Main> fromConstr (mkStringConstr (dataTypeOf 'a') "ab") :: String
     "*** Exception: constrIndex
 }}}


 The correct way of using `mkStringConstr` is to construct a `Char`. This,
 however, only works for strings with a single character:

 {{{
     *Main> fromConstr (mkStringConstr (dataTypeOf 'a') "b")  :: Char
     'b'
     *Main> fromConstr (mkStringConstr (dataTypeOf 'a') "ab") :: Char
     *** Exception: gunfold
     *Main> fromConstr (mkStringConstr (dataTypeOf 'a') "")   :: Char
     *** Exception: gunfold
 }}}

 I find this behavior counterintuitive. Therefore I propose to rename
 `StringRep` to `CharRep` and `mkStringConstr` to `mkCharConstr`. For
 backwards compatibility, this entails:
  * Deprecating `mkStringConstr` and `StringConstr`
  * Deprecating `mkStringRep` and `StringRep`
  * Introducing `mkCharConstr` and `CharConstr`
  * Introducing `mkCharRep` and `CharRep`

 Additionally, due to deprecation warnings, the following have to change as
 well:
  * libraries/template-haskell/Language/Haskell/TH/Quote.hs
  * compiler/utils/Serialized.hs

 I'm attaching a patch with the proposed changes. I propose a discussion
 period of 4 weeks, therefore until the 8th of January.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2875>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to