题
我的教练提供了此代码。我应该通过找到Mergesort的F#Inters来解决它。当我尝试发送到Interactive时,我会遇到错误。我问我的教授出了什么问题,他说这是由于在课堂网站上格式化错误所致。我尝试添加空间删除空间,但每次得到一个
〜VS4489.FSX(8,14):错误FS0588:遵循此“ LET”的块未完成。期待表达。
在最后两种方法上。我怎样才能解决这个问题?
这是代码
let rec merge = function
| ([], ys) -> ys
| (xs, []) -> xs
| (x::xs, y::ys) -> if x < y then x :: merge (xs, y::ys)
else y :: merge (x::xs, ys)
let rec split = function
| [] -> ([], [])
| [a] -> ([a], [])
| a::b::cs -> let (M,N) = split cs
(a::M, b::N)
let rec mergesort = function
| [] -> []
| L -> let (M, N) = split L
merge (mergesort M, mergesort N)
解决方案
我只能 猜测 至于正确的凹痕是什么,但是…
let rec merge = function
| ([], ys) -> ys
| (xs, []) -> xs
| (x::xs, y::ys) -> if x < y then x :: merge (xs, y::ys)
else y :: merge (x::xs, ys)
let rec split = function
| [] -> ([], [])
| [a] -> ([a], [])
| a::b::cs -> let (M,N) = split cs
(a::M, b::N)
let rec mergesort = function
| [] -> []
| L -> let (M, N) = split L
merge (mergesort M, mergesort N)
不隶属于 StackOverflow