-
"this" in javascript
If you don't know javascript is a functional language and you do lots of object oriented programming, the follow code must be very confusing for you.
var name = "Jerry";
-
mutable binding and ref type
We all know that in F#, once you bind a value to an identifier, that the value can not be changed. What does this means? It means the your identifier will be like a read only property, the property return a value that is determined at the time of binding. After binding, the identifier looks like a constant. Mutable makes identifier more like a variable. But actually, it is a property with both getter and setter. Let's look at the following code.
let testMutable = //let mutable temp = 1 let temp = 1 let innerFunction() = printfn "%i" temp () innerFunction
-
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; // } //}
-
Pattern matching shorthand in function definition
Pattern matching is powerful construct in F#, but sometime it is confusing to beginner, below is pattern matching shorthand in function definition. The paramter is implied in the matching pattern, essentially you can rewrite it as below.
let listOfList = [[2; 3; 5]; [7; 11; 13]; [17; 19; 23; 29]]
-
benchmark you javascript
Here is script that is used to benchmark jQuery.
// Runs a function many times without the function call overhead function benchmark(fn, times, name){ fn = fn.toString(); var s = fn.indexOf('{')+1, e = fn.lastIndexOf('}'); fn = fn.substring(s,e); return benchmarkString(fn, times, name); }