The standard OO way of doing this would be
Public MustInherit Class HTML
Public Tag as String
End Class
Public Class B
Inherits HTML
Public Content as String
End Class
Public Class R
Inherits HTML
Public HTML as HTML
End Class
This isn't the same as the Haskell datatype. Besides possibly being null
, someone could define another class that's neither B
nor R
Public Class TrickedYou
Inherits HTML
End Class
There's another way to express sum types in .Net that matches Haskell's sum types up to null
s. It uses generics and is fairly alien to OO programming; the closest OO design pattern is a visitor, which almost gets a sum type right. The visitor OO pattern doesn't get the generic return type right.