let getLogicalWithDoubleLevelElement<'E when 'E :> DoubleLevelElement>
(logicalModifier : InletPosition * OutletPosition -> Logical)
(logical : Logical) =
我需要logicalModifier
为泛型函数,其类型与getLogicalWithDoubleLevelElement
类型相同。
如何定义?
答案 0 :(得分:1)
如果需要将显式多态函数作为参数传递,那么在F#中执行此操作的唯一方法是使用具有泛型方法的新类型:
type LogicalModifier =
abstract MakeLogical<'E when 'E :> DoubleLevelElement> : InletPosition * OutletPosition -> Logical
let getLogicalWithDoubleLevelElement<'E when 'E :> DoubleLevelElement>
(logicalModifier : LogicalModifier)
(logical : Logical) = ... logicalModifier.MakeLogical<'E> ...