Modeling multiple levels of inheritance using discriminated associations

Is there a recommended way to simulate multiple levels of inheritance in F #, presumably using a discriminated union?

Something like the following in C #:

class Expr { }
class SourceExpr : Expr { }
class JoinExpr : SourceExpr { }
class TableExpr : SourceExpr { }

I did this in F #:

type SourceExpr =
    | Join of JoinExpr
    | Table of TableExpr

type Expr = 
    | Source of SourceExpr
    | ...

Is there a better way? Does this have the same polymorphic behavior as inheritance?

+5
source share
2 answers

. , , (DU). / - , "", DU "". , ( ) . , DU (, ), () , , ( " ".)

, DU, ; , , . , , ; (), , (Draw, Resize,...), .

+8

F # , #.... ... , .

, , , , , , .

, F # #... UNLESS.... .

- ... .

... .... , .... .

0

All Articles