【发布时间】:2021-12-31 20:12:06
【问题描述】:
open System
let rec quick (cast: int list) mmm =
match mmm with
| [] -> []
| first::rest ->
let small = (rest |> List.filter (fun x -> x < first))
let large = (rest |> List.filter (fun x -> x >= first))
quick small |> ignore
quick large |> ignore
//[small @ [first] @ large]
List.concat [small; [first]; large]
[<EntryPoint>]
let main argv =
printfn "%A" (quick [3;5;6;7;8;7;5;4;3;4;5;6]);;
0
尝试在 F# 中实现一个简单的快速排序功能。 该语言相对较新,但从我所阅读的内容和我对语法的理解来看,这应该呈现一个整数列表,而是呈现一个模棱两可的“单元列表”。
为什么这给出了一个单元列表而不是一个 int 列表?
它在“%A”处出错,说类型不匹配。
【问题讨论】:
标签: sorting types functional-programming f# visual-studio-2019