Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在F#中使用可为空的抽象类型?_F#_Nullable - Fatal编程技术网

如何在F#中使用可为空的抽象类型?

如何在F#中使用可为空的抽象类型?,f#,nullable,F#,Nullable,以下是我试图做的: and [<AbstractClass>] Figure() = let mutable name : string = "" let mutable color : ColorType = WHITE abstract member Name : string member F.Color with get() = color and set v = color <-

以下是我试图做的:

and [<AbstractClass>] Figure() =
    let mutable name : string = ""
    let mutable color : ColorType = WHITE   
    abstract member Name : string       
    member F.Color
        with get()  = color
        and set v   = color <- v
    abstract member motion : Dashboard -> SPosition -> ColorType -> list<SPosition * CellDashboard * bool>;
    override F.ToString() = name
and CellDashboard(addingFigure : Nullable<Figure>) as C =
    let mutable attacked    : bool      = false;
    let mutable cleaned     : bool      = false;
    let mutable _CellState  : Nullable<Figure> = Nullable<Figure>(addingFigure);
为什么??如何避免此错误?

可为空的
类型只能用于.NET值类型。错误消息本质上意味着编译器无法检查约束是否有效(因为类型是抽象的)

如果要用F#表示缺少的值,最好使用
选项

如果您正在编写将从C#使用的代码,那么最好避免暴露F#特定的类型(如
option
),并且可以使用
AllowNullLiteral
标记该类型,这使得可以将
null
作为类型的值传递(但是
null
是邪恶的,因此除非必要,否则不应该这样做!)

可为空的
类型只能用于.NET值类型。错误消息本质上意味着编译器无法检查约束是否有效(因为类型是抽象的)

如果要用F#表示缺少的值,最好使用
选项

如果您正在编写将从C#使用的代码,那么最好避免暴露F#特定的类型(如
option
),并且可以使用
AllowNullLiteral
标记该类型,这使得可以将
null
作为类型的值传递(但是
null
是邪恶的,因此除非必要,否则不应该这样做!)

Error   1   A generic construct requires that the type 'Figure' be non-abstract