ZFR, This code should work equally well (depending on what you're doing with it) and it's more in keeping with F#'s idioms (at least as I understand them). As far as I understand, you want to avoid mutable members if possible and I think in this case you can.

1
2
3
4
5
6
7
8
9
10
11
12
 

type ComplexNumber(r:float32, i:float32) = 

   member this.Real = r 

   member this.Imaginary = i 

   static member (+) (a1:ComplexNumber, a2:ComplexNumber) = 

      new ComplexNumber(a1.Real + a2.Real, a1.Imaginary + a2.Imaginary) 

And then this should work:

1
2
3
4
5
6
 

let a = new ComplexNumber(1.0f, 1.0f) 

let b = a + new ComplexNumber(1.0f, 0.0f) 

My humble attempt at assistance.

By on 5/5/2010 2:08 PM ()

Psychic answer:

[link:msdn.microsoft.com]

:)

By on 5/5/2010 12:24 PM ()
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