app-lens
applicative (functional) bidirectional programming beyond composition chains
A bidirectional transformation connects data in difference formats,
maintaining consistency amid separate updates. The "lens"
programming language---with Kmett's Haskell lens package being
one of the most influentials---is a solution to this problem.
Many lens implementations (including Kmett's Haskell library) only
support the point-free style of programming. Though concise at times,
this style becomes less handy when programs get more complicated.
This module provides the infrastructure for programming complex
bidirectional transformations, by representing lenses as functions
that are subject to the normal applicative-style programming. For
example, let us consider the 'unlines' functions and to define a
lens version of it. In our framework we can program through pattern
matching and explicit recursion as in normal functional programming.
> unlinesF :: [L s String] -> L s String
> unlinesF [] = new ""
> unlinesF (x:xs) = catLineF x (unlinesF xs)
> where catLineF = lift2 catLineL
Here, @lift2 :: Lens' (a,b) c -> (forall s. L s a -> L s b -> L s
c)@ and @new :: a -> (forall s. L s a)@ lift lenses to functions.
The former is for binary lenses and the latter is for constant
lenses. We can then apply lenses as functions, alleviating the
need of specialized combinators. In the above, we omitted the
definition of a primitive lens @catLineL :: Lens' (String, String)
String@ that concatenates two strings with a newline in between.
Simply unlifting ('unlift', 'unlift2', 'unliftT') such "lens functions"
gives us the desired lenses.
> unlinesL :: Lens' [String] String
> unlinesL = unliftT unlinesF
The obtained lens works as expected.
> >>> ["banana", "orange", "apple"] ^. unlinesL
> "banana\norange\napple\n"
> >>> ["banana", "orange", "apple"] & unlinesL .~ "Banana\nOrange\nApple\n"
> ["Banana","Orange","Apple"]
One may prefer to define @unlinesF@ with 'foldr'. Indeed, we can
use 'foldr' as below because @catLineF@ and @unlinesF@ are simply
Haskell functions.
> unlinesF = foldr (lift2 catLineL) (new "")
Here, the program is written in a point-free manner similar to that
of the other lens frameworks. But note that this 'foldr' is just
Haskell's 'foldr', instead of a special combinator for lenses.
More examples can be found at \"Examples\" in the source code
<https://bitbucket.org/kztk/app-lens/downloads>.
/Remark/.
The applicative-style programming is possible in our implementation
because a function representation different from Kmett's is used for lenses.
As a result, when we program record-field access chains such as
> src .^ l1 . l2
> src & l1 . l2 .~ tgt'
The order of composition is inverted in our implementation.
> src .^ unlift (lift l2 . lift l1)
> src & unlift (lift l2 . lift l1) .~ tgt'
This difference causes slight inconvenience for record updates, but is
crucial in allowing the applicative-style lens programming we
aim for.
| version | uploaded | uploader | changes | |
|---|---|---|---|---|
| 0.1.0.3 | 2016-09-25 14:32 UTC | kztk | +5/−4 lines, 2 filesdep ~basedep ~lensPVP: major bump suggested | |
| 0.1.0.1 | 2015-09-03 05:18 UTC | kztk | +16/−16 lines, 2 filesPVP ok | |
| 0.1.0.0 | 2015-06-16 05:27 UTC | kztk | 3 revisions | +1286/−0 lines, 12 filesdep +app-lensdep +basedep +containerssetup-changed |
Dependencies of app-lens-0.1.0.3
base >=4.7 && <4.10 4.9.1.0 → 4.22.1.0 newer than bounds
| 2026-12-01 12:38 UTC | 4.22.1.0 newer than bounds | +388/−6 lines, 9 filesdep ~ghc-internalPVP: major bump suggested |
| 2025-12-19 11:52 UTC | 4.22.0.0 newer than bounds | +886/−215 lines, 28 filesdep ~ghc-internalPVP ok |
| 2026-03-27 12:26 UTC | 4.21.2.0 newer than bounds | +10/−3 lines, 4 filesdep ~ghc-internalPVP ok |
| 2025-12-27 10:31 UTC | 4.21.1.0 newer than bounds | +17/−5 lines, 4 filesdep ~ghc-internalPVP ok |
| 2024-12-16 09:24 UTC | 4.21.0.0 newer than bounds | +1170/−396 lines, 39 filesdep ~ghc-internalPVP ok |
showing 5 of 61 versions
containers >=0.5 && <0.6 0.5.11.0 → 0.8.1 newer than bounds
| 2026-10-04 06:08 UTC | 0.8.1 newer than bounds | +8085/−5169 lines, 39 filesdep +template-haskell-liftdep ~arraydep ~deepseqPVP: major bump suggested |
| 2025-03-01 13:03 UTC | 0.8 newer than bounds | +8447/−7031 lines, 37 filesnew-uploaderPVP ok |
| 2023-09-27 12:15 UTC | 0.7 newer than bounds | +76/−33 lines, 3 filesPVP ok |
| 2023-09-28 04:21 UTC | 0.6.8 newer than bounds | +644/−184 lines, 17 filesdep ~basedep ~deepseqPVP: major bump suggested |
| 2023-02-01 03:11 UTC | 0.6.7 newer than bounds | +783/−229 lines, 20 filesPVP: major bump suggested |
showing 5 of 43 versions
criterion >=1.1 && <1.2 1.1.4.0 → 1.6.5.0 newer than bounds
| 2026-04-02 13:34 UTC | 1.6.5.0 newer than bounds | +7650/−7639 lines, 41 filesdep −parsecdep −timedep −vector-algorithmsdep ~aesondep ~deepseqsetup-changedPVP ok |
| 2025-09-06 22:52 UTC | 1.6.4.1 newer than bounds | +7639/−4696 lines, 42 filesdep ~base-compat-batteriessetup-changedbinary-addedPVP: major bump suggested |
| 2024-10-27 00:12 UTC | 1.6.4.0 newer than bounds | +64/−143 lines, 15 filesdep −faildep −ghc-primdep −semigroupsdep ~aesondep ~basedep ~binaryPVP: major bump suggested |
| 2023-08-08 11:17 UTC | 1.6.3.0 newer than bounds | +13/−7 lines, 3 filesdep ~base-compat-batteriesPVP ok |
| 2023-05-23 23:07 UTC | 1.6.2.0 newer than bounds | +18/−62 lines, 4 filesdep +prettyprinterdep +prettyprinter-ansi-terminaldep ~aesondep ~optparse-applicativePVP ok |
showing 5 of 70 versions
deepseq >=1.3 && <1.5 1.4.8.1 → 1.6.0.0 newer than bounds
| 2024-09-08 16:18 UTC | 1.6.0.0 newer than bounds | +5/−14 lines, 3 filesdep ~basePVP ok |
| 2025-06-14 22:25 UTC | 1.5.2.0 newer than bounds | +13/−4 lines, 3 filesPVP: major bump suggested |
| 2024-09-09 12:48 UTC | 1.5.1.0 newer than bounds | +69/−14 lines, 3 filesdep −arraydep ~basePVP: major bump suggested |
| 2023-07-27 19:32 UTC | 1.5.0.0 newer than bounds | +619/−532 lines, 5 filesdep ~basePVP ok |
| 2022-12-18 00:14 UTC | 1.4.8.1 | +34/−9 lines, 3 filesdep ~basePVP: major bump suggested |
showing 5 of 26 versions
lens >=4 && <4.15 4.14 → 5.3.6 newer than bounds
| 2026-01-10 22:05 UTC | 5.3.6 newer than bounds | +39/−28 lines, 7 filesdep −ghc-primdep −transformers-compatdep ~template-haskellPVP ok |
| 2025-06-17 11:56 UTC | 5.3.5 newer than bounds | +99/−99 lines, 5 filesdep +tastydep +tasty-hunitdep +tasty-quickcheckdep −HUnitdep −test-frameworkdep −test-framework-hunitdep ~parallelPVP: major bump suggested |
| 2025-03-03 12:24 UTC | 5.3.4 newer than bounds | +156/−44 lines, 14 filesdep ~containersPVP ok |
| 2024-12-28 16:38 UTC | 5.3.3 newer than bounds | +198/−36 lines, 11 filesdep ~basedep ~template-haskellPVP ok |
| 2024-05-12 23:00 UTC | 5.3.2 newer than bounds | +131/−19 lines, 7 filesdep ~hashablePVP: major bump suggested |
showing 5 of 162 versions
mtl >=2.2 && <2.4 2.3.1 → 2.3.2
| 2025-12-08 04:58 UTC | 2.3.2 | +112/−21 lines, 12 filesdep ~basenew-uploaderPVP: major bump suggested |
| 2022-10-31 21:28 UTC | 2.3.1 | +188/−33 lines, 8 filesdep ~basePVP: major bump suggested |
| 2022-05-07 20:34 UTC | 2.3 | +1284/−520 lines, 29 filesdep ~basedep ~transformersnew-uploaderPVP ok |
| 2018-02-24 22:15 UTC | 2.2.2 | +152/−36 lines, 14 filesdep ~basePVP: major bump suggested |
| 2014-06-02 02:22 UTC | 2.2.1 | +179/−4 lines, 8 filesdep ~basedep ~transformersPVP: major bump suggested |
showing 5 of 20 versions
Reverse dependencies
1 packages depend on app-lens