Having mixed types in a list and accessing them

Hi again

I have a union type holding some record types

type OpsFlag {}
member this.State() : FlagState
type ReleaseFlag {}
member this.State(value: bool) : FlagState

type Flag =
| OpsFlag of OpsFlag
| ReleaseFlag of ReleaseFlag

Problem: How do i access the State function on each record type given that they have different signatures and that I have only a list of Flags

Now I deserialize from a json file into “flag list”.

let flags: flag list = flagsFromJson

how can i “unbox” the actual type when i get an element from that list

let f = flags.head

it returns an item of type Flag but i need the record type “OpsFlag” or whatever it is.


is there a chance to add mixed types to a list/seq


any better way of doing that?

Does this make sense?

You need to use match on each flag:

|> List.map (fun flag ->
    match flag with
    | OpsFlag f -> f.State()
    | ReleaseFlag f -> f.State(true)