Sounds to me like you describe a typical inheritance relationship, i.e. "Label IS-A Control". In this case, you should really consider using class types. GUI programming is often considered a strength of object-oriented programming.

That said, if you really absolutely want to use records here, you could make it work with interfaces:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Marker interface for controls
type IControl = interface end

type Control =
   { ID: string; SkinID: string; Controls: seq<IControl> }
   interface IControl

type ILabel = 
  inherit IControl

type Label =
   { Text: string }
   interface ILabel

let label = { Text="hello" }
let nestedControl = { ID="2"; SkinID="3"; Controls=[] }

let control = { ID="1"; SkinID="2"; Controls=[label; nestedControl]}

On the other hand, I'm not sure whether custom interfaces for records are officially part of the language. It says on MSDN:

"Records are basically simple aggregates of values, without separate constructors that can perform custom actions, without hidden fields, and without inheritance or interface implementations." ( [link:msdn.microsoft.com] )

By on 3/29/2011 8:57 AM ()

The answer helped me well, thanks!

By on 4/10/2011 12:47 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper