From c3d48cf1fea66cbde81312a88224ccd32fc21b68 Mon Sep 17 00:00:00 2001 From: amesgen Date: Wed, 19 Jul 2023 11:59:23 +0200 Subject: [PATCH 1/2] Update spago package set --- packages.dhall | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages.dhall b/packages.dhall index 582d6d3..24117e0 100644 --- a/packages.dhall +++ b/packages.dhall @@ -1,4 +1,5 @@ let upstream = - https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall + https://raw.githubusercontent.com/purescript/package-sets/psc-0.15.10-20230719/src/packages.dhall + sha256:dfc2383cad9ae1beea830197d36ef39aed9d4cd587c0af04b8fce252209a2f0d in upstream From c5324cee43206fb2ce11b70895e9f4637fb3ad78 Mon Sep 17 00:00:00 2001 From: amesgen Date: Wed, 19 Jul 2023 11:58:52 +0200 Subject: [PATCH 2/2] Add `prop` variant using VTA --- CHANGELOG.md | 1 + src/Data/Lens/Record/VTA.purs | 27 +++++++++++++++++++++++++++ test/Main.purs | 7 +++++++ 3 files changed, 35 insertions(+) create mode 100644 src/Data/Lens/Record/VTA.purs diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eb19aa..4a52ee1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based Breaking changes: New features: +- Added a variant of `prop` in `Data.Lens.Record.VTA` that supplies the `Symbol` via VTA (visible type application) instead of via `Proxy` (#145 by @amesgen) Bugfixes: diff --git a/src/Data/Lens/Record/VTA.purs b/src/Data/Lens/Record/VTA.purs new file mode 100644 index 0000000..67a254e --- /dev/null +++ b/src/Data/Lens/Record/VTA.purs @@ -0,0 +1,27 @@ +module Data.Lens.Record.VTA (prop) where + +import Data.Lens (Lens) +import Data.Symbol (class IsSymbol) +import Prim.Row as Row +import Type.Proxy (Proxy(..)) +import Data.Lens.Record as Data.Lens.Record + +-- | Construct a (type-changing) lens for a record property, by providing a +-- | `Symbol` via VTA (visible type application) which corresponds to the +-- | property label. +-- | +-- | The lens is polymorphic in the rest of the row of property labels. +-- | +-- | For example: +-- | +-- | ```purescript +-- | prop @"foo" +-- | :: forall a b r. Lens { foo :: a | r } { foo :: b | r } a b +-- | ``` +prop + :: forall @l r1 r2 r a b + . IsSymbol l + => Row.Cons l a r r1 + => Row.Cons l b r r2 + => Lens (Record r1) (Record r2) a b +prop = Data.Lens.Record.prop (Proxy @l) diff --git a/test/Main.purs b/test/Main.purs index f7bad6d..57a24bd 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -12,6 +12,7 @@ import Data.Lens.Index (ix) import Data.Lens.Indexed (itraversed, reindexed) import Data.Lens.Lens (IndexedLens, cloneIndexedLens, ilens) import Data.Lens.Record (prop) +import Data.Lens.Record.VTA as VTA import Data.Lens.Setter (iover) import Data.Lens.Traversal (cloneTraversal) import Data.Lens.Zoom (ATraversal', IndexedTraversal', Lens, Lens', Traversal, Traversal', zoom) @@ -28,6 +29,12 @@ foo = prop (Proxy :: Proxy "foo") bar :: forall a b r. Lens { bar :: a | r } { bar :: b | r } a b bar = prop (Proxy :: Proxy "bar") +foo' :: forall a b r. Lens { foo :: a | r } { foo :: b | r } a b +foo' = VTA.prop @"foo" + +bar' :: forall a b r. Lens { bar :: a | r } { bar :: b | r } a b +bar' = VTA.prop @"bar" + barAndFoo :: forall a b r. Getter' { bar :: a, foo :: b | r } (Tuple a b) barAndFoo = takeBoth bar foo