Hide this comment

Looks like this might be what you want:

1
2
3
type 'a Obs = Obs of 'a with
  static member inline (+)(Obs(a),Obs(b)) = Obs(a + b)

I don't think this worked in the previous release of F# unless you used ^a instead of 'a throughout, but I could be mistaken.

By on 6/30/2009 4:40 AM ()Reply
Hide this comment

Cool. I had no idea you could do this. Thanks!

By on 6/30/2009 5:40 AM ()Reply
Hide this comment

I eagerly typed in the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
type vector3 = { x: float; y: float; z: float }


type System.Double with
        [< OverloadIDAttribute("op_Multiply_Vector3") >]
        static member inline ( * )(a : float, b : vector3) : vector3 =
            { x = a * b.x ; y = a * b.y ; z = a * b.y }


let v = { x = 1.0; y = 2.0; z = 3.0 }


do printfn "%A" (5.0 * v)

to see if the long-standing limitation on operators in type extensions had been dealt with.

Alas no.

So close...

By on 6/30/2009 6:27 AM ()Reply
Hide this comment

Good question. I'd love to get an answer to this too.

By on 6/30/2009 3:48 AM ()Reply
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

Logging in...