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 7008149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:41:52+00:00 2026-05-27T21:41:52+00:00

Basically I want to achieve a tuple (or any datatype that fits my problem)

  • 0

Basically I want to achieve a tuple (or any datatype that fits my problem) that contains a list that can be updated. Because of immutability and such the below demonstrator code does not work of course. It is only to illustrate better what I want to achieve.

I wonder of there are any elegant ways, datatypes (IOREfs?) or modules that would do that for me or if in such a case I really would need to take apart the whole tuple, and reconstruct it with the updated elements.

By the way: intuitively I would have expected that at least as long as test is not printed the list msgs will not be evaluated.

test = ("192.168.1.1", 3455, (1234566, msgs))
msgs = ["aaa", "bbbb", "ccccc"]

main = do
     --print test
     let msg_tmp = "first" : msgs
     let msgs = msg_tmp
     print msgs
     print test 
  • 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-27T21:41:53+00:00Added an answer on May 27, 2026 at 9:41 pm

    Have you considered using lenses? If your purpose is to make updating the tuple easy and transparent for the programmer, they fit the bill very nicely. The following uses the excellent fclabels package:

    import Data.Label
    import Control.Category
    import Prelude hiding ((.))
    
    
    test = ("192.168.1.1", 3455, (1234566, msgs))
    msgs = ["aaa", "bbbb", "ccccc"]
    
    append x = modify messages (x :)
    
    main = do
         let test' = append "first" test
         print test'
         print (get messages test')
    
    second2 = lens (\(a,b) -> b)   (\b (a,_) -> (a,b))
    third3  = lens (\(a,b,c) -> c) (\c (a,b,_) -> (a,b,c))
    messages = second2 . third3
    

    The second2 and third3 can either be generic functions that you
    define once for all the tuples you need, or they can be something
    with meaningful names like messages, or timestamp. Anyways, this
    is something that is written once, and then hidden in the library.

    Testing with GHCi gives the desired result:

    ghci> :main
    
    ("192.168.1.1",3455,(1234566,["first","aaa","bbbb","ccccc"])) 
    ["first","aaa","bbbb","ccccc"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just can't figure a way to achieve this. I basically want to get
Basically I want to achieve such functionality that 5-10 functions are executed in a
Basically, I want to achieve the same thing as ON DUPLICATE KEY in MySQL.
I'm trying to achieve a small animated intro to a website. Basically I want
Part 1 I want to build a PHP Zend Framework application that users can
I have Django app that presents a list of items that you can add
I'm looking for some API for printing. Basically what I want to achieve is
Basically I want to achieve this workflow: Checkout from repository on windows system (or
Sorry for the poor title, basically I want to access a list item based
I'm pretty desperate because I can't figure out how to achieve what I stated

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.