Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I define a record type in terms of another?

Tags:

f#

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 have to repeat all fields of the QueryDisplayRecord that match? Can I do something like you can do with record instances? type QueryDisplay = {QueryResult with lastBuild:Object}

In this case I'm varying record based on a field type, I'd also love to know if I can do this but on added fields instead of type changed fields.

I am not referring to instances, I'm referring to Record type definitions.

Are either of these possible?

like image 914
Maslow Avatar asked Dec 25 '22 08:12

Maslow


1 Answers

A record type cannot "inherit" from another type. You could put all the common fields in a separate type and reference 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
like image 104
Daniel Avatar answered Jan 02 '23 10:01

Daniel