タグ

関連タグで絞り込む (0)

  • 関連タグはありません

タグの絞り込みを解除

swiftとtypeに関するgrapswizのブックマーク (1)

  • Typeclass encoding in Swift

    In Swift, if we want to sum the elements of an array, we might write a function like this: func sumVecInt(xs: Array<Int>) -> Int { return xs.reduce(0) { $0 + $1 } } This works fine for Int, but what about when we want to sum an Array of Int8, Int32, or other number types? The + operator can only work on a fixed type, so using any other type will give us a type error. We would be forced to re-defin

  • 1