Can I determine the type of record in terms of another?

type ProcessParametersPair = {Definition:string; Provided:string}
type QueryResult = { DefinitionId:int;DefinitionName:string; ProcessTemplateId:int; StatusName:string; DefinitionArgs:string; BuildArgs:string;
    StatusCode:int option;cleanWorkspaceOption:string; RawProcessParameters:ProcessParametersPair; lastBuild:Tbl_Build}     
type QueryDisplay = { DefinitionId:int;DefinitionName:string; ProcessTemplateId:int; StatusName:Object; DefinitionArgs:string; BuildArgs:string;
    StatusCode:int option;cleanWorkspaceOption:string; RawProcessParameters:Object; lastBuild:Object}   

Do I really need to repeat all QueryDisplayRecord fields that match? Can I do something similar with record instances?type QueryDisplay = {QueryResult with lastBuild:Object}

In this case, I am changing the record based on the type of the field, I would also be interested to know if I can do this, but in the added fields instead of the fields with the changed type.

I don't mean instances, I mean record type definitions.

Are any of these options possible?

+4
source share
1 answer

A record type cannot "inherit" from another type. You can put all common fields in a separate type and refer to it:

type Common = { A: int; B: int }
type Record1 = { Common: Common; C: int }
type Record2 = { Common: Common; D: int }

Or use classes:

type Common(a, b) =
    member val A = a
    member val B = b

type Class1(a, b, c) =
    inherit Common(a, b)
    member val C = c

type Class2(a, b, d) =
    inherit Common(a, b)
    member val D = d
+10
source

Source: https://habr.com/ru/post/1543253/


All Articles