Member constraints don't work with type extensions. If they did, you could do some seriously cool things...

I'm not sure whether this limitation is documented in the F# spec.

The lower half of this thread might be also interesting to you: [link:cs.hubfs.net]

Regards,
Stephan

By on 9/15/2008 12:29 AM ()

[b]Stephan[/b], thanks for your answer.

What does the [b]F# Team[/b] say about this?

By on 9/15/2008 5:18 AM ()

Hi yashez,

I've run into the same problem myself.

I was trying to extend Vector with mathematical functions and operators so:

1
2
3
4
5
6
7
8
9
type Microsoft.FSharp.Math.Vector<'a > with


    static member Exp xv =  Vector.map exp xv


    /// Dot Product of two vectors multiplication of two vectors.
    [<OverloadID("VectorVectorMultiplyPlus")>]
    static member ( *+ ) (xv: Vector<'a>) (yv: Vector<'a>) = Vector.sum (xv .* yv)

so I could write stuff like:

1
let μ = pmf *+ exp (d0 * xv)

alas I get a similar errors:
The type 'vector' does not support any operators named 'Exp'The type 'vector' does not support any operators named '*+'

Having native support for more mathematical functions, operators ( e.g. ** and ScalarVectorAdd ), interfaces ( e.g. IList) in vector and matrix would be cool.

Type constraints and operators in extensions would be highly desirable (if found to be well-behaved) and very powerful indeed.

Until such time I'll continue to debate which of the following is more elegant:

1
2
3
4
let Sv          = vector [ for x in xv -> S * exp ( µ * T + d0 * x ) ]

let Sv          = S * Vector.map (fun x -> exp ( µ * T + d0 * x ) ) xv

At the moment form (1) is ahead.

regards,

Danny

By on 9/15/2008 10:04 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