Generics 使用类型别名在Swift中为通用协议编写函数

Generics 使用类型别名在Swift中为通用协议编写函数,generics,swift,functional-programming,type-constraints,type-alias,Generics,Swift,Functional Programming,Type Constraints,Type Alias,我正在使用库中的一些代码,试图为向量编写一个泛型函数。这是我的协议 //Inherits from Functor in the basis library public protocol Vector: Functor { typealias VB = FB typealias C typealias VC = K1<C> class func foldl(B) -> ((A, B) -> B) -> Self -> B

我正在使用库中的一些代码,试图为向量编写一个泛型函数。这是我的协议

//Inherits from Functor in the basis library
public protocol Vector: Functor {
    typealias VB = FB
    typealias C
    typealias VC = K1<C>

    class func foldl(B) -> ((A, B) -> B) -> Self -> B
    class func zipWith((A, B) -> C) -> Self -> VB -> VC
}
//从基库中的Functor继承
公共协议向量:函子{
typealias VB=FB
别名C
typealias VC=K1
类func foldl(B)->((A,B)->B)->Self->B
使用((A,B)->C)->Self->VB->VC来初始化函数
}
我有一个向量2函数的具体实现

我想定义几个通用函数,因为协议有fmap、foldl和zipWith。然而,我似乎无法写出像这样编译的东西

//This is basically just an identity
func trailFunction<A, V: Vector where V.A == A, V.B == A, V.FB == V>(v: V) -> V {
    let f = V.fmap({$0})
    return f(v)

}

//Fails with B is not identical to Int error
func testFunction(v: Vector2<Int>) -> Vector2<Int> {
    return trailFunction(v)
}
//这基本上只是一个身份
函数跟踪函数(v:v)->v{
设f=V.fmap({$0})
返回f(v)
}
//B与Int error不相同时失败
func testFunction(v:Vector2)->Vector2{
返回跟踪功能(v)
}
我做错了什么