Q:

How to store a generic closure?

I'm trying to create a type erased type using a closure in Swift 3 but I can't figure out how to store the closure in a property. How can I store the closure for later use? See the code below:
protocol ProtocolA {
    associatedtype AssociatedType
}

protocol ProtocolB {
    associatedtype AssociatedType
    func fn<A: ProtocolA>(a: A) where A.AssociatedType == AssociatedType
}

class AnyProtocolB<T>: ProtocolB {
    typealias AssociatedType = T

    init<A: ProtocolA>(fn: @escaping (A) -> Void)  where A.AssociatedType == AssociatedType {
        _fn = fn
    }

    func fn<A: ProtocolA>(a: A) where A.AssociatedType == AssociatedType {
        _fn(a)
    }

    let _fn: (A) -> Void // how to declare this so it will compile?
}

As a side note, I was able to do this in Swift 2 by declaring it like this:
let _fn: (AnyProtocolA<AssociatedType>) -> Void

But the above doesn't work in Swift 3 (it crashes the compiler.)

A:

It looks like this works:
protocol ProtocolA {
    associatedtype AssociatedType
}

class AnyProtocolA<T>: ProtocolA {
    typealias AssociatedType = T

    init<A: ProtocolA>(_ a: A) where AssociatedType == A.AssociatedType {

    }
}

protocol ProtocolB {
    associatedtype AssociatedType
    func fn<A: ProtocolA>(a: A) where A.AssociatedType == AssociatedType
}

class AnyProtocolB<T>: ProtocolB {
    typealias AssociatedType = T

    init<A: ProtocolA>(fn: @escaping (A) -> Void)  where A.AssociatedType == AssociatedType {
        _fn = { fn(wrap($0)) }
    }

    func fn<A: ProtocolA>(a: A) where A.AssociatedType == AssociatedType {
        _fn(AnyProtocolA(a))
    }

    let _fn: (AnyProtocolA<T>) -> Void
}

func wrap<A: ProtocolA, T>(_ a: AnyProtocolA<T>) -> A where A.AssociatedType == T {
    return a as! A
}

