lenses Questions

1

Solved

As I understand it, each van Laarhoven optic type can be defined by a constraint on a type constructor: type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t type Traversal ...
Divergent asked 27/1, 2023 at 2:23

1

I'm encoding a form of van Laarhoven lenses in OCaml, but am having difficulty due to the value restriction. The relevant code is as follows: module Optic : sig type (-'s, +'t, +'a, -'b) t val le...
Fist asked 21/3, 2015 at 19:49

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

0

I've had a bit of difficulty using Lenses with Maps. I have maps that look like this Map String (Map String Int). These are multidimensional arrays, and I usually set them up with known dimensions....
Fuentes asked 26/6, 2020 at 19:14

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

Many types of optics have a van Laarhoven representation. For example, a Lens of type Lens s t a b can be represented as: Functor f => (a -> f b) -> s -> f t Similarly a Traversal...
Larimer asked 27/10, 2019 at 21:19

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

2

Solved

Given the following code: case class Person(name :String) case class Group(group :List[Person]) val personLens = GenLens[Person] val groupLens = GenLens[Group] how can i "filter" out ce...
Intendant asked 26/5, 2016 at 19:15

2

Solved

Is there some way to automatically generate a getter/setter function pair for a property in a class in Swift? Something along the lines of a lens in Haskell. I've been able to do the following man...
Pembroke asked 22/10, 2014 at 20:58

3

Solved

I have an array of objects like this: [ { name: "Group 1", value: "Foo" }, { name: "Group 2", value: "Bar" }, { name: "Group 1", value: "Baz" } ] I'd like to use Partial Lenses library to tra...
Spearman asked 15/11, 2018 at 12:58

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

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

0

What I'd like to do, is having field descriptor defined as field1.field2[1].field3, access value two of json: { "field1": { "field2": [ { "field3": "one" }, { "field3": "two" } ] } } I...
Hephzipah asked 9/3, 2018 at 17:37

2

Solved

In functional optics, a well-behaved prism (called a partial lens in scala, I believe) is supposed to have a set function of type 'subpart -> 'parent -> 'parent, where if the prism "succeeds"...
Buhrstone asked 23/9, 2017 at 20:51

3

Similar to this case class question but with a twist: I have a case class which has some deeply nested case classes as properties. As a simple example, case class Foo(fooPropA:Option[String], foo...
Zoellick asked 2/8, 2013 at 21:11

1

Let's say I have a pair of conversion functions string2int :: String -> Maybe Int int2string :: Int -> String I could represent these fairly easily using Optics. stringIntPrism :: Prism ...
Hanover asked 28/11, 2015 at 14:21

2

import Control.Lens import Control.Lens.TH data Foo = Foo { _bar, _baz :: Int } makeLenses ''Foo Now if I want to modify both int fields, I can do barbaz :: Setter' Foo Int barbaz = sets $ \f...
Dacoity asked 14/3, 2017 at 11:30

1

Solved

A type like Maybe (Lens' a b) doesn't work because Lens' is under the hood a Rank-2 type, that can't be wrapped in a type constructor without the -XImpredicativeTypes extension (which is not really...
Harmonicon asked 7/1, 2017 at 15:7

1

Solved

I have the following model import monocle.macros.Lenses import monocle.function.all._ import monocle.std.list._ @Lenses("_") case class Poll(pollChoices: List[PollChoice], totalVoteCount: Int) @L...
Pulchia asked 13/12, 2016 at 14:23

3

I'm currently writing a Haskell program that involves simulating an abstract machine, which has internal state, takes input and gives output. I know how to implement this using the state monad, whi...
Intercommunion asked 2/10, 2016 at 3:50

1

I'm trying to build lenses for records which have the same field names. Along with that, I'm trying to "wrap/extend" these base records and want the same field names to work for the wrapped/extende...
Calamite asked 12/8, 2016 at 9:41

2

Solved

My use case is based on the following model: struct Person { let name: String let houses: [House] } struct House { let owner: Person } Now, ideally I would like to maintain a bidirectional r...
Delp asked 25/7, 2016 at 1:32

2

Solved

I'm watching the Control.Lens introduction video. It makes me wonder why is it needed for the Setter type to wrap things in functors. It's (roughly) defined like this: type Control.Lens.Setter s t...
Bathhouse asked 6/6, 2016 at 20:57

2

Solved

Using Ramda.js (and lenses), I want to modify the JavaScript object below to change "NAME:VERSION1" to "NAME:VERSION2" for the object that has ID= "/1/B/i". I want to use a lens because I want to ...
Inflect asked 21/2, 2016 at 16:0

1

Was playing around with lenses in Prolog. Lenses are a kind of microscope that allow to zoom into a structure and do some reads or writes in a functional fashion. Basically my point of departure wa...
Baskerville asked 17/2, 2016 at 17:16

© 2022 - 2024 — McMap. All rights reserved.