lenses Questions

1

Solved

Let's say I have a list of records, and I want to summarize it by taking the median. More concretely, say I have data Location = Location { x :: Double, y :: Double } I have a list of measuremen...
Gigantean asked 28/8, 2014 at 3:49

1

Solved

The problem is pretty simple. I have a structure that looks something like this data Foo = Foo [Bar] data Bar = Boo | Moo Item Int data Item = Item String Int and I have a lens for changing the ...
Govan asked 1/7, 2014 at 16:17

1

Solved

I've been playing around with lenses recently, and finding them very pleasant for their intended usage - digging into complex data structures. But one of the areas that I'd most appreciate them is ...
Triparted asked 27/6, 2014 at 23:23

3

Solved

I'm struggling with using the lens library for a particular problem. I'm trying to pass an updated data structure a lens focussed on part of that updated structure to another function, g. I pas...
Sebrinasebum asked 2/5, 2014 at 8:49

2

What is the best way to update an element in a collection using lenses? For example: case class Ingredient(name: String, quantity: Int) case class Recipe(val ingredients: List[Ingredient]) If ...
Regurgitation asked 18/10, 2013 at 8:14

1

Solved

I'm trying to get used to the lens library for Haskell, and find myself struggling at some simple problems. For instance, let's say (for convenience) that at and _1 have the following types (this i...
Glengarry asked 12/3, 2014 at 20:34

2

Solved

I find myself using this pattern often: do let oldHeaders = mail ^. headers put $ (headers .~ (insert header value oldHeaders)) mail which seems like the kind of thing Control.Lens should be a...
Safe asked 13/1, 2014 at 5:0

2

Solved

I'm working with Control.Lens. The actual function I'm writing is rather complex, but for the purpose of this question, I've boiled it down to a minimal failing example: import Control.Lens exam...
Surveying asked 20/11, 2013 at 19:28

3

Solved

I have a [(a, Maybe b)], and want to obtain a [(a, b)], with all pairs where the second element was Nothing filtered out. Is there a concise way to describe this operation using lens?
Winchester asked 25/10, 2013 at 14:7

1

Solved

There's an example of a Scalaz map lens here: Dan Burton calls it containsKey, and it's inspired by the Edward Kmett talk. There is also something called mapVPLens in Scalaz 7 which is useful for m...
Whang asked 16/9, 2013 at 18:49

1

Solved

If I have a record type with lenses, is it possible to construct a new record without using the underlying record accessors? {-# LANGUAGE TemplateHaskell #-} import Control.Lens import Control.Le...
Tanjatanjore asked 25/8, 2013 at 15:2

1

Solved

I am using Edward Kmett's lens library for the first time, and finding it rather nice, but I ran into a snag... The question at [1] explains that existential quantifiers disrupt makeLenses. I real...
Hinayana asked 5/8, 2013 at 15:19

2

Solved

I'm using the code below on a record that has a field '_scene' of type SceneGraph. I've created lenses for it using makeLenses. inputGame :: Input -> Game -> Game inputGame i g = flip execSt...
Dogvane asked 9/7, 2013 at 1:47

2

Solved

Using a lens library I can apply a modification function to individual targets, like so: Prelude Control.Lens> (1, 'a', 2) & _1 %~ (*3) (3,'a',2) Prelude Control.Lens> (1, 'a', 2) & ...
Naominaor asked 8/7, 2013 at 13:38

1

Solved

The following code doesn't compile: {-# LANGUAGE TemplateHaskell #-} import Control.Lens data MyType = MyType Int data Outer = Outer { _inners :: [ Inner ] } data Inner = Inner { _val :: MyType ...
Kamerad asked 8/7, 2013 at 2:12

2

Most popular JSON libraries for Scala have the ability to serialize and deserialize to case classes. Unfortunately, until Scala 2.11 is released, there is a restriction on the number of parameters...
Oahu asked 22/6, 2013 at 20:56

1

Solved

I have this file: {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE ExistentialQuantification #-} module Toy where import Control.Lens data Bar = Bar { _barish :: String } data Foo = forall a. Show...
Elka asked 22/6, 2013 at 22:55

2

Solved

Having these imports: > import Control.Lens Control.Lens> import qualified Data.Map as Map and a map value defined as follows: Control.Lens Map> let m = Map.fromList [('a', 1), ('c', 3...
Slew asked 17/6, 2013 at 9:28

3

Solved

I have a list of records and need a function which searches the list for a record with a given name and modify the value of this record OR if no record matches append a new record to the resulting ...
Shed asked 13/6, 2013 at 12:57

2

Solved

I have some datatypes along the line of data Outer = Outer { _list :: [ Inner ] } data Inner = Inner { _bool :: Bool } using Control.Lens, I can access the _bool of the ith Inner (inside a 'Stat...
Tartu asked 9/6, 2013 at 5:15

1

Solved

Let’s play a game. There are two piles we’re going to use, both consisting of black/white sided chips. data Pile = Pile { _blacks, _whites :: Int } makeLenses ''Pile data Game = Game { _pileA, _p...
Beachhead asked 3/6, 2013 at 0:4

2

Solved

How does lens handle the case where a de-sugared field is a keyword? I seem to remember reading that something special is done, but I can't remember where I read it or what the name of the "lensed"...
Oralee asked 17/5, 2013 at 13:2

1

I want to create a function A -> Bool using some lenses of A. For instance: data A = A { _foo :: Int, _bar :: Int } makeLenses ''A l :: [A] l' = filter (\a -> a^.foo > 100) l The filt...
Joses asked 13/5, 2013 at 9:54

2

Solved

I'm learning the Lens package. I must say it's a rather challenging task. Can someone show me how to traverse a Tree with Zipper from Lens? In particular, how can I write a function that takes a ...
Underneath asked 19/3, 2013 at 0:15

1

Solved

I was coding with with the lens package. Everything was going fine until I tried to access a certain field on an algebraic type: import Control.Lens data Type = A { _a :: Char } | B makeLenses '...
Colangelo asked 25/4, 2013 at 3:33

© 2022 - 2024 — McMap. All rights reserved.