Friday, November 30, 2012

Boolean operators in F# are just fucntions.

Of course, F# has its boolean operators.
> true || false;;
val it : bool = true
> true && false;;
val it : bool = false
But, these are syntax sugar. && and || are not only operators but also functions!
> (||) true false;;
val it : bool = true
> (&&) true false;;
val it : bool = false
I have never known the fact until reading "Programming F# 3.0, 2nd Edition".

Tuesday, November 27, 2012

F#'s variable name is allowed to use apostrophe

F#'s variable name is allowed to use apostrophe, except as first character. I have never known the fact until reading "Programming F# 3.0, 2nd Edition".
> let Mary'sCookie = "Yummy";;

val Mary'sCookie : string = "Yummy"

Saturday, November 24, 2012

Start reading "Programming F# 3.0, 2nd Edition "

I have started reading the final edition of "Programming F# 3.0, 2nd Edition".
As far as I know, It's the first book dealing both F# 3.0 and VS2012.

Thursday, November 22, 2012

FreeBSD project has announced the security incident.

FreeBSD project has announced the security incident. And PC-BSD project also announces too.

Monday, November 19, 2012

I've finished reading "Programming Microsoft ASP.NET MVC, Second Edition"

I've finished reading the Japanese edition of "Programming Microsoft® ASP.NET MVC, Second Edition".

  • This book deals with ASP.NET MVC just literally. In other words, This book does not deal with EntityFramework.
  • But, this book is useful for understanding internal architecture of ASP.NET MVC 3.
  • Japanese edition's appendix (about ASP.NET MVC 4) is not enough, so I wait for its next edition!

Friday, November 16, 2012

Some libraries for Rails 3 still depend to rake 0.9

In this week, both Rails 3.2.9 and Rake 10.x have been released. Rails itself does not depend to rake version. But, some libraries of Rails 3 are depending to rake 0.9.x. so we should fix Gemfile like below:
gem 'rails', '3.2.9'
gem 'rake', '~> 0.9'

Tuesday, November 13, 2012

Three inconvenient things of F# Units of Measure

1. Becoming error when calculate between SI one and its scaled variation

For example, conversion between meter and kilometer is not self‐evident in F#.
For help type #help;;

> open Microsoft.FSharp.Data.UnitSystems.SI.UnitSymbols;;
> let a = 195<m>;;

val a : int<m> = 195

> [<Measure>] type km;;

[<Measure>]
type km

> let b = 42<km>;;

val b : int<km> = 42

> a + b;;

  a + b;;
  ----^

stdin(5,5): error FS0001: The unit of measure 'km' does not match the unit of measure 'm'
In this case, we must create some functions to convert these.

2. Becoming error when calculate with non-SI one

For example, conversion between meter and mile is not self‐evident in F#.
For help type #help;;

> open Microsoft.FSharp.Data.UnitSystems.SI.UnitSymbols;;
> let a = 10<m>;;

val a : int<m> = 10

> [<Measure>] type mile;;

[<Measure>]
type mile

> let b = 9<mile>;;

val b : int<mile> = 9

> a + b;;

  a + b;;
  ----^

stdin(5,5): error FS0001: The unit of measure 'mile' does not match the unit of measure 'm'
In this case too, we must create some functions to convert these.

3. Cannot instantiate collection of units values with range notation

Surprisingly, F# cannot allow to instantiate collection of units values with range notation.
For help type #help;;

> open Microsoft.FSharp.Data.UnitSystems.SI.UnitSymbols;;
> seq {1<g>..10<g>};;

  seq {1<g>..10<g>};;
  -----^^^^^

stdin(7,6): error FS0001: The type 'int<g>' does not match the type 'int'
In this case, we must do the redundant operation like below:
> seq { for i in [1..10] -> i * 1<g> };;
val it : seq<int<g>> = seq [1; 2; 3; 4; ...]

Saturday, November 10, 2012

QtCreator 2.6.0 has been released

In this week, QtCreator 2.6.0 has been released. This is the first major update since Digia finish to accept whole Qt Development teams. So I re-install both Qt 4.8.3 and QtCreator 2.6.0.

Thursday, November 8, 2012

Ruby 2.0 new feature : Refinements

In previous article, I wrote the ruby code with "monkey-patching". But, since ruby 2.0, there are better way to do it. It is "Refinements".
require 'singleton'

# Fibonacci as Singleton class
class Fibonacci < Enumerator
  include Singleton

  def initialize
    super { |y|
      a = 0
      b = 1
      loop do
        y << a
        a, b = b, a + b
      end
    }
  end
end

# define a refinement
module Nth
  refine Enumerator do
    def nth(n)
      self.take(n+1).find.with_index { |elem, i| i == n }
    end
  end
end

begin
  # there are no additional methods
  puts Fibonacci.instance.lazy.nth(100)
rescue => e
  puts e
end

#using refinments
using Nth

begin
  # there is an additional method
  puts Fibonacci.instance.lazy.nth(100)
rescue => e
  puts e
end

$ cd /c/ruby-2.0.0
$ ./bin/ruby ~/fibonacci.rb
undefined method `nth' for #<Enumerator::Lazy:0x26430d8>
354224848179261915075

Monday, November 5, 2012

Ruby 2.0 new feature : Enumerator::Lazy

In functional language, The feature called "lazy evaluation" exists as its key feature. For example, fibonacci in F# is:
Microsoft (R) F# Interactive version 11.0.50727.1
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> let fibonacci = Seq.cache <| Seq.unfold (fun (current, next) -> Some(current, (next, current + next))) (0I, 1I);;

val fibonacci : seq

> fibonacci |> Seq.nth 100;;
val it : System.Numerics.BigInteger =
  354224848179261915075 {IsEven = false;
                         IsOne = false;
                         IsPowerOfTwo = false;
                         IsZero = false;
                         Sign = 1;}

Ruby 2.0's Enumerator::Lazy can do "lazy evaluation" like this:
irb(main):001:0> RUBY_VERSION
=> "2.0.0"
irb(main):002:0> fibonacci = Enumerator.new { |y|
irb(main):003:1*   a = 0
irb(main):004:1*   b = 1
irb(main):005:1>   loop do
irb(main):006:2*     y << a
irb(main):007:2>     a, b = b, a + b
irb(main):008:2>   end
irb(main):009:1> }.lazy
=> #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x23cbbc0>:each>>
irb(main):010:0> def fibonacci.nth(n)
irb(main):011:1>   self.take(n+1).find.with_index { |elem, i| i == n }
irb(main):012:1> end
=> nil
irb(main):013:0> fibonacci.nth(100)
=> 354224848179261915075

If the above sample did not use Enumerator::Lazy, it would take many many seconds.

Friday, November 2, 2012

Ruby 2.0.0 preview 1 has been announced

Today, Ruby 2.0.0 preview 1 has been announced.

[ruby-dev:46348] [ANN] ruby 2.0.0-preview1 released

On my Windows (MinGW), build goes green.