felipe zapata | 4 Nov 23:51 2013
Picon

updating multiple fields of a record with lenses

 Dear Haskellers,

 let's  suppose I have the following lenses

 data Foo = Foo { _a :: String
                  _b :: [Double]
                  _c :: Vector Double
                  _d :: Int
                  .............. (more fields)
                  _z :: Double 
                }

Now, I want to update fields a,b,c and d without changing the rest.
What is the functional way of doing it ?

Surely there a function smarter than 

 set a "String" . set b [1,2,3] . set c  <1,2,3> . set d 4 $ foo
 
 can some please help me with it?
 
 Thanks in advance,
   
   Felipe Z.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Dan Burton | 5 Nov 00:04 2013
Picon

Re: updating multiple fields of a record with lenses

There's not really a "smarter" way to do it, but there is a "prettier" way:

foo
  & a .~ "String"
  & b .~ [1,2,3]
  & c .~ 'c'
  & d .~ 4


-- Dan Burton


On Mon, Nov 4, 2013 at 2:51 PM, felipe zapata <tifonzafel <at> gmail.com> wrote:
 Dear Haskellers,

 let's  suppose I have the following lenses

 data Foo = Foo { _a :: String
                  _b :: [Double]
                  _c :: Vector Double
                  _d :: Int
                  .............. (more fields)
                  _z :: Double 
                }

Now, I want to update fields a,b,c and d without changing the rest.
What is the functional way of doing it ?

Surely there a function smarter than 

 set a "String" . set b [1,2,3] . set c  <1,2,3> . set d 4 $ foo
 
 can some please help me with it?
 
 Thanks in advance,
   
   Felipe Z.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Charlie Paul | 5 Nov 00:09 2013
Picon

Re: updating multiple fields of a record with lenses

I had a similar question a while back, and I've been wondering why there isn't a nicer way to combine fine grained lenses. It could be used to create law-breaking lenses, but it instead gets implemented manually each time. Perhaps some sort of typeclass or GADT arrangement could be used to define a 'basis' of an object consiting of lenses which are independent, so setting twice works fine. Actually, I think an Iso' with a tuple would be sufficient to define this.

On Mon, Nov 4, 2013 at 3:04 PM, Dan Burton <danburton.email <at> gmail.com> wrote:
There's not really a "smarter" way to do it, but there is a "prettier" way:

foo
  & a .~ "String"
  & b .~ [1,2,3]
  & c .~ 'c'
  & d .~ 4


-- Dan Burton


On Mon, Nov 4, 2013 at 2:51 PM, felipe zapata <tifonzafel <at> gmail.com> wrote:
 Dear Haskellers,

 let's  suppose I have the following lenses

 data Foo = Foo { _a :: String
                  _b :: [Double]
                  _c :: Vector Double
                  _d :: Int
                  .............. (more fields)
                  _z :: Double 
                }

Now, I want to update fields a,b,c and d without changing the rest.
What is the functional way of doing it ?

Surely there a function smarter than 

 set a "String" . set b [1,2,3] . set c  <1,2,3> . set d 4 $ foo
 
 can some please help me with it?
 
 Thanks in advance,
   
   Felipe Z.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane