B. 采用优惠制和成员限制 我无法为已知成员打上uck锁,但如果我这样界定一种通用功能的话:
let rap
带有签字b和“>”的标识;返回价值将成为实施a(即接口)并将电话转.的一个物体。
我在C#中利用反思这样做。 我不禁要问,F#的思考、引言或其他构造是否会更容易。
关于如何做到这一点的任何建议?
EDIT after reading Tims answer I thought I d give a bit more details
我在谈到利用引言帮助时所想的是:
{new IInterface with member x.SayHello() = !!<@ %expr @>}
! 经营人将报价转化为功能,从业者占该方法工作单位的百分比。 我能够将这一表述转化为一种功能(我猜测),但会不知道如何去做。
当然,这只字眼完全是这样,要么因为伊联会是我希望F#思考会有一些手法功能,这样我就能够建造一种基于某种物体和某些功能价值观的类型。
EDIT As an update to Tomas Petricek answer I ll give some code to explain my needs
type SourceRole =
abstract transfer : decimal -> context
and context(sourceAccount:account, destinationAccount) =
let source = sourceAccount
let destination = destinationAccount
member self.transfer amount =
let sourcePlayer =
{new SourceRole with
member this.transfer amount =
use scope = new TransactionScope()
let source = source.decreaseBalance amount
let destination = destination.increaseBalance amount
scope.Complete()
context(source,destination)
}
sourcePlayer.transfer(amount)
which is a try at porting "the" textbook example of DCI in F#. The source and destination are DCI roles. It s the idea that any data object that adhere s to a specific contract can play those. In this case the contract is simple. source needs a memberfunction called decreaseBalance and destination needs a member function called increaseBalance. I can accomplish that for this specific case with let inline and member constraints. But I d like to write a set of functions that given an interface and an object. In this case it could be source (as the object) and
type sourceContract =
abstract decreaseBalance : decimal -> sourceContract
类型。 其结果将是类型源背心的物体,即管道法指源物体上相同名称的方法。