小编dav*_*tme的帖子

跨类型共享功能

如果f#接受了在关系数据库中排序的数据,然后将其转换为可用于第三方平台的星型模式,我们将编写一个etl流程。因为我们正在对数据进行非规范化,所以我们(几乎)有重复的对象,类型和属性分散在系统中。到目前为止,我一直对此感到满意,因为对象的差异足以保证不同的功能,或者我们已经能够将公共/共享属性分组到子记录中。

但是,我们现在添加的对象需要选择和选择系统的不同部分,并且不属于现有的常规分组。在尝试了几种不同的样式之后,我开始使用接口,但是使用它们并不适合。有谁遇到过这个问题并提出了不同的方法?

module rec MyModels =
    type AccountType1 =
        { Id : int
          Error : string option 
          Name : string option }
        // PROBLEM: this get very bulky as more properties are shared
        interface Props.Error<AccountType1> with member x.Optic = (fun _ -> x.Error), (fun v -> { x with Error = v })
        interface Props.AccountId<AccountType1> with member x.Optic = (fun _ -> x.Id), (fun v -> { x with Id = v })
        interface Props.AccountName<AccountType1> with member x.Optic = (fun …
Run Code Online (Sandbox Code Playgroud)

f# types record

4
推荐指数
1
解决办法
1282
查看次数

标签 统计

f# ×1

record ×1

types ×1