Skip to content

Instantly share code, notes, and snippets.

@pcantrell
Last active November 14, 2015 20:58
Show Gist options
  • Save pcantrell/446e38bb1c33559c82b1 to your computer and use it in GitHub Desktop.
Save pcantrell/446e38bb1c33559c82b1 to your computer and use it in GitHub Desktop.
protocol Tensor {
static var numberOfDims: Int { get }
}
struct NestedTensor<Element: Tensor>: Tensor {
static var numberOfDims: Int {
return 1 + Element.numberOfDims
}
// ...etc...
}
struct UnitTensor<Unit>: Tensor {
static var numberOfDims: Int {
return 0
}
// ...etc...
}
let x = NestedTensor<NestedTensor<UnitTensor<Int>>>()
x.dynamicType.numberOfDims // returns 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment