Dec 7, 2010

How Binding in f# is like in CLR

In c# or clr philosophy, everything is object, object is the horsepower. In f# philosophy, everything is value, function is the horsepower. However f# is implemented in CLR, I am just curious how F# is implement in CLR, so I use reflector to decompile the generated code. However, I don't think reflector is not very accurate here. To really understand , it is better is use ILDASM.exe.

let m1 = 1 // convert to readonly property
//public static int m1
//{
//    [CompilerGenerated, DebuggerNonUserCode]
//    get
//    {
//        return 1;
//    }
//}

let mutable m2 = 1 //get and set property
//[CompilationMapping(SourceConstructFlags.Value)]
//public static int m2
//{
//    get
//    {
//        return $Program.m2@174;
//    }
//    set
//    {
//        $Program.m2@174 = value;
//    }
//}
 
 
let m3() = 1 //method return 1
//public static int m3()
//{
//    return 1;
//}
 

let m4 x = x + 1  //method accept one parameter
//public static int m4(int x)
//{
//    return (x + 1);
//}

 
let m5 (x) = x + 1 //method accept one parameter, same as m5
//public static int m5(int x)
//{
//    return (x + 1);
//}

let m6 x y = x + y + 1 //a method that accept two parameter x, y, but with a attribute CompilationArguementCounts
//[CompilationArgumentCounts(new int[] { 1, 1 })]
//public static int m6(int x, int y)
//{
//    return ((x + y) + 1);
//}


let m7 (x, y) = x + y + 1 //a method that accept one parameter, which is a turple, compiled into normal function
//public static int m7(int x, int y)
//{
//    return ((x + y) + 1);
//}

let m8 = m6 1 //partial function, compiled to property that returns a delegate, which is type of FSharpFunc<int, int>
//CompilationMapping(SourceConstructFlags.Value)]
//public static FSharpFunc<int, int> m8
//{
//    get
//    {
//        return $Program.m8@180;
//    }
//}

//[Serializable]
//internal class m8@180 : FSharpFunc<int, int>
//{
//    // Fields
//    [DebuggerBrowsable(DebuggerBrowsableState.Never), CompilerGenerated, DebuggerNonUserCode]
//    public int x;
//
//    // Methods
//    internal m8@180(int x)
//    {
//        this.x = x;
//    }
//
//    public override int Invoke(int y)
//    {
//        return Program.m6(this.x, y);
//    }
//}


let m9 y = m7 (1, y) //compiled to a method, that call a m7 with 1 and y
//public static int m9(int y)
//{
//    return m7(1, y);
//}

let turple1 = (1, 2)
//[CompilationMapping(SourceConstructFlags.Value)]
//public static Tuple<int, int> turple1
//{
//    get
//    {
//        return $Program.turple1@268;
//    }
//}
 
// [DebuggerBrowsable(DebuggerBrowsableState.Never)]
//internal static Tuple<int, int> turple1@268;
//

 
let m10 = m7 turple1 
//[CompilationMapping(SourceConstructFlags.Value)]
//public static int m10
//{
//    get
//    {
//        return $Program.m10@281;
//    }
//}
// 
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
//internal static int m10@281;
//