Questions tagged [haskell-lens]

A lenses library for Haskell.

An extensive library which provides families of lenses, isomorphisms, folds, traversals, getters and setters.

For more info visit:

454 questions
1
vote
1 answer

Do I need Applicative Pretext for using Traversal with Lens?

I have a function that I believe is stricter than lens because of Applicative f context. Prelude Text.XML.Lens Data.Maybe Data.String Text.XML> :t f f :: Control.Applicative.Applicative f => (Element -> f Element) -> Document -> f…
sevo
  • 4,559
  • 1
  • 15
  • 31
1
vote
2 answers

Update nested maps in scala

In haskell it is possible to do the following. import Control.Lens import qualified Data.Map as M m :: Map Int (Map Int String) m = M.empty & at 1 . non M.empty . at 2 .~ Just "one-two" Is it possible to do something similar in scala? Maybe using…
Pavel
  • 127
  • 6
1
vote
1 answer

cabal install lens: library not found for -lHStransformers-compat-0.3.3.4-ghc7.8.3

This is on Mac OS X with brew installed ghc and cabal-install. latest versions. ghc 7.8.3 When I run cabal install lens I get this error output: Resolving dependencies... [1 of 1] Compiling Main (…
clay
  • 18,138
  • 28
  • 107
  • 192
1
vote
1 answer

Using a Prism as a smart constructor

I was browsing the 'lens' documentation concerning prisms, and I noticed a line in Control.Lens.Review stating that the infix review operator # 'is commonly used when using a Prism as a smart constructor.'. This got my a bit intrigued, because the…
Kasper
  • 1,205
  • 12
  • 22
1
vote
1 answer

wreq not compiling with cabal sandbox

I'm using cabal sandbox and I got this error when compiling the wreq library: Network/Wreq/Lens/Machinery.hs:20:58: Couldn't match type `[Name]' with `Name' Expected type: Name -> [Name] -> Name -> [DefName] Actual type: [Name] -> Name…
z1naOK9nu8iY5A
  • 903
  • 7
  • 22
1
vote
1 answer

Trouble when composing lenses

First of all, a snippet of code: λ> let applicationState = ('a','b',(M.fromList $ zip [1..3] [11,22,33],M.fromList $ zip [4,5,6] [44,55,66],M.fromList $ zip [7,8,9] [S.fromList ["77","777","7777"],S.fromList ["88","888","8888"],S.fromList…
FallingSkies
  • 121
  • 1
  • 10
1
vote
2 answers

Some potential and difficulties in the use of lenses in MonadState

What follows is a series of examples/exercises upon Lenses (by Edward Kmett) in MonadState, based on the solution of Petr Pudlak to my previous question. In addition to demonstrate some uses and the power of the lenses, these examples show how…
Alberto Capitani
  • 1,039
  • 13
  • 30
1
vote
1 answer

Saving a position with Lenses

I'm trying to use xml-conduit and xml-lens for parsing and traversing an XML document. Instead of having to traverse the same parts of the document multiple times, I would like to store the traversal up until the previous point and then drill down…
Adam
  • 89
  • 1
  • 2
  • 8
1
vote
2 answers

Is it possible to nest `at` with setters?

I'd like to set a value in 2 level map - i.e. to a key in a map which is a value for some key in an "outer" map. For ordinary Map I could use something like m & at 42 ?= "value" But I could not find any way to nest 2 at's What is the easiest way to…
Qrilka
  • 612
  • 1
  • 6
  • 19
1
vote
0 answers

Lensified Entity System

Inspired by this two comments on reddit I set out to create a 'lensified entity system'. The basic idea is to have Lens' Entity Value lenses, but although there is Action to create Getters with side effects there is no Setter or a combined LensM'…
fho
  • 6,787
  • 26
  • 71
1
vote
1 answer

How does `lens` work?

I mean, not the simple stuff like this (from here): strike :: StateT Game IO () strike = do lift $ putStrLn "*shink*" boss.health -= 10 But things like using lens to map over types from Linear. How would I express this in terms of…
fho
  • 6,787
  • 26
  • 71
1
vote
1 answer

Different setter and getter types in Haskell's lenses

I've got a data type G, which have got field _repr :: Data.Graph.Inductive.Gr String String. The normal way, when adding new node into Gr graph, we have to provide an LNode a object, which basically is defined as a tuple of (Int, a), where Int is…
Wojciech Danilo
  • 11,573
  • 17
  • 66
  • 132
0
votes
1 answer

How to conditionally set values in a nested record + list using lenses?

What's a succinct way to implement the ensureRecAFlag function using lenses? If RecB contains a RecA with recaFlag=True then do nothing Else, if RecB contains a RecA with recaName="internal_code" then set recaFlag=True for that RecA Else, if RecB…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
0
votes
1 answer

Implement a ReaderT monad Type for mocking network api calls

data TestEnv = TestEnv { rateLimiter' :: !TokenBucket , apiManager :: !Manager , apiKey :: !BS.ByteString } type BunnyReaderT m = ReaderT TestEnv m class MonadIO m => HasBunny m where runRequest :: Request -> m (Response BSL.ByteString) …
0
votes
1 answer

Elegant way to apply curried function to indexed traversal

I want to compose a curried function f :: i -> a -> b With an indexed traversal l :: IndexedTraversal' i s a apply it to an s and get back a [b]. I came up with s ^.. l . withIndex . to (uncurry f) But I would like a combinator itoListByOf that…
pat
  • 12,587
  • 1
  • 23
  • 52