I'm not sure I follow this. Do you want your code to have labeled arguments with the labels mean, volatility, skew and kurtosis but you want the body of your function to refer to them by their greek symbols and you want the code to transparently interop with other .NET languages using the latin names rather than the greek symbols?

Maybe F#'s named arguments satisfy the requirements? I haven't used them but maybe something like:
static member func(mean=μ, volatility=σ, skew=ξ, kurtosis=κ) =
1.0 + μ + σ + ξ + κ</code>Cheers, Jon.

By on 8/17/2008 1:46 PM ()

Hi Jon,

many thanks for the quick response.

You've hit the nail on the head. The interop I'd like is more to do with reflection of argument names (for documentation, intellisense etc) than latin/greek, but this idea is the same. As you've perhaps found, the readability of large mathematical formulas (like polynomial expansions) can suffer when using full english names whereas using conventional mathematical symbols can help (especially with a reference to the original mathematical text.)

Unfortunately using the snippet you provided caused a syntax error. After reading the F# manual it seems that only calls to methods (rather than definitions) may use named arguments. If fact using the 'as' pattern in a method signature breaks the use of named arguments even when calling the method:

1
let result = Test.func( volatility=1.0, skew=0.0, kurtosis=3.0, mean=0.0) // this is fine
1
let error = TestAsPatternInMethod.func( volatility=1.0, skew=0.0, kurtosis=3.0, mean=0.0) // causes Error: The member or object constructor 'func' has no argument or settable return property 'volatility'...

Reflector disassembles TestAsPatternInMethod.func so:

1
2
3
4
5
6
7
8
9
10
11
12
public static double func(double _arg2, double _arg3, double _arg4, double _arg5)
{
    double mean = _arg2;
    double μ = mean;
    double volatility = _arg3;
    double σ = volatility;
    double skew = _arg4;
    double ξ = skew;
    double kurtosis = _arg5;
    double κ = kurtosis;
    return ((((1.0 + μ) + σ) + ξ) + κ);
}

which probably breaks the reflection mechanism used in intellisense.

Please let me know if I got this all wrong!

thanks again,

Danny

By on 8/17/2008 2:49 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