F#间距和Mergesort [英] f# spacing and mergesort

查看:67
本文介绍了F#间距和Mergesort的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的讲师提供了此代码.我应该通过查找f#从mergesort推断出什么类型来修复它.当我尝试发送至交互式时,出现错误.我问我的校长出了什么问题,他说这是由于班级网站上的格式错误所致.我尝试添加空格以删除您命名的空格,但是每次我得到

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):错误FS0588:此"let"之后的块未完成.期待表达.

~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?

这是代码

 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)

推荐答案

我只能猜测什么是正确的缩进,但…

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)

这篇关于F#间距和Mergesort的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆