Pages

Sunday, December 12, 2010

F# project and AssemblyInfo

put the following code into your project and make this file's extension from .fs to .fsx.

.fs won't build, but .fsx will build.

open System.Reflection;
open System.Runtime.CompilerServices;
open System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[ < assembly: AssemblyTitle("BB from © AA") > ]
[ < assembly: AssemblyDescription("BB") > ]
[ < assembly: AssemblyConfiguration("") > ]
[ < assembly: AssemblyCompany("AA") > ]
[ < assembly: AssemblyProduct("BB") > ]
[ < assembly: AssemblyCopyright("© AA. All rights reserved.") > ]
//[ < assembly: AssemblyTrademark("") > ]
[ < assembly: AssemblyCulture("") > ]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[ < assembly: ComVisible(false) > ]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[ < assembly: Guid("c95f0dd1-9182-4d48-8bc2-b6cc2bca17bc5") > ]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the ‘*’ as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[ < assembly: AssemblyVersion("1.0.1010.0032") > ]
[ < assembly: AssemblyFileVersion("1.0.1010.0032") > ]
()


I have to say I was wrong, you can still use it as a .fs file. But .fsi file should still work. 

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.