Sunday, February 24, 2008

WMI - FSharp

WMI test is my 'Hello World' :-)

#light
open System
open System.Management

let getLogicalDisk () =
let query = "select * from win32_logicaldisk where drivetype = '3'"
let objMgt = new ManagementObjectSearcher(query)
let result = objMgt.Get()
for info in result do
let caption = info.GetPropertyValue("Caption").ToString()
let size = info.GetPropertyValue("Size").ToString()
printf "%2s : %15s Ko\n" caption size

getLogicalDisk ()

read_line ()

FSharp - Discovering

I must admit that after Python, It has been difficult for me to find another
language which was as attractive as Python.
I think F# will be this one.


#light

open System

let print x = printfn "%A" x
let sub a b = a - b

let halfway a b =
let dif = b -a
let mid = dif/2
let z = mid + a
z

let y = (fun x y -> x + y) 1 2

let rec fib x =
match x with
| 1 -> 1
| 2 -> 1
| x -> fib (x-1) + fib (x-2)

let UnAnApres =
DateTime.Now + new TimeSpan(365,0,0,0,0)

let print_List l =
List.iter print_string l
print_string "\n"

let shortHand = ["apples"; "pairs"]

shortHand |> printf "%A"

read_line ()