| CARVIEW |
Select Language
HTTP/1.1 200 OK
Connection: keep-alive
Server: nginx/1.24.0 (Ubuntu)
Content-Type: text/html; charset=utf-8
Cache-Control: public, max-age=300
Content-Encoding: gzip
Via: 1.1 varnish, 1.1 varnish
Accept-Ranges: bytes
Age: 0
Date: Sat, 17 Jan 2026 05:01:55 GMT
X-Served-By: cache-dfw-kdal2120139-DFW, cache-bom-vanm7210031-BOM
X-Cache: MISS, MISS
X-Cache-Hits: 0, 0
X-Timer: S1768626115.328707,VS0,VE387
Vary: Accept, Accept-Encoding
transfer-encoding: chunked
cornea: classy optical monadic state
cornea: classy optical monadic state
Modules
[Index] [Quick Jump]
Downloads
- cornea-0.4.0.1.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
| Versions [RSS] | 0.2.0.0, 0.2.1.0, 0.2.2.0, 0.3.0.0, 0.3.0.1, 0.3.1.0, 0.3.1.1, 0.3.1.2, 0.4.0.0, 0.4.0.1 (info) |
|---|---|
| Dependencies | base (>=4 && <5), either (>=5.0.1), lens (>=4), lifted-base (<0.3), monad-control (>=1.0), mtl, relude (>=0.7), template-haskell, th-abstraction (>=0.3), transformers [details] |
| License | BSD-2-Clause-Patent |
| Copyright | 2021 Torsten Schmits |
| Author | Torsten Schmits |
| Maintainer | tek@tryp.io |
| Uploaded | by tek at 2022-02-05T14:43:57Z |
| Category | Lens |
| Home page | https://github.com/tek/cornea#readme |
| Bug tracker | https://github.com/tek/cornea/issues |
| Source repo | head: git clone https://github.com/tek/cornea |
| Distributions | NixOS:0.4.0.1 |
| Reverse Dependencies | 3 direct, 4 indirect [details] |
| Downloads | 2694 total (43 in the last 30 days) |
| Rating | 2.0 (votes: 1) [estimated by Bayesian average] |
| Your Rating |
|
| Status | Docs uploaded by user Build status unknown [no reports yet] |
Readme for cornea-0.4.0.1
[back to package description]Intro
Classes for accessing and mutating nested data types with corresponding adapter
classes for MonadState, MonadReader and MonadError. Inspired by the
next level mtl with classy optics talk.
Internals
Lenses and Prisms from lens are autogenerated with TH by splicing with
deepPrisms and deepLenses.
The generator recurses into single-field constructors and record fields if
there are instances of DeepPrisms or DeepLenses for their parameter types.
Example
For MonadError:
{-# LANGUAGE TemplateHaskell #-}
import Cornea (MonadDeepError(throwHoist))
import Control.Monad.Trans.Except (runExceptT)
import Data.DeepPrisms (deepPrisms)
newtype Error = Error String
newtype Inner = Inner Error
deepPrisms ''Inner
data Mid = Mid Inner
deepPrisms ''Mid
newtype Outer = Outer Mid
deepPrisms ''Outer
throwDeep :: MonadDeepError e Inner m => m ()
throwDeep = throwHoist (Inner (Error "boom"))
main :: IO (Either Outer ())
main = runExceptT throwDeep
In main, MonadError Outer IO and DeepPrisms Outer Inner are summoned.
Analogously for MonadState:
{-# LANGUAGE TemplateHaskell #-}
import Cornea (MonadDeepState(get, gets, put))
import Control.Monad.Trans.State (execStateT)
import Data.DeepLenses (deepLenses)
newtype S = S Int
newtype Inner = Inner { _innerS :: S }
deepLenses ''Inner
data Mid = Mid { _midInner :: Inner }
deepLenses ''Mid
newtype Outer = Outer { _outerMid :: Mid }
deepLenses ''Outer
stateDeep :: MonadDeepState s Inner m => m ()
stateDeep = do
(Inner (S a)) <- get
b <- gets $ \(Inner (S b)) -> b
put (Inner (S (a + b + 3)))
main :: IO Outer
main = do
execStateT stateDeep (Outer (Mid (Inner (S 5))))
MonadReader works basically the same as MonadState.