Yes, if you're using a record type, you can clone it replacing some values in the process like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#light


type MyType = { P1 : float; P2 : float; P3 : float; Pn : float }


let x = { P1 = 1.0; P2 = 2.0; P3 = 3.0; Pn = 4.0 }


let y = { x with P1 = x.P1 + 0.1 }


printfn "x: %A" x
printfn "y: %A" y

This script prints the following to the console:

1
2
3
4
5
6
7
8
x: {P1 = 1.0;
 P2 = 2.0;
 P3 = 3.0;
 Pn = 4.0;}
y: {P1 = 1.1;
 P2 = 2.0;
 P3 = 3.0;
 Pn = 4.0;}
By on 10/6/2008 7:32 AM ()

I tried with .Copy - but I did'nt think that it is that easy ;-)

Thanks a lot. F# rulez.

By on 10/6/2008 7:43 AM ()

Thanks a lot. F# rulez.

That it does! Glad to help. :)

By on 10/6/2008 7:45 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper