|
ToDo:
|
5:50にbootしました。
ボチボチとF#をお勉強始めました。
delegateはof句に続き引数の仮宣言して、->で戻り値ですかね。
type delegatedFunc = delegate of int * int -> string
let ret = (new delegatedFunc(fun x y -> "Return = " + System.Convert.ToString(x * y))).Invoke(10,20)
System.Diagnostics.Debug.WriteLine(ret)
奇数・偶数の判定
let (|Judge|_|) j =
match j%2 with
| 0 -> Some(Judge)
| _ -> None
let Judge j =
match j with
| Judge j -> "Even"
| _ -> "Odd"
do {1..10} |> Seq.iter(
fun x -> System.Diagnostics.Debug.WriteLine(
System.Convert.ToString(x) + " is " + Judge x))
FuzzBuzzもお試し。コードはダサいけど晒す。
let (|Fuzz|_|) i =
match i%3 with
| 0 -> Some(i)
| _ -> None
let (|Buzz|_|) i =
match i%5 with
| 0 -> Some(i)
| _ -> None
let (|FuzzBuzz|_|) i =
match i%15 with
| 0 -> Some(i)
| _ -> None
let FuzzBuzz i =
match i with
| FuzzBuzz i -> "FuzzBuzz"
| Fuzz i -> "Fuzz"
| Buzz i -> "Buzz"
| _ -> System.Convert.ToString(i)
{0..60} |> Seq.iter(fun x -> System.Diagnostics.Debug.WriteLine(FuzzBuzz x))