haskell-lens Questions

3

Solved

Control.Lens.Tutorial says: type Traversal' a b = forall f . Applicative f => (b -> f b) -> (a -> f a) type Lens' a b = forall f . Functor f => (b -> f b) -> (a -> f a) ...
Avulsion asked 21/2, 2024 at 14:5

1

Solved

I was trying to use the lens library to solve the following problem: Given the list version of a tree, make a tree. Example: Given: [1,2,3,4,5,6,7] I should make a tree: 1 2 3 4 5 6 7 My solu...
Bod asked 11/7, 2023 at 15:41

2

Solved

When you look at setting in lens-family-core package, you'll find that its type is Identical f => ((a -> b) -> s -> t) -> LensLike f s t a b, and Identical is defined as class (Trave...
Sabadilla asked 6/6, 2023 at 0:42

1

Solved

I have a value: my :: [(A, Either B [C])] and I want to get [(A, C)] from it using lens. The result items are items from my that: the second item in tuples is Right [C] the list in this Right [C]...
Kylie asked 11/5, 2023 at 10:46

1

Suppose I have a simple GADT. data Expr a where Int' :: Integer -> Expr Int Fun :: Text -> Expr a (:*) :: Expr (a -> b) -> Expr a -> Expr b Now, I can define the following traver...
Wooldridge asked 26/7, 2022 at 8:52

2

Solved

I am trying to access a nested record using lenses and prisms in Haskell: import Data.Text (Text) import Control.Lens.TH data State = State { _stDone :: Bool , _stStep :: StateStep } data Stat...
Cacophony asked 28/2, 2022 at 21:52

2

Solved

I would like to be able to combine two tuples of the same length using a function, similar to the zipWith function from base. For example, for the case of length 3 tuples: zipTupleWith f (a0,a1,a2)...
Orrin asked 1/6, 2021 at 22:22

1

Solved

I'm wondering if there is an identity lens in Haskell. A lens identity such that if I had a type data MyType = MyType { _myField :: Int }, then I can do myType ^. identity . myField .~ 2 . There se...
Venge asked 23/6, 2020 at 8:47

2

Solved

If I have a newtype newtype Foo = Foo Int is there an automatic way to get an Iso' Foo Int? I saw I could use makeLenses ''Foo, but I don't know what is the name of the generated iso.
Covarrubias asked 7/2, 2020 at 8:51

1

Solved

Edward Kmett's optics library; Control.Lens defines a large number of types. Most of these have relatively self explanatory names, like Traversal and Fold. It also defines some types with less ...
Latency asked 19/8, 2019 at 8:32

1

Solved

I'm writing a function which uses the lenses library, but curiously, the code doesn't compile when I remove the type annotation. {-# LANGUAGE TemplateHaskell, Rank2Types #-} import Control.Lens ...
Ngocnguyen asked 16/7, 2019 at 22:12

4

Solved

This is an example of using a zipper in Haskell: data Tree a = Fork (Tree a) (Tree a) | Leaf a data Cxt a = Top | L (Cxt a) (Tree a) | R (Tree a) (Cxt a) type Loc a = (Tree a, Cxt a) left :: Loc ...

3

Solved

I have a type like this: data Problem = ProblemFoo Foo | ProblemBar Bar | ProblemBaz Baz Foo, Bar and Baz all have a lens for their names: fooName :: Lens' Foo String barName :: Lens' Bar Strin...
Eboh asked 16/10, 2018 at 9:49

1

Solved

zoom allows us to use a state action that only uses some state variables, in a context where more variables are actually defined. {-# LANGUAGE TemplateHaskell #-} import Control.Lens import Cont...
Passer asked 16/8, 2018 at 11:33

3

Solved

I'm trying to achieve a deeper understanding of lens library, so I play around with the types it offers. I have already had some experience with lenses, and know how powerful and convenient they ar...
Antipodes asked 18/6, 2018 at 18:34

1

Solved

A prism is an optic for focusing into coproduct types, while affine traversal is a kind of optic which can focus at 0 of 1 element, i.e. AffineTraversal s t a b is isomorphic to (s -> Maybe a, (...
Sneed asked 19/3, 2018 at 23:19

3

Solved

Let's say I have some fairly simple data type Person with a couple of fields, and a type that holds a collection of Persons. data Person = Person { _name :: String, _age :: Int } data ProgramStat...
Diadiabase asked 3/1, 2014 at 10:39

4

Solved

lens offers holesOf, which is a somewhat more general and powerful version of this hypothetical function: holesList :: Traversable t => t a -> [(a, a -> t a)] Given a container, holesL...
Yardman asked 23/2, 2018 at 18:53

3

Solved

I'm new to the excelent Control.Lens and I'm trying to combine 2 lens in "parallel" (not in sequence) like I would do with `Control.Arrow.&&&). If I take the example from the lens docu...
Erection asked 27/4, 2014 at 9:50

1

Solved

Can I use a list of Traversal? The following code: f::[Int] -> [[Int]] f l = [l & i .~ 1 | i<-[ix 0], (l^? i) == Just 0] produces an error: • Couldn't match type ‘Const (Data.Monoid....
Pushkin asked 5/11, 2017 at 8:15

1

Solved

Imagine I have the following list: lst :: [(Bool, Maybe Integer)] lst = [(True, Just 3), (True, Nothing), (False, Just 12)] Using the lens library, I want to extract the elements of the tuples, ...
Induline asked 26/7, 2017 at 18:23

2

Solved

I'm looking to filter a traversal, then select the last element to use with over. e.g. something like this (but which will actually compile): [1,2,3,4] & traverse . filtered even . _last +~ ...
Garamond asked 19/6, 2017 at 2:5

3

Solved

If I have lenses for a nested record, where each lens returns a Maybe, how can I get them to compose, so that if anything in the "traversal" returns a Nothing the final result is a Nothing? data C...
Whiteeye asked 19/6, 2017 at 6:58

1

Solved

I'm trying to learn more about the lens library. I already understand the lenses in the lens-family package and their derivation and also grasp the two type parameter versions of Store, Pretext and...
Mitran asked 1/6, 2017 at 14:35

4

Solved

I'm basically trying to override a bunch of default values in a record only if the user-specific values are NOT Nothing. Is it possible to do it via lenses? import qualified Data.Default as DD in...
Gannet asked 25/5, 2017 at 16:0

© 2022 - 2025 — McMap. All rights reserved.