This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Bit {} | |
protocol IsSet {} | |
protocol IsClr {} | |
struct Set : Bit, IsSet {} | |
struct Clr : Bit, IsClr {} | |
protocol NandOp { typealias Result } | |
extension NandOp { typealias Result = Set } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (Xcode 7.1 beta 2) | |
// Background: | |
// I wanted to replace these two overloads with a generic function/method (working for Float and Double): | |
// func oldRemoveSrgbGamma(v: Float) -> Float { | |
// return (v <= 0.04045) ? v * (1.0 / 12.92) : pow((v + 0.055) * (1.0 / (1.0 + 0.055)), 2.4) | |
// } | |
// func oldRemoveSrgbGamma(v: Double) -> Double { | |
// return (v <= 0.04045) ? v * (1.0 / 12.92) : pow((v + 0.055) * (1.0 / (1.0 + 0.055)), 2.4) | |
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct SA<T> { | |
let v: T | |
init(_ v: T) { self.v = v } | |
} | |
typealias SB = SA<(Int, Int)> | |
typealias SC = SA<W> | |
typealias W = (Int, Int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------ | |
// The following compiles and works, but see comments for 2 compiler crashers. | |
//------------------------------------------------------------------------------ | |
protocol DefaultInitializable { init() } | |
extension Int: DefaultInitializable {} | |
// Hople = Homogeneous tuple / static array implemented using recursive structs. | |
protocol HopleType : DefaultInitializable { | |
typealias Element: DefaultInitializable | |
subscript(index: Int) -> Element { get set } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct True {} | |
struct False {} | |
protocol ResultPossessingType {} | |
extension ResultPossessingType { typealias Result = False } | |
struct IsIntegerType<T> : ResultPossessingType { | |
static func printResult() { print("Static method prints \(self).Result:", Result.self, self.Result.self) } // <-- Added self.Result.self | |
} | |
extension IsIntegerType where T: IntegerType { | |
typealias Result = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I'm using the concept of bits just to make the code a bit more concrete. | |
// The actual use case has nothing to do with implementing type level bits ... | |
// This code compiles and runs as is, but note the last line. | |
// Q: Should this program compile without errors? If so, what should the last line print? | |
protocol BitType {} | |
struct Clr : BitType {} | |
struct Set : BitType {} | |
protocol BitAndOp { | |
typealias A: BitType = Clr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This little program takes ~ 6 seconds to compile on my MacBook Pro Late 2013. | |
// It compiles and works as expected. But the type checker spends a lot of time | |
// on the function at the end. | |
// In my actual project, I have much more code like this, and it results in very | |
// long compile times. So I'd like to know if there is something I can do to | |
// speed that up. | |
protocol DefaultInitializable { init() } | |
extension Float : DefaultInitializable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//---------------------------------------------------------------------------------------------------- | |
// This program compiles and runs. Question: Can generic struct X be made to satisfy TEST? | |
//---------------------------------------------------------------------------------------------------- | |
protocol DefaultInitializable { init() } | |
extension Double : DefaultInitializable {} | |
extension Float : DefaultInitializable {} | |
extension Int : DefaultInitializable {} | |
extension UInt8 : DefaultInitializable {} | |
// ... | |
protocol CountType { static var value: Int { get } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================== | |
// This program is possibly demonstrating an issue/opportunity for improvement | |
// of the optimizer. | |
// (Tested with Xcode 7.2 beta 4, OS X 10.10.5, Macbook Pro late 2013) | |
// (Compiled (-O -gnone) as command line app) | |
//============================================================================== | |
// | |
// There is a test at the end which measures the time it takes to do some | |
// matrix (and vector) type operations. | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol DefaultInitializable { init() } | |
protocol StaticStorageType : DefaultInitializable { | |
typealias Element: DefaultInitializable = Self | |
static var staticCount: Int { get } | |
} | |
extension StaticStorageType { | |
typealias Plus1 = StaticStorageOfOneMoreThan<Self> | |
typealias Plus2 = Plus1.Plus1 | |
typealias Plus3 = Plus2.Plus1 | |
typealias Times2 = StaticStorageDoubled<Self> |
OlderNewer