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
0
votes
1 answer

How to modify an element that matches a condition using lenses?

I'm trying to write a function with the following type-signature using lenses, but staring blankly at filtered is apparently not working! modifyElem :: (a -> Bool) -- predicate function -> (a -> a) -- modification to apply -> [a] …
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
0
votes
1 answer

Could not deduce (Show a10) arising from a use of ‘def’

I have been stuck on this error for quite a while. I'm not sure if I am being stupid but I cannot see where it is coming from... The data type Settings is defined as so: data Settings a = Settings { _nodeDrawFunction :: a -> Diagram B …
0
votes
1 answer

How to increase coverage for record types with lenses?

Background I am using record types with the lens. I have written some unit tests with HUnit and HSpec. However, the hpc coverage report shows that the field accessors were never executed. Thus, contributing to the lower coverage for the record…
Gavin
  • 4,458
  • 3
  • 24
  • 37
0
votes
1 answer

How to use the same record selector two ways within a function? Lenses?

I have some data that have different representations based on a type parameter, a la Sandy Maguire's Higher Kinded Data. Here are two examples: wholeMyData :: MyData Z wholeMyData = MyData 1 'w' deltaMyData :: MyData Delta deltaMyData = MyData…
trevor cook
  • 1,531
  • 8
  • 22
0
votes
1 answer

How can I reconstruct a JSON array from a slice using lens?

I would like to extract a slice of a JSON array using lenses, and get a Value back. More specifically, I am trying to do the following: $ import qualified Data.ByteString.Lazy as LBS $ import Data.Aeson.Lens $ import Control.Lens $ let e =…
insitu
  • 4,488
  • 3
  • 25
  • 42
0
votes
1 answer

Folding or concatMap-ing an Aeson Array via lenses

I've been starting at https://www.stackage.org/haddock/lts-12.1/lens-aeson-1.0.2/Data-Aeson-Lens.html and https://www.stackage.org/haddock/lts-12.1/lens-4.16.1/Control-Lens-Fold.html trying to figure out how to write an expression that allows me to…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
0
votes
1 answer

Is it possible to define your own Persistent / Esqueleto lens?

Given the following persistent type: share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| Account email Text passphrase Text firstName Text lastName Text deriving Eq Show Generic |] What I think is a…
danbroooks
  • 2,712
  • 5
  • 21
  • 43
0
votes
1 answer

What makes lengthOf inefficient in lens?

I noticed this remark in lens claiming that lengthOf can be "rather inefficient": -- /Note:/ This can be rather inefficient for large containers [...] lengthOf :: Getting (Endo (Endo Int)) s a -> s -> Int lengthOf l = foldlOf' l (\a _ -> a + 1)…
sevo
  • 4,559
  • 1
  • 15
  • 31
0
votes
0 answers

Using Control.Lens.Plated with python AST

I'm trying to learn to use plated to transform and search through the python AST generated by language-python (https://hackage.haskell.org/package/language-python-0.5.4/docs/Language-Python-Common-AST.html) To briefly summarize the types: Modules…
willtalmadge
  • 406
  • 3
  • 7
0
votes
1 answer

Traverse/Rewrite a JSON Value

I have the following json-data value :: Maybe Value value = decode "{ \"import\" : { \"starttime\": \"2017-02-20T18:45:456.45645\" \ \ , \"endtime\" : \"2017-02-20T18:45:456.45645\" \ \ } \ \ ,…
epsilonhalbe
  • 15,637
  • 5
  • 46
  • 74
0
votes
1 answer

How to eliminate the boilerplate of wrapping and unwrapping using lenses

tl;dr: is it possible to use any of the lens family of abstractions to wrap/unwrap any arbitrary newtype (that provides an instance for such abstractions)? I'll motivate my question by a simple example, based on a true story. Suppose I define the…
Damian Nadales
  • 4,907
  • 1
  • 21
  • 34
0
votes
0 answers

Haskell Setter/over with multiple targets?

Is there a way to combine lenses, such that I can apply a function over a and b in the below structure, but not c? import Control.Lens hiding (element) data SomeInts = SomeInts {_a :: Int , _b :: Int, _c :: Int } deriving (Show) makeLenses…
Carbon
  • 3,828
  • 3
  • 24
  • 51
0
votes
2 answers

How to apply the same lens on two different records? (or, record field-names as first-class values?)

Consider the following records and their lenses: data Bar = Bar {barField1 :: Int, barField2 :: String} makeLensesWith abbreviatedFields ''Bar data BarError = BarError {barerrField1 :: [String], barerrField2 :: [String]} makeLensesWith…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
0
votes
1 answer

A typecheck errors in deriving wrapper for Linear.V

I am trying to make a newtype wrapper for the Linear.V type and derive useful instances. I was trying this: {-# LANGUAGE DataKinds, PolyKinds, ScopedTypeVariables, StandaloneDeriving, FlexibleContexts, UndecidableInstances,…
user1747134
  • 2,374
  • 1
  • 19
  • 26
0
votes
1 answer

Haskell: use or uses in Getter

In Control.Lens we have Getter that can access the nested structure. Getter has use and uses, but it's not clear to me how they work. So it'd be great if someone can provide some simple examples that use or uses is utilised. Why do I need to know…
4xx
  • 165
  • 8