FAQ Database Discussion Community


Is it possible to make Traversal an instance of IsString

haskell,types,lens,aeson
I want to use string literal as Traversal, but I am a bit lost in types. Is it possible to create this instance? import Control.Lens import Data.Aeson import Data.Aeson.Lens import Data.String import Data.Default {- Having: key' :: AsValue t => Text -> Traversal' t (Maybe Value) _JSON :: (ToJSON a,...

Functionally updating arbitrarily nested data structures with lenses

haskell,functional-programming,lens
Say I have a data structure representing a Bag of Holding, which can hold multiple items. The user could place another Bag of Holding in this bag, and that bag could contain other bags, or even bags containing bags. Is there a lens for functionally updating arbitrarily nested bags, e.g....

Haskell lens: let binding of Traversal'

haskell,traversal,lens
I'm a bit confused and don't know where to look for the information/explanation of the following "issue" (it's not an issue per se, but more of a situation where I don't understand what is wrong behind the scenes): I have a monad transformer stack with StateT. At some point in...

What is the purpose of united lens?

haskell,lens
While reading through the Lens over Tea #1 article, I found the united lens. My implementation is united :: Lens' a () united f v = const v <$> f () which is pretty much the same as the implementation in the Lens library. What leaves me completely baffled is...

Use a lens to replace a specific element of a (key,value) list

haskell,lens
I want to use Kmett's lens library to access an element of a (key, value) list under a specific key. In other words, I would like to replace this code with something more idiomatic and perhaps shorter: type Headers = [ (ByteString, ByteString) ] headerLens :: Functor f => ByteString...

Is this expected behavior of Template Haskell?

haskell,template-haskell,lens
Can anyone tell why this code doesn't compile data A = A { _b :: B } makeLenses ''A type B = String with message Not in scope: type constructor or class B and this does: type B = String data A = A { _b :: B } makeLenses...

Transformations with Data.Aeson.Lens

haskell,lens,aeson
Using aeson-lens, I wrote this program that takes me very close to what I want to achieve: {-# LANGUAGE OverloadedStrings #-} import Network.HTTP.Conduit ( simpleHttp ) import Data.Aeson ( decode , Value ) import Data.Maybe ( fromJust ) import Control.Lens ( (^.) ) import Data.Aeson.Lens ( key, nth ) main...

Type error with rank-n types and lenses

haskell,lens,higher-rank-types
I have a simple polymorphic datatype Foo {-# LANGUAGE TemplateHaskell #-} import Control.Lens data Foo c = Foo { _bar :: c, _baz :: c, _quux :: c } makeLenses ''Foo The generated lenses are, of course, polymorphic in c. The type from GHCi is: *Main> :t bar bar ::...

What are the similarities and differences between a lens in Haskell and using a key-sequence in Clojure?

haskell,clojure,lens,nested-map
Assumptions: I know that Haskell encourages solving problems with a type system, and Clojure eschews a type system, preferring to solve the problem with data structures. We can see that we can create a lens like this in Haskell: {-# LANGUAGE TemplateHaskell #-} import Control.Lens initialState :: Game initialState =...