Skip to content

Add nub constraint on Record Show instance #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ Breaking changes:
- Change Generic Rep's `NoConstructors` to newtype `Void` (#282 by @JordanMartinez)
- Replaced polymorphic proxies with monomorphic `Proxy` (#281, #288 by @JordanMartinez)
- Fix `signum zero` to return `zero` (#280 by @JordanMartinez)
- Fix `Show` instance on records with duplicate labels by adding `Nub` constraint (#269 by @JordanMartinez)

New features:

Bugfixes:
- Fix Record's `Show` instance when it has duplicate labels (#269 by @JordanMartinez)

Other improvements:
- Changed `unit`'s FFI representation from `{}` to `undefined` (#267 by @JordanMartinez)
Expand Down
7 changes: 6 additions & 1 deletion src/Data/Show.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Data.Show
) where

import Data.Symbol (class IsSymbol, reflectSymbol)
import Prim.Row (class Nub)
import Prim.RowList as RL
import Record.Unsafe (unsafeGet)
import Type.Proxy (Proxy(..))
Expand Down Expand Up @@ -41,7 +42,11 @@ instance showArray :: Show a => Show (Array a) where
instance showProxy :: Show (Proxy a) where
show _ = "Proxy"

instance showRecord :: (RL.RowToList rs ls, ShowRecordFields ls rs) => Show (Record rs) where
instance showRecord ::
( Nub rs rs
, RL.RowToList rs ls
, ShowRecordFields ls rs
) => Show (Record rs) where
show record = case showRecordFields (Proxy :: Proxy ls) record of
[] -> "{}"
fields -> intercalate " " ["{", intercalate ", " fields, "}"]
Expand Down