on master help sign in
Add insertOrSet, WIP

Commented out for later

commit7bbf81ce7aca5f2bf9d497d7e15c588f9a5ae00f authorSridhar Ratnakumar <srid@srid.ca> dateSun 23 Aug 2020, 14:13 (6 years ago) parent0e3d5a8
2 files changed+24
src/JRec.hs+17 test/JRecSpec.hs+7
src/JRec.hs+17
@@ -9,6 +9,7 @@ module JRec
99 pattern Rec,
1010 append,
1111 union,
12+ -- insertOrSet
1213 )
1314where
1415
@@ -74,6 +75,22 @@ union ::
7475 Rec res
7576union = R.union
7677
78+--insertOrSet ::
79+-- forall label value rhs res.
80+-- ( KnownNat (R.RecSize rhs),
81+-- KnownNat (R.RecTyIdxH 0 label res),
82+-- KnownNat (1 + R.RecSize rhs),
83+-- KnownSymbol label,
84+-- res ~ R.Union '[label := value] rhs,
85+-- value ~ R.RecTy label res,
86+-- R.RecCopy rhs rhs res
87+-- ) =>
88+-- label := value ->
89+-- Rec rhs ->
90+-- Rec res
91+--insertOrSet = union . Rec
92+--
93+
7794----------------------------------------------------------------------------
7895-- Generic
7996----------------------------------------------------------------------------
test/JRecSpec.hs+7
@@ -58,3 +58,10 @@ spec = do
5858 r2 = Rec (#c := 7, #a := 8)
5959 r1 `union` r2
6060 `shouldBe` Rec (#b := 5, #a := 6, #c := 7)
61+-- describe "insertOrSet" $ do
62+-- it "distinct" $ do
63+-- insertOrSet (#a := 1) (Rec (#b := 2, #c := 3))
64+-- `shouldBe` Rec (#a := 1, #b := 2, #c := 3)
65+-- it "overwrite" $ do
66+-- insertOrSet (#c := 1) (Rec (#b := 2, #c := 3))
67+-- `shouldBe` Rec (#b := 2, #c := 1)