You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For Swift, generics can't be decoded without the type variable implementing Decodable. For example:
importData.Tree
mobileGen ''Tree
Currently this produces:
/// Non-empty, possibly infinite, multi-way trees; also known as *rose trees*.
structTree<A>{
/// label value
varrootLabel:A
/// zero or more child trees
varsubForest:[Tree<A>]}
At compile time, the Swift program can pass a type to use when decoding subForest like so:
tree.map(Tree<String>.self)
The problem, though, is that A needs to be annotated with the Decodable protocol for this to work, like struct Tree<A : Decodable>. To do this, we can pass structTyVars = ["A : Decodable"], but this won't work in Kotlin.
If tyvars were modeled with type names and bounds, then we could implement this separately for Swift and Kotlin.
I think we want the same conformance as our other types get (Equatable, Hashable, Codable) - though, I'm not sure what decides that. But this would look like this:
struct GenericType<A: Equatable & Hashable & Codable>: Equatable, Hashable, Codable {
var genericProperty: A
}
@kylebshr Look at the rose tree tyvar unfolding code. That might be helpful here. Actually, nvm, we can probably just do some simple constraint synthesis. If we add Codable et al to a type, we need to demand that its type variables all have that, too. So I don't think this change would actually be that complicated - just a pretty printer change.
For Swift, generics can't be decoded without the type variable implementing
Decodable
. For example:Currently this produces:
At compile time, the Swift program can pass a type to use when decoding
subForest
like so:The problem, though, is that
A
needs to be annotated with theDecodable
protocol for this to work, likestruct Tree<A : Decodable>
. To do this, we can passstructTyVars = ["A : Decodable"]
, but this won't work in Kotlin.If tyvars were modeled with type names and bounds, then we could implement this separately for Swift and Kotlin.
Related: #13
The text was updated successfully, but these errors were encountered: