Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6876197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:26:51+00:00 2026-05-27T04:26:51+00:00

Could someone explain functional lenses to me? It’s a surprisingly difficult subject to google

  • 0

Could someone explain functional lenses to me? It’s a surprisingly difficult subject to google for and I haven’t made any progress. All I know is that they provide similar get/set functionality than in OO.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:26:51+00:00Added an answer on May 27, 2026 at 4:26 am

    A lens consists of two functions, a getter and a setter:

    data Lens a b = Lens { getter :: a -> b, setter :: b -> a -> a }
    

    For example, we might have lenses for the first and second parts of a pair:

    fstLens :: Lens (a, b) a
    fstLens = Lens fst $ \x (a, b) -> (x, b)
    
    sndLens :: Lens (a, b) b
    sndLens = Lens snd $ \x (a, b) -> (a, x)
    

    The real convenience of lenses is that they compose:

    compose :: Lens b c -> Lens a b -> Lens a c
    compose f g = Lens (getter f . getter g) $
                       \c a -> setter g (setter f c (getter g a)) a
    

    And they mechanically convert to State transitions:

    lensGet :: MonadState s m => Lens s a -> m a
    lensGet = gets . getter
    
    lensSet :: MonadState s m => Lens s b -> b -> m ()
    lensSet f = modify . setter f
    
    lensMod :: MonadState s m => Lens s b -> (b -> b) -> m ()
    lensMod f g = modify $ setter f =<< g . getter f
    
    (+=) :: (MonadState s m, Num b) => Lens s b -> b -> m ()
    f += x = lensMod f (+ x)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not looking for any specific code examples, but could someone explain why I
I wonder if someone could be kind enough to explain the function.prototype thingie (thingie!!??)
Could someone explain to me in simple terms the easiest way to change the
Could someone explain? I understand the basic concepts behind them but I often see
Could someone explain why this works in C#.NET 2.0: Nullable<DateTime> foo; if (true) foo
Could someone explain why both tests using the latest versions of Moq and Rhino.Mocks
Could someone explain what I am doing wrong with my classes that my JTabbedPane
Could someone explain to me how can I run my py2exe program, a console
Could someone explain this (strange) behavior? Why is the length in the first example
Could someone explain to me what this portion of code means? repeat scroll 0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.