小编Luk*_*uke的帖子

这个表达式预计有'unit'类型,但这里有''a []'类型

下面的代码试图在F#中进行递归冒泡排序,我收到了错误

"This expression was expected to have type 'unit' but here has type ''a []'"

对于中间三行:

let swap i j (arr : 'a []) =
    let tmp = arr.[i]
    arr.[i] <- arr.[j]
    arr.[j] <- tmp

let rec recursiveBubbleSort i j (sequence : 'a []) =
    if i = sequence.Length then sequence //error
    elif j = sequence.Length then recursiveBubbleSort (i+1) 0 sequence //error
    elif sequence.[i] > sequence.[j] then swap i j sequence //error
    recursiveBubbleSort i (j+1) sequence
Run Code Online (Sandbox Code Playgroud)

这真让我感到困惑,因为我发现的所有资源都没有充分解释或暗示为什么会发生这种情况.任何帮助都会有很大的帮助.

f#

3
推荐指数
1
解决办法
444
查看次数

在调用对象的 ContainsKey 后字典抛出 StackOverflowException

以下代码是大量面向对象的 C# 脚本的一部分,在那里我收到了错误:

An unhandled exception of type 'System.StackOverflowException' occurred in script.exe
Run Code Online (Sandbox Code Playgroud)

我发现这特别奇怪,因为我找不到任何可能与我的程序逻辑中无限发生的某种形式的过程有关的任何东西。

它会一直发生作为operator !=我为 Coordinates 类制作的一部分,每当它被用作Dictionary.ContainsKey()应该返回的a 的参数时true

这是坐标类:

class Coordinate
{
    private int _x;
    private int _y;
    public int X
    {
        get
        {
            return _x;
        }
    }
    public int Y
    {
        get
        {
            return _y;
        }
    }

    public Coordinate(Random r)
    {
        this._x = r.Next(79);
        this._y = r.Next(24);
    }

    public Coordinate(int x, int y)
    {
        this._x = x;
        this._y = y;
    }

    public static …
Run Code Online (Sandbox Code Playgroud)

c# stack-overflow dictionary class

2
推荐指数
1
解决办法
807
查看次数

标签 统计

c# ×1

class ×1

dictionary ×1

f# ×1

stack-overflow ×1