This commit is contained in:
Sanchime 2022-02-26 13:51:01 +08:00
parent 80614a0a3b
commit 12cce6d8b4
1 changed files with 48 additions and 3 deletions

View File

@ -10,6 +10,8 @@ match 1 with
| 3 -> printfn "3"
| _ -> printfn ""
// 线,
//
match "one" with
| "one" -> printfn "one"
@ -18,16 +20,59 @@ match "one" with
type Shape = Square | Circular
//
//
//
match Square with
| Square -> printfn"Square"
| Circular -> printfn"Circular"
| Square -> printfn "Square"
| Circular -> printfn "Circular"
//
//
type UserInfo = { Name: string; Email: string }
let user = { Name = "小明"; Email = "xxx@xxx.com" }
match user with
| { Name = name; Email = email } as user when name = "小明" -> printfn "%A" user
| _ -> printfn "%A" user
//
match 1 with
| 1 | 2 | 3 -> printfn "123"
| _ -> printfn""
//
match [1] with
| [] -> printfn ""
| [_] -> printfn ""
| [_; _] -> printfn ""
| _ -> printfn ""
//
match [|1; 2|] with
| [||] -> printfn ""
| [|_|] -> printfn ""
| [|_; _|] -> printfn ""
| _ -> printfn ""
//
match (0, 1) with
| (0, 0) -> printfn "(0, 0)"
| (0, 1) -> printfn "(0, 1)"
| _ -> printfn ""
// as
match "111" with
| "111" as s -> printfn "字符串:%s" s
| _ -> printfn ""
//
// 变量模式 +
match 5 with
| n when n < 2 -> printfn "%d小于2" n
| n when n < 6 -> printfn "%d小于6" n
| n -> printfn "%d不满足上述匹配" n
// cons
let rec sum_of_list list =
match list with