1

Here is what am I trying to do :

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);

the trouble is :

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

why ? And how can I avoid this error ?

cnd
  • 32,616
  • 62
  • 183
  • 313

1 Answers1

5

The Nullable<T> type can only be used for .NET value types. The error message essentially means that the compiler cannot check whether the constraint holds or not (because the type is abstract).

If you want to represent missing value in F#, it is better to use option<T> instead.

If you're writing code that will be used from C#, then it is better to avoid exposing F#-specific types (like option<T>) and you can mark the type with AllowNullLiteral, which makes it possible to pass null as a value of the type (but null is evil, so this shouldn't be done unless necessary!)

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553