yav / pretty-show

Tools for working with derived Show instances in Haskell.
MIT License
57 stars 15 forks source link

pretty-show stripping necessary parentheses #34

Closed dspies-leapyear closed 5 years ago

dspies-leapyear commented 5 years ago

I generated this entityDef with persistent-template (looking at -ddump-splices) and then I tried to strip the unnecessary parentheses and clean it up by passing it to ppsh, but what it gave back wasn't the same structure.

The first error here is that

(FTTypeCon Nothing "UserId") became two separate parameters (FTTypeCon Nothing) and "UserId"

(((((((((EntityDef
             (HaskellName
                ("User")))
            (DBName
               ("user")))
           (((((((FieldDef
                    (HaskellName
                       ("Id")))
                   (DBName
                      ("id")))
                  ((FTTypeCon Nothing)
                     ("UserId")))
                 SqlInt64)
                [])
               True)
              ((ForeignRef
                  (HaskellName
                     ("User")))
                 ((FTTypeCon
                     (Just ("Data.Int")))
                    ("Int64")))))
          [])
         [((((((FieldDef
                  (HaskellName
                     ("name")))
                 (DBName
                    ("name")))
                ((FTTypeCon Nothing)
                   ("String")))
               SqlString)
              [])
             True)
            NoReference,
          ((((((FieldDef
                  (HaskellName
                     ("age")))
                 (DBName
                    ("age")))
                ((FTTypeCon Nothing)
                   ("Int")))
               SqlInt64)
              [])
             True)
            NoReference,
          ((((((FieldDef
                  (HaskellName
                     ("dream")))
                 (DBName
                    ("dream")))
                ((FTTypeCon Nothing)
                   ("String")))
               SqlString)
              ["Maybe"])
             True)
            NoReference,
          ((((((FieldDef
                  (HaskellName
                     ("home")))
                 (DBName
                    ("home")))
                ((FTTypeCon Nothing)
                   ("AddressId")))
               (sqlType
                  (Proxy :: Proxy Int64)))
              [])
             True)
            ((ForeignRef
                (HaskellName
                   ("Address")))
               ((FTTypeCon
                   (Just ("Data.Int")))
                  ("Int64")))])
        [])
       [])
      ["Show"])
     (Map.fromList []))
    False

became

(EntityDef (HaskellName "User"))
(DBName "user")
(FieldDef (HaskellName "Id"))
(DBName "id")
(FTTypeCon Nothing)
"UserId"
SqlInt64
[]
True
(ForeignRef (HaskellName "User"))
(FTTypeCon (Just "Data.Int"))
"Int64"
[]
[ (FieldDef (HaskellName "name"))
  (DBName "name")
  (FTTypeCon Nothing)
  "String"
  SqlString
  []
  True
  NoReference
, (FieldDef (HaskellName "age"))
  (DBName "age")
  (FTTypeCon Nothing)
  "Int"
  SqlInt64
  []
  True
  NoReference
, (FieldDef (HaskellName "dream"))
  (DBName "dream")
  (FTTypeCon Nothing)
  "String"
  SqlString
  [ "Maybe" ]
  True
  NoReference
, (FieldDef (HaskellName "home"))
  (DBName "home")
  (FTTypeCon Nothing)
  "AddressId"
  (sqlType Proxy)
  []
  True
  (ForeignRef (HaskellName "Address"))
  (FTTypeCon (Just "Data.Int"))
  "Int64"
]
[]
[]
[ "Show" ]
(Map.fromList [])
False
yav commented 5 years ago

Thanks for reporting this. I think I fixed it, try out version 1.9.3 on Hackage. Now it prints:

EntityDef
  (HaskellName "User")
  (DBName "user")
  (FieldDef
     (HaskellName "Id")
     (DBName "id")
     (FTTypeCon Nothing "UserId")
     SqlInt64
     []
     True
     (ForeignRef
        (HaskellName "User") (FTTypeCon (Just "Data.Int") "Int64")))
  []
  [ FieldDef
      (HaskellName "name")
      (DBName "name")
      (FTTypeCon Nothing "String")
      SqlString
      []
      True
      NoReference
  , FieldDef
      (HaskellName "age")
      (DBName "age")
      (FTTypeCon Nothing "Int")
      SqlInt64
      []
      True
      NoReference
  , FieldDef
      (HaskellName "dream")
      (DBName "dream")
      (FTTypeCon Nothing "String")
      SqlString
      [ "Maybe" ]
      True
      NoReference
  , FieldDef
      (HaskellName "home")
      (DBName "home")
      (FTTypeCon Nothing "AddressId")
      (sqlType (Proxy :: Proxy Int64))
      []
      True
      (ForeignRef
         (HaskellName "Address") (FTTypeCon (Just "Data.Int") "Int64"))
  ]
  []
  []
  [ "Show" ]
  (Map.fromList [])
  False

which as far as I can tell is reasonable?

dspies-leapyear commented 5 years ago

LGTM