Questions tagged [haskell-optics]
7 questions
9
votes
1 answer
Is there a van Laarhoven optic based on the Monad typeclass?
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 s t a b = forall f. Applicative f => (a -> f b) -> s ->…

Katie Casamento
- 93
- 3
3
votes
1 answer
Haskell optics: Setter for several lists
I would like to set an item at position x between two lists, as if they were the same list.
For example:
data Foo = Foo {
list1 :: [Char],
list2 :: [Char]}
foo = Foo ['a', 'b', 'c'] ['d', 'e', 'f']
setItem :: Int -> Char -> Foo ->…

cdupont
- 1,138
- 10
- 17
3
votes
2 answers
What is the difference between single double qoute/apostrophe in template-haskell?
When learning about Haskell lenses with the Optics package, i encountered the following example:
data Person = Person
{ _name :: String
, _age :: Int
}
makeLenses ''Person
makePrisms 'Person
What does a value of type Name represent and what…

manews
- 340
- 2
- 12
2
votes
1 answer
Is there an `id` of `prism' id Just`?
I have a function called:
mapRouteEncoder ::
Prism' FilePath FilePath ->
Prism' r1 r2 ->
(b -> a) ->
RouteEncoder a r1 ->
RouteEncoder b r2
This function is often used by specifying "identity" prisms (if we can call it that) in the first…

Sridhar Ratnakumar
- 81,433
- 63
- 146
- 187
2
votes
1 answer
Unable to coerce during `DerivingVia` when using optics types like `Prism'`
I'm unable to automatically derive instances using DerivingVia on any type that uses types from optics-core like Prism'; the error I get from compiler is:
src/Main.hs:24:13-19: error:
• Couldn't match type ‘Foo’ with ‘Stringable Foo’
…

Sridhar Ratnakumar
- 81,433
- 63
- 146
- 187
2
votes
1 answer
Optic from map to its association pairs
I need a Fold (Map k v) (k, v) optic. Is there a way to obtain it with the "optics" library? If not, is there one with "lens"?

Nikita Volkov
- 42,792
- 11
- 94
- 169
0
votes
1 answer
Haskell Lenses: Difference of two HashSets in Folds
Given:
f1, f2 :: Fold Box (HashSet Thing)
how do I write a fold that focuses the Things that are in f1 but not in f2? It would (of course) be the same Box, but f1 and f2 filter its contents differently.
I can see that filtered and hasn't might come…

Adrian May
- 2,127
- 15
- 24