Pages

Sunday, November 28, 2010

Default Company name for Visual Studio 2010 project

you have to change:


  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization (for 32-bit version)
  • HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization (for Windows 7 64-bit)
I tested it on Win7 version.

Monday, November 8, 2010

F# continuation

Another sample of F# continuation passing style (CPS).

let F01 list =
            let rec FF list cont =
                match list with
                    | [] -> cont(0)
                    | h::t -> FF t (fun x -> cont(h+x))
            FF list (fun x-> x)

Friday, November 5, 2010

F# interop with C#

In F# file:

namespace AA

    [ < system.runtime.compilerservices.extension > ]
    module BB =
        [< system.runtime.compilerservices.extension > 
        let F(i:System.Int32, first:char, last:char) = {first .. last}

        let F2(a,b) = 12

In C#, you can call:


            int a = 3;
            var list = a.F('a', 'z');
            var b = BB.F2(a, 0.5);

Thursday, November 4, 2010

Serialization when using Base class

XmlInclude is the key, it should put on the base class and make the serialization of Automobile feasible.

[System.Xml.Serialization.XmlInclude(typeof(Car))]
[System.Xml.Serialization.XmlInclude(typeof(Truck))]
public class Automobile
{
    public string Name;
    public int Year;
}

public class Car : Automobile
{
    public int NumerOfDoors;
}

public class Truck : Automobile
{
    public bool LongBed;
}

Monday, November 1, 2010

Recursion in F# Yacc

Just do not know why, keep forget the recursion for fsyacc.


List:
| Expr { [$1] }
| List ',' Expr { $3::$1 }

Sunday, October 24, 2010

Tail Recursive Call != Recursive function call

These days I always think about the F# continuation and about the people blame recursive call. Is that true all the recursive call will generate the stack overflow? The answer is NO. The stack-overflow only happens when the parent call is waiting for the return value from the child invoke. If the recursive function does not return anything, there is no stack-overflow at all.

You have to use 64-bit compiler to make this happen; 32-bit does not work.

Wednesday, October 20, 2010

Pre-Order/In-Order/Post-Order tree transversal

when we use the CSP to transverse a tree, I got confused due to the how to implement the pre-order/in-order/post-order transversal.

when i look at previous post, i realize the keypoint is in the highlighted section.

type Tree = 
    E | T of Tree * value * Tree

let rec f2 tree cont =
    match tree with
        | EmptyTree -> cont([])
        | Tree(l, n, r) ->
            f2 l (fun lSum ->
                    f2 r (fun rSum->cont(lSum@[n]@rSum)))


currently it is in-order. You can change it to [n]@lSum@rSum and this will be pre-order.