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
2 answers

Haskell: What does "uses" do in control lens?

I'm new to Haskell. I was reading the code here and I'm not sure (though I can guess) what uses do: inRange <- uses fsCurrentCoinRangeUpperBound (coinIndex <=) Also, why's <- been used? I've looked up for "Control lens uses in Haskell" but I…
user4564798
  • 97
  • 10
0
votes
1 answer

How do I correctly format a function using Control.Lens?

I'm currently learning the lens library by writing some simple functions using the library. Unfortunately, I'm rather confused by the compiler errors generated, and so I'm struggling to determine why, in the function dmg below, the first two…
SolventGren
  • 145
  • 1
  • 6
0
votes
1 answer

How to automatically convert a record in "makeFields" lens format to JSON with fields matching lenses?

data ArticlePreview = ArticlePreview { _articlePreviewName :: T.Text , _articlePreviewPerex :: T.Text , _articlePreviewAuthorName :: T.Text , _articlePreviewAuthorUrl :: T.Text , _articlePreviewDate ::…
monnef
  • 3,903
  • 5
  • 30
  • 50
0
votes
1 answer

How do I combine lenses which contain context?

I'm starting from authorityL via authorityHostL to hostBSL - I know you can combine lenses via (authorityL . authorityHostL . hostBSL) but that fails with Couldn't match type ‘Authority’ with ‘Maybe Authority’. How do I properly deal with the Maybe…
Reactormonk
  • 21,472
  • 14
  • 74
  • 123
0
votes
1 answer

Lens setter to add element to end of tuple

Is there any lens that will help me do the following transformation for a tuple of any length (say up 10-15 elements, at least): (a, b, c) -> d -> (a, b, c, d)
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
0
votes
1 answer

Get list of values from sublist with Control.Lens

I am trying to get list of values from a substructure. I have the following structure ("Value",[(1,"1"),(2,"2"),(3,"3"),(4,"4"),(5,"5")]) And I am trying to get the second element of the tuples in the list. ["1", "2" , "3" , "4" , "5"] The…
yilmazhuseyin
  • 6,442
  • 4
  • 34
  • 38
0
votes
1 answer

The relationship between Data.Key and Control.Lens.Indexed

There are Keyed and FunctorWithIndexed classes in keys and lens` libraries respectively. Their member functions mapWithKey and imap seems to be similar, except that keys is formulated using type families, and lens uses functional dependencies. When…
phadej
  • 11,947
  • 41
  • 78
0
votes
1 answer

Query properties of Object

What's the Aeson equivalent of the javascript property accessor. How would you translate the javascript statement x.a.b to Haskell? As an example, given someObject :: Object containing e.g: { a: { b: [ 1 , 2 ] } } What would the…
fredefox
  • 681
  • 3
  • 11
0
votes
1 answer

Why do all Lens match Foldl.Handler type?

According to Control.Foldl documentation: Any lens, traversal, or prism will type-check as a Handler type Handler a b = forall x. (b -> Constant (Endo x) b) -> a -> Constant (Endo x) a One might claim that since lens allows for any Functor…
sevo
  • 4,559
  • 1
  • 15
  • 31
0
votes
2 answers

Composable Lensing

I have the following Haskell types import Control.Lens import Data.Map.Lens import qualified Data.Map as M type RepoStats = M.Map String (M.Map String RepoStat) data RepoStat = RepoStat { _full_name :: String, _bug_count :: Maybe Int, …
Steve
  • 1,596
  • 1
  • 10
  • 21
0
votes
0 answers

Cabal error: Failed to load interface for `Control.Lens.Type'

Can't build trifecta-1.5.2 ghc-pkg check shows no borken packages error: [ 8 of 13] Compiling Text.Trifecta.Highlight ( src\Text\Trifecta\Highlight.hs, dist\build\Text\Trifecta\Highlight.o ) src\Text\Trifecta\Highlight.hs:73:1: Failed to load…
cnd
  • 32,616
  • 62
  • 183
  • 313
0
votes
1 answer

Using lens for access to a Data.Sequence.Seq

Is there any way to use lens to get functionality similar to the functions in Data.List? For instance I am thinking of something like isPrefixOf :: Eq a => Seq a -> Seq a -> Bool isSuffixOf :: Eq a => Seq a -> Seq a -> Bool And of course these…
massysett
  • 1,100
  • 6
  • 13
0
votes
1 answer

Haskell: Changing an element at a given index in a ByteString

I'm trying to change a character at indices x and y in a matrix made of ByteStrings to a different character. Initially, I used [[Char]] to represent the matrix, so I was able to use .~ from Control.Lens.Setter to change the value, but this doesn't…
the spectre
  • 350
  • 4
  • 11
0
votes
2 answers

Array indexing lens out of array and index lenses

This is a simpler version of Using lens for array indexing if both array and index are in State as I have resolved some issues. I'm not sure if I should delete the original or edit it in place. Given {-# Language TemplateHaskell #-} {-# Language…
nponeccop
  • 13,527
  • 1
  • 44
  • 106
0
votes
1 answer

xml-lens API surprise: function composition and travelsals

How are following expressions different in their intent? I'm surprised that they actually type check and produce different results in example below. (./) :: Plated a => Traversal s t a a -> Traversal a a u v -> Traversal s t u v --…
sevo
  • 4,559
  • 1
  • 15
  • 31
1 2 3
30
31