Thursday, February 28, 2013

Ruby DevKit is also updated

Ruby DevKit is also updated. There are two distributions.

If you use MinGW in Windows 64bit, you should add configure option --host=x86_64-mingw32 or --build=x86_64-mingw32.

Monday, February 25, 2013

Ruby 2.0.0 has been released

In yesterday, Ruby 2.0.0 has been released, finally.
If you build this tarball on MinGW32, you must do configure with --host=mingw32 option like this post.

Ruby 2.0.0 contains RubyGems 2.0.0, and if you want to use bundler with RubyGems 2.0.0, there are 2 ways.

Friday, February 22, 2013

Couchconf Tokyo 2013

(Write it later)

Tuesday, February 19, 2013

Type dispatch with F# pattern match

(In learning from "Programming F# 3.0, 2nd Edition")

In F#, type dispatch is made with pattern match.
> let whatTypeNumberIs (n:obj) =
-   match n with
-   | :? int16 | :? int32 | :? int64 as i -> "This is int."
-   | :? uint16 | :? uint32 | :? uint64 as ui -> "This is uint."
-   | :? double as d -> "This is double."
-   | :? single as s -> "This is single."
-   | _ -> "This is not a number.";;

val whatTypeNumberIs : n:obj -> string

> whatTypeNumberIs 2;;
val it : string = "This is int."
> whatTypeNumberIs 2.0;;
val it : string = "This is double."

Saturday, February 16, 2013

Calling constructor of superclass in F#

(In learning from "Programming F# 3.0, 2nd Edition")

> open System.Globalization;;
> type AncientCalendar<'a> =
-   inherit JulianCalendar
-   val m_subfield : 'a
-   new(subfield) =
-     {
-       inherit JulianCalendar()
-       m_subfield = subfield
-     };;

type AncientCalendar<'a> =
  class
    inherit JulianCalendar
    new : subfield:'a -> AncientCalendar<'a>
    val m_subfield: 'a
  end

Thursday, February 14, 2013

Visual Studio Tools for Git becomes perfect

In this week, Microsoft has released Visual Studio Tools for Git 0.7.0.2. since this release VisualStudio for Git becomes perfect for 2 reasons.

  1. Visual Studio Tools for Git also supports Visual Studio Express 2012 for Web
  2. And since 0.7.0.2, this tool goes green on multi-byte environment. (see this article)

Monday, February 11, 2013

Reference cell

(In learning from "Programming F# 3.0, 2nd Edition")

Reference cell is another way to define mutable variable without mutable keyword. When using ref keyword, it creates reference cell that contains that you write after ref keyword.
> let x = ref 0;;

val x : int ref = {contents = 0;}

> x;;
val it : int ref = {contents = 0;}
> !x;;
val it : int = 0
> x := !x + 1;;
val it : unit = ()
> x;;
val it : int ref = {contents = 1;}
> !x;;
val it : int = 1
In sample above, x referres reference cell itself, if we want to refer the content of reference cell, we must use !x, and if we want to modify the content of reference cell, wemust use operator :=

Friday, February 8, 2013

Explain Seq.unfold verbosely

(In learning from "Programming F# 3.0, 2nd Edition")

Seq.unfold is a function hard-to-understand if I read any Microsoft's documents and any books. For example, the way in "Programming F# 3.0, 2nd Edition" is hard to understand.
> // Generate the next element of the Fibonacci sequence given the previous
// two elements. To be used with Seq.unfold.
let nextFibUnder100 (a, b) =
    if a + b > 100 then
        None
    else
        let nextValue = a + b
        Some(nextValue, (nextValue, a));;

val nextFibUnder100 : int * int -> (int * (int * int)) option

> let fibsUnder100 = Seq.unfold nextFibUnder100 (0, 1);;

val fibsUnder100 : seq<int>

> Seq.toList fibsUnder100;;
val it : int list = [1; 1; 2; 3; 5; 8; 13; 21; 34; 55; 89]

But, since I re-write this example verbosely like below, I can understand about it.
module UnfoldVerbosely =
    let fibSeed (current, next) =
        let yieldValue = current
        let next'current = next
        let next'next = current + next
        Some(yieldValue, (next'current, next'next))
    let fib = Seq.unfold fibSeed (1L, 1L)

printfn "%A" (Seq.take 2 UnfoldVerbosely.fib)
printfn "%A" (Seq.take 3 UnfoldVerbosely.fib)
printfn "%A" (Seq.take 4 UnfoldVerbosely.fib)
printfn "%A" (Seq.take 5 UnfoldVerbosely.fib)
module UnfoldVerbosely = begin
  val fibSeed : current:int * next:int -> (int * (int * int)) option
  val fib : seq<int>
end

seq [1; 1]
seq [1; 1; 2]
seq [1; 1; 2; 3]
seq [1; 1; 2; 3; ...]

Wednesday, February 6, 2013

Yield Bang is similar to Ruby's multiple assignment

(In learning from "Programming F# 3.0, 2nd Edition")

Yield Bang ( yield! ) is similar to Ruby's multiple assignment.

In Ruby (multiple assignment)

require 'pathname'

def all_file_under(pathname)
  pathname.each_child.find_all(&:directory?).reduce(pathname.each_child.find_all(&:file?)) do |accum, subpathname|
    accum = Array[*accum, *all_file_under(subpathname)]
  end
end

puts all_file_under(Pathname.new('C:\temp'))
C:\temp/AAAAA
C:\temp/BBBBBB
C:\temp/CCCCCCC
C:\temp/DDD/EEEE
...

In F# (Yield Bang)

> open System.IO;;
> let rec allFilesUnder basePath =
-     seq {
-         yield! Directory.GetFiles(basePath)
-         for subdir in Directory.GetDirectories(basePath) do
-             yield! allFilesUnder subdir
-     };;

val allFilesUnder : basePath:string -> seq<string>

> allFilesUnder @"C:\temp";;
val it : seq<string> =
  seq
    ["C:\temp\AAAAA"; "C:\temp\BBBBBB";
     "C:\temp\CCCCCCC"; "C:\temp\DDD\EEEE"; ...]

Monday, February 4, 2013

Lazy Evaluation in F#

(In learning from "Programming F# 3.0, 2nd Edition")

Define lazy instance

These two are completely same way.
> let current = lazy(System.DateTime.Now);;

val current : Lazy<System.DateTime> = Value is not created.
> let current = Lazy<System.DateTime>.Create(fun() -> System.DateTime.Now);;

val current : System.Lazy<System.DateTime> = Value is not created.

Evaluate lazy instance

These two are also completely same way.
> current.IsValueCreated;;
val it : bool = false
> current.Value;;
val it : System.DateTime = 2013/02/04 20:40:19 {Date = 2013/02/04 0:00:00;
                                                Day = 4;
                                                DayOfWeek = Monday;
                                                DayOfYear = 35;
                                                Hour = 20;
                                                Kind = Local;
                                                Millisecond = 676;
                                                Minute = 40;
                                                Month = 2;
                                                Second = 19;
                                                Ticks = 634956072196762680L;
                                                TimeOfDay = 20:40:19.6762680;
                                                Year = 2013;}
> current.IsValueCreated;;
val it : bool = true
> current.Value;;
val it : System.DateTime = 2013/02/04 20:40:19 {Date = 2013/02/04 0:00:00;
                                                Day = 4;
                                                DayOfWeek = Monday;
                                                DayOfYear = 35;
                                                Hour = 20;
                                                Kind = Local;
                                                Millisecond = 676;
                                                Minute = 40;
                                                Month = 2;
                                                Second = 19;
                                                Ticks = 634956072196762680L;
                                                TimeOfDay = 20:40:19.6762680;
                                                Year = 2013;}
> current.IsValueCreated;;
val it : bool = false
> current.Force();;
val it : System.DateTime = 2013/02/04 20:40:19 {Date = 2013/02/04 0:00:00;
                                                Day = 4;
                                                DayOfWeek = Monday;
                                                DayOfYear = 35;
                                                Hour = 20;
                                                Kind = Local;
                                                Millisecond = 676;
                                                Minute = 40;
                                                Month = 2;
                                                Second = 19;
                                                Ticks = 634956072196762680L;
                                                TimeOfDay = 20:40:19.6762680;
                                                Year = 2013;}
> current.IsValueCreated;;
val it : bool = true
> current.Force();;
val it : System.DateTime = 2013/02/04 20:40:19 {Date = 2013/02/04 0:00:00;
                                                Day = 4;
                                                DayOfWeek = Monday;
                                                DayOfYear = 35;
                                                Hour = 20;
                                                Kind = Local;
                                                Millisecond = 676;
                                                Minute = 40;
                                                Month = 2;
                                                Second = 19;
                                                Ticks = 634956072196762680L;
                                                TimeOfDay = 20:40:19.6762680;
                                                Year = 2013;}

Friday, February 1, 2013

Qt-MinGW reloaded

In this week, Qt 5.0.1 is released. And, Qt-MinGW distribution restarts!