Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let add x y = x + y
let square x = x * x
let negete x = x * -1
let triple x = x * x * x
let print (x : Object) = Console.WriteLine(x);
let multilineString = @"This is \\hoge
multiline string"
let dump x = x.Dump(); x // let inline dump x = x.Dump; x にするとコンパイル時に利用している型の分だけ関数が生成される (なんちゃってジェネリクス代わりにはなりそう
let dumpTitle (x : string) y = y.Dump(x); y
let titleDump = dumpTitle "れんしゅー"
square 42 |> negete |> triple |> dump |> square |> print
let hello = "Hello" + "World" |> dump
hello |> dumpTitle "文字列"
hello |> titleDump
// Lists use square brackets and `;` delimiter
let list1 = [ "a"; "b" ]
// :: is prepending
let list2 = "c" :: list1
// @ is concat
let list3 = list1 @ list2
list1 |> dump
list2 |> dump
list3 |> dump
let intList = [1..3..20] |> dump
[
yield 1
yield 2
yield! intList
] |> dump
List.map square [0..10] |> dumpTitle "まっぷ"
List.map (fun x -> x*x) [0..10] |> dumpTitle "まっぷ2"
[0..10] |> List.map square |> dumpTitle "まっぷ3"
[ for x in 0..10 -> square x ] |> dumpTitle "リスト内包表記"
let z = add 6 10 |> dump
z = 5 |> dump
sprintf "Hello %s! Number is %d" "world" 42 |> dump
sprintf "Hello %s! Number is %d. %s" "world" 42 "hoge" |> dump
let nums = [ 1 .. 10 ]
let formatted = nums |> List.map (sprintf "number %d") |> dump
let str1 = "hoge"
printfn "%s" (str1.[0..2])
printfn "First character: %c" (str1.Chars(0))
printfn "%c" (str1.[0])
printfn "%A" list1
let f x = 2*x*x - 5*x + 3
f 6 + 4 |> dump
f (6 + 4) |> dump
let rec factorial n = if n=0 then 1 else n * factorial (n-1)
factorial 5 |> dump
let rec fibonacc n = if n=0 then 0 elif n=1 then 1 else fibonacc(n-1) + fibonacc(n-2);
fibonacc 7 |> dump
let rec fib n =
match n with
| 0 -> 0
| 1 -> 1
| n -> fib(n-1) + fib(n-2)
fib 7 |> dump
let tuple = (1, "person", "Joeh doe")
tuple |> dump
let hoge tuple1 =
match tuple1 with
| (no, kind, name) -> sprintf "No : %A, Kind : %A, Name : %A" no kind name
hoge tuple |> dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.