f# spacing and mergesort

…衆ロ難τιáo~ 提交于 2019-12-11 05:36:25

问题


I have this code provided by my instructor. I am supposed to fix it by finding what type f# infers from mergesort. When I try to send to interactive i get an error . I asked my proffesor what was wrong and he said that it was due to formatting errors on the class website. I have tried adding spaces removing spaces you name it but every time i get a

~vs4489.fsx(8,14): error FS0588: Block following this 'let' is unfinished. Expect an expression.

on the last two methods. How can I fix this?

Here is the code

 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)

回答1:


I can only guess as to what the correct indentation is, but …

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)


来源:https://stackoverflow.com/questions/9303740/f-spacing-and-mergesort

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!