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

  • SEARCH
  • Home
  • 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 6123261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:59:41+00:00 2026-05-23T15:59:41+00:00

In Mercury I can use: A = B^some_field := SomeValue to bind A to

  • 0

In Mercury I can use:

A = B^some_field := SomeValue

to bind A to a copy of B, except that some_field is SomeValue instead of whatever it was in B. I believe the Haskell equivalent is something like:

a = b { some_field = some_value }

Does Scala have something like this for “modifying” immutable values. The alternative seems to be to have a constructor that directly sets every field in the instance, which isn’t always ideal (if there are invarients the constructor should be maintaining). Plus it would be really clunky and much more fragile if I had to explicitly pass every other value in the instance I want to have a modified copy of.

I couldn’t find anything about this by googling, or in a brief survey of the language reference manual or “Scala By Example” (which I have read start-to-finish, but haven’t absorbed all of yet, so it may well be in there).

I can see that this feature could have some weird interactions with Java-style access protection and subclasses though…

  • 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-23T15:59:41+00:00Added an answer on May 23, 2026 at 3:59 pm

    You can use case classes for this, but you don’t have to. Case classes are nothing magical – the modifier case just saves you a lot of typing.
    The copy method is realized by the use of named and default parameters. The names are the same as the fields and the defaults are the current values of the fields. Here’s an example:

    class ClassWithCopy(val field1:String, val field2:Int) {
        def copy(field1:String = this.field1, field2:Int = this.field2) = {
            new ClassWithCopy(field1,field2);
        }
    }
    

    You can use this just like the copy method on case classes. Named and default parameters are a very useful feature, and not only for copy methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use the Mercury editor that was presented in railscast lately =>
Using CSS, how can I style the following: <dl> <dt>Mercury</dt> <dd>Mercury (0.4 AU from
I have a working rails 3.1 application that uses the mercury wysiwyg editor, however
I'm using Asp.net to create a csv file that the user can open directly
I want to use Mercury Editor (https://github.com/jejacks0n/mercury) to edit posts in the blog area
I have a virtual machine (VMware) with Mercury Quick Test Professional 9.2 installed. I
Is it possible to call a COM API from Java (specifically the HP/Mercury Quality
I'm attempting to add Mercury editor and while modifying the layout for it, it
I'm trying to send an email using swift_smtptransport that will connect to 127.0.0.1:25 I'm
I am new to TFS and i have been using svn,mercury. I am confused

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.