Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions lib/Fmt/Internal/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,18 @@ instance (GetFields a, Constructor c) => GBuildable (M1 C c a) where
-- * Ordinarily e.g. "Foo" is prefix and e.g. ":|" is infix
-- * However, "Foo" can be infix when defined as "a `Foo` b"
-- * And ":|" can be prefix when defined as "(:|) a b"
gbuild c@(M1 x) = case conFixity c of
Infix _ _
| [a, b] <- fields -> format "({} {} {})" a infixName b
-- this case should never happen, but still
| otherwise -> format "<{}: {}>"
prefixName
(mconcat (intersperse ", " fields))
Prefix
| isTuple -> tupleF fields
| conIsRecord c -> nameF (build prefixName) (blockMapF fieldsWithNames)
| null (getFields x) -> build prefixName
-- I believe that there will be only one field in this case
| null (conName c) -> mconcat (intersperse ", " fields)
| otherwise -> format "<{}: {}>"
prefixName
(mconcat (intersperse ", " fields))
gbuild c@(M1 x)
| Infix _ _ <- conFixity c
-- There will always be two fields in this context.
, [a, b] <- fields = format "({} {} {})" a infixName b
| isTuple = tupleF fields
| conIsRecord c = nameF (build prefixName) (blockMapF fieldsWithNames)
| null (getFields x) = build prefixName
-- I believe that there will be only one field in this case
| null (conName c) = mconcat (intersperse ", " fields)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can the conName ever be null? Was this just a mistake?

| otherwise = format "<{}: {}>"
prefixName
(mconcat (intersperse ", " fields))
where
(prefixName, infixName)
| ":" `isPrefixOf` conName c = ("(" ++ conName c ++ ")", conName c)
Expand Down