Tuesday, May 31, 2011

Studying F# : inline keyword

When you define simple calculator function, you just write like below:
let add a b = a + b

There is a question. What type of these arguments? In F# interactive console, it's int, so othre numeric types is not accepted for this function.
> let add a b = a + b;;

val add : int -> int -> int

> add 2 3;;
val it : int = 5
> add 2.0 3.0;;

  add 2.0 3.0;;
  ----^^^

stdin(3,5): error FS0001: This expression was expected to have type
    int
but here has type
    float
How do we make the function acceptable other numeric types?

Saturday, May 28, 2011

openSUSE Tumbleweed on VirtualBox

If you want to launch openSUSE Tumbleweed on your machine directory, you just install from this repository.

http://download.opensuse.org/repositories/openSUSE:/Tumbleweed/standard/

But, if you want to launch openSUSE Tumbleweed on VirtualBox, that is not enough. You should add the repository below:

http://download.opensuse.org/repositories/Virtualization:/VirtualBox_Tumbleweed/openSUSE_Tumbleweed/

Thursday, May 26, 2011

Yet another simple way to associate One-To-One relation and to modify both tables.

There's a sample to associate One-To-One relation and to modify both tables in ASP.NET MVC3.
But there is some margin for more CoC. So I describe yet another simple way.

Monday, May 23, 2011

Tickets for RubyKaigi2011 are on sale

From yesterday, Some tickets about RubyKaigi2011 (a.k.a. THE LAST RubyKaigi) were on sale. There are three SKUs for attending this conference.
In addition to these SKUs, there are one more ticket for attending official conference party.

I already bought a Normal Ticket.

Friday, May 20, 2011

O'Reilly's e-books go DRM free in Japan too.

E-books on oreilly.co.jp were not DRM free, despite e-books on oreilly.com had been DRM free already. But that is over. In yesterday, oreilly.co.jp announced they made their e-books DRM free (news release in Japanese).

Tuesday, May 17, 2011

Studying F# : Module

In F#, there are namespace like C#. But, it is not normal F# way and F#'s namespace is not permitted nested namespaces. The normal F# way is defining module.

Declaration

module Examples
let helloWorld() = "Hello World"
module Greeting =
    let helloWorld() = "Hello Module World"
    module Inner =
        let helloWorld() = "Hello Inner Module World"
Normally, it is enough that there is just one module declaration in the first line. If you want to declare more than one modules or nested modules, module declaration is in below lines and it requires =.

Usage

If you want to use some modules, open statement must be in another module or in namespace global.
namespace Program
open Examples
[<Class>]
type Simple() =
    static member execute() =
        System.Console.WriteLine("Examples.helloWorld() : {0}", helloWorld())
        System.Console.WriteLine("Examples.Greeting.helloWorld() : {0}", Greeting.helloWorld())
        System.Console.WriteLine("Examples.Greeting.Inner.helloWorld() : {0}", Greeting.Inner.helloWorld())
        0

Saturday, May 14, 2011

Studying F# : Generics

In Java or C#, Generics is written as <T>, T is the type parameter.

In F#, it's similar to above, we just write <'a>, 'a is the type parameter.
[<Class>]
type Reflector<'a>() =
    member r.GetMembers() =
        let ty = typeof<'a>
        ty.GetMembers()
let rflc = new Reflector<System.Math>()
// usage
Array.iter (fun it -> System.Console.WriteLine(it.ToString())) (rflc.GetMembers())
Function typeof gets the concrete type of type parameter.

This is normal generic way. And there is one more generic way - with static type parameter.
[<Class>]
type StaticReflector() =
    static member GetMembers<'a>() =
        let ty = typeof<'a>
        ty.GetMembers()
// usage
Array.iter (fun it -> System.Console.WriteLine(it.ToString())) (StaticReflector.GetMembers<System.Math>())

Wednesday, May 11, 2011

Studying F# : Interface

F# has interfaces. we can define it and use it like other object-oriented languages.

Definition


[<Interface>]
type IDrinker =
    inherit System.IComparable
    inherit System.IFormattable
    abstract Drink : unit -> unit // method definition of interface
    abstract FavoriteDrink : string // property definition of interface
Interface can inherit another interfaces multiply.

Usage


[<Class>]
type DrinkingPerson(fn, ln, a) =
    inherit System.Object()
    interface IDrinker with
        member this.CompareTo(other) =
            let other = other :?> DrinkingPerson
            let tln : string = this.LastName
            let ln = tln.CompareTo(other.LastName)
            if ln <> 0 then
                let tfn : string = this.FirstName
                let fn = tfn.CompareTo(other.FirstName)
                if fn <> 0 then
                    let ta : int = this.Age
                    ta.CompareTo(other.Age)
                else
                    fn
            else
                ln
        member this.ToString(s:string, fp:System.IFormatProvider):string =
           "Not interesting enough to implement yet"
        member this.Drink() =
            System.Console.WriteLine("Yep")
        member this.FavoriteDrink =
            "Grapefruit juice"
    override this.GetHashCode() =
        hash(fn, ln, a)
    override this.Equals(other) =
        compare this (other:?>DrinkingPerson) = 0
    member p.FirstName = fn
    member p.LastName = ln
    member p.Age = a
hash and compare are utility functions for implementing GetHashCode() and Equals(other) explicitly.

Monday, May 9, 2011

Qt 4.7.3 has been released

A few days ago, Qt Framework 4.7.3 and Qt Creator 2.2 have been released. We can choose for installing the latest Qt either by using QtSDK only or by using each installers (Qt Framework and Qt Creator).