Skip to content

Commit

Permalink
Add nub constraint on Record Show instance (#269)
Browse files Browse the repository at this point in the history
* Add nub constraint on Record Show instance

* Update changelog

* Copy Record.union and verify show on duplicate labels record fails

* Remove show duplicate label test
  • Loading branch information
JordanMartinez authored Mar 16, 2022
1 parent a273e03 commit eff3517
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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:

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

0 comments on commit eff3517

Please sign in to comment.