purescript / purescript-record

Functions for working with records and polymorphic labels
BSD 3-Clause "New" or "Revised" License
70 stars 31 forks source link

get, set, modify, insert, delete #1

Closed paf31 closed 7 years ago

paf31 commented 7 years ago

If this looks good, I'll tag an initial release and add this library to Bower/Pursuit.

LiamGoodacre commented 7 years ago

I tried these tests to demonstrate my point that insert should have a rowlacks constraint:

  -- if you insert after deleting what you insert, all is fine
  assert' "insert, delete, insert" $
    get x (insert x 42 (delete x (insert x 0 {}))) == 42

  -- shouldn't be able to insert twice, but it succeeds
  assert' "insert, insert" $
    get x (insert x 42 (insert x 0 {})) == 42

  -- can't delete after inserting twice due to rowlacks failing
  assert' "insert, insert, delete" $
    get x (insert x 42 (delete x (insert x 0 (insert x 0 {})))) == 42

With the following error for the "insert, insert, delete" case:

[1/1 NoInstanceFound] test/Main.purs:30:25

  30      get x (insert x 42 (delete x (insert x 0 (insert x 0 {})))) == 42
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  No type class instance was found for

    Type.Row.RowLacking Entry "x" Int ( x :: Int )
paf31 commented 7 years ago

Thanks everyone, I'll tag an initial release.