Skip to content

Commit 9fb62c3

Browse files
committed
Port to Swift 3.1 + PackageManager
Needed to remove the associated types (and refactor the Modules) because of an update to Swift that requires operators inside of protocols have at least one argument of type Self.
1 parent 549e02d commit 9fb62c3

File tree

20 files changed

+312
-161
lines changed

20 files changed

+312
-161
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ DerivedData
2020
*.xcscmblueprint
2121
Carthage/
2222

23+
# SwiftPM
24+
.build/
25+
2326
# CocoaPods
2427
#
2528
# We recommend against adding the Pods directory to your .gitignore. However

.swift-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.1

.travis.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,28 @@ matrix:
55
include:
66
- os: osx
77
language: objective-c
8-
osx_image: xcode7.3
8+
osx_image: xcode8.3
99
before_install:
1010
- git submodule update --init --recursive
1111
script:
12-
# Restore pod build before shipping for 3.0
12+
# Restore pod build before shipping for 3.0
1313
# - pod lib lint
14+
# Generate xcodeprojects for the pure Swift PM deps
15+
- (cd Carthage/Checkouts/Operadics && xcrun swift package generate-xcodeproj --xcconfig-overrides ../../../deployments.xcconfig)
1416
- carthage build --no-skip-current
1517
- os: osx
1618
language: objective-c
17-
osx_image: xcode7.3
19+
osx_image: xcode8.3
1820
before_install:
21+
# Generate xcodeprojects for the pure Swift PM deps
22+
- (cd Carthage/Checkouts/Operadics && xcrun swift package generate-xcodeproj --xcconfig-overrides ../../../deployments.xcconfig)
1923
- git submodule update --init --recursive
2024
script:
2125
- set -o pipefail
2226
- xcodebuild test -scheme Algebra | xcpretty -c
2327
# !!!: Make sure desired device name & OS version are suitable for the Xcode version installed on osx_image
24-
- iOS_DEVICE_NAME="iPad Pro"
25-
- iOS_RUNTIME_VERSION="9.3"
28+
- iOS_DEVICE_NAME="iPad Air"
29+
- iOS_RUNTIME_VERSION="10.3"
2630
# Get simulator identifier for desired device/runtime pair
2731
- SIMULATOR_ID=$(xcrun instruments -s | grep -o "${iOS_DEVICE_NAME} (${iOS_RUNTIME_VERSION}) \[.*\]" | grep -o "\[.*\]" | sed "s/^\[\(.*\)\]$/\1/")
2832
- echo $SIMULATOR_ID
@@ -36,13 +40,11 @@ matrix:
3640
dist: trusty
3741
before_install:
3842
- git submodule update --init --recursive
39-
- wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
40-
- wget https://swift.org/builds/swift-2.2.1-release/ubuntu1404/swift-2.2.1-RELEASE/swift-2.2.1-RELEASE-ubuntu14.04.tar.gz
41-
- tar xzf swift-2.2.1-RELEASE-ubuntu14.04.tar.gz
42-
- export PATH=${PWD}/swift-2.2.1-RELEASE-ubuntu14.04/usr/bin:"${PATH}"
43+
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
44+
- rm -rf Carthage
4345
script:
44-
# Uncomment when releasing Swift 3.0
45-
# - swift build
46+
- swift build
47+
- SWIFTPM_TEST_Algebra=YES swift test
4648
notifications:
4749
webhooks:
4850
urls:

Algebra.xcodeproj/project.pbxproj

Lines changed: 155 additions & 38 deletions
Large diffs are not rendered by default.

Algebra.xcodeproj/project.xcworkspace/xcshareddata/Algebra.xcscmblueprint

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,32 @@
44

55
},
66
"DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
7-
"53964F28C4CCA0826677C9F951DD3F64C20326C4" : 0,
8-
"570C4D95BE80B5E8C6FFC0BED8318BC62404E6A6" : 0,
9-
"B1566CF92CFABA5E37554B7B555A1BA50691C03A" : 0
7+
"53964F28C4CCA0826677C9F951DD3F64C20326C4" : 9223372036854775807,
8+
"570C4D95BE80B5E8C6FFC0BED8318BC62404E6A6" : 9223372036854775807,
9+
"B1566CF92CFABA5E37554B7B555A1BA50691C03A" : 9223372036854775807
1010
},
11-
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "7463F262-5386-4D27-88FC-7EDEE3B15B7F",
11+
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "B9716910-90F7-4DC2-BC98-DD5F4D526F33",
1212
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
13-
"53964F28C4CCA0826677C9F951DD3F64C20326C4" : "Algebra\/Carthage\/Checkouts\/SwiftCheck\/",
13+
"53964F28C4CCA0826677C9F951DD3F64C20326C4" : "Algebra\/.build\/checkouts\/SwiftCheck.git--4306398712468813520\/",
1414
"570C4D95BE80B5E8C6FFC0BED8318BC62404E6A6" : "Algebra\/",
15-
"B1566CF92CFABA5E37554B7B555A1BA50691C03A" : "Algebra\/Carthage\/Checkouts\/SwiftCheck\/Carthage\/Checkouts\/Operadics\/"
15+
"B1566CF92CFABA5E37554B7B555A1BA50691C03A" : "Algebra\/Carthage\/Checkouts\/Operadics\/"
1616
},
1717
"DVTSourceControlWorkspaceBlueprintNameKey" : "Algebra",
18-
"DVTSourceControlWorkspaceBlueprintVersion" : 203,
18+
"DVTSourceControlWorkspaceBlueprintVersion" : 204,
1919
"DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "Algebra.xcodeproj",
2020
"DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [
2121
{
22-
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/typelift\/SwiftCheck.git",
22+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "\/Users\/bkase\/Algebra\/.build\/repositories\/SwiftCheck.git--4306398712468813520",
2323
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
2424
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "53964F28C4CCA0826677C9F951DD3F64C20326C4"
2525
},
2626
{
27-
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/CodaFi\/Algebra.git",
27+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:bkase\/Algebra.git",
2828
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
2929
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "570C4D95BE80B5E8C6FFC0BED8318BC62404E6A6"
3030
},
3131
{
32-
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/typelift\/Operadics.git",
32+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "\/Users\/bkase\/Algebra\/.build\/repositories\/Operadics.git-5626071303828032414",
3333
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
3434
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "B1566CF92CFABA5E37554B7B555A1BA50691C03A"
3535
}

Algebra/AlgebraOperators.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
// Copyright (c) 2014 TypeLift. All rights reserved.
77
//
88

9-
infix operator *<> { }
10-
infix operator <>* { }
9+
// TODO: Uncomment these operators when we figure out a way to use them with Modules
10+
// infix operator *<>
11+
// infix operator <>*

Algebra/Group.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
///
1212
/// a <> b = b <> a = e
1313
protocol Group : Additive {
14-
static func invert(_ : M) -> M
14+
static func invert(_ : Self) -> Self
1515
}
1616

1717
/// An Abelian Group is a group where the binary operation is commutative. That is forall 'a', 'b',
@@ -21,19 +21,19 @@ protocol Group : Additive {
2121
protocol AbelianGroup : Group { }
2222

2323
extension Int : Group {
24-
static func invert(l : Int) -> Int { return -l }
24+
static func invert(_ l : Int) -> Int { return -l }
2525
}
2626
extension Int8 : Group {
27-
static func invert(l : Int8) -> Int8 { return -l }
27+
static func invert(_ l : Int8) -> Int8 { return -l }
2828
}
2929
extension Int16 : Group {
30-
static func invert(l : Int16) -> Int16 { return -l }
30+
static func invert(_ l : Int16) -> Int16 { return -l }
3131
}
3232
extension Int32 : Group {
33-
static func invert(l : Int32) -> Int32 { return -l }
33+
static func invert(_ l : Int32) -> Int32 { return -l }
3434
}
3535
extension Int64 : Group {
36-
static func invert(l : Int64) -> Int64 { return -l }
36+
static func invert(_ l : Int64) -> Int64 { return -l }
3737
}
3838

3939
extension Int : AbelianGroup { }

Algebra/Lattice.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
/// operation that computes the least upper bound).
1111
protocol JoinSemilattice {
1212
associatedtype L
13-
static func join(_ : L) -> L -> L
13+
static func join(_ : L) -> (L) -> L
1414
}
1515

1616
/// A Meet-Semilattice is a partially ordered set that defines a meet operation (that is, has an
1717
/// operation that computes the greatest lower bound).
1818
protocol MeetSemilattice {
1919
associatedtype L
20-
static func meet(_ : L) -> L -> L
20+
static func meet(_ : L) -> (L) -> L
2121
}
2222

2323
/// A Lattice is a partially ordered set that defines both a meet and join operation.
@@ -41,13 +41,13 @@ protocol BoundedLattice : BoundedJoinSemilattice, BoundedMeetSemilattice { }
4141

4242
extension Bool : JoinSemilattice {
4343
typealias L = Bool
44-
public static func join(l : Bool) -> Bool -> Bool {
44+
public static func join(_ l : Bool) -> (Bool) -> Bool {
4545
return { r in l || r }
4646
}
4747
}
4848

4949
extension Bool : MeetSemilattice {
50-
public static func meet(l : Bool) -> Bool -> Bool {
50+
public static func meet(_ l : Bool) -> (Bool) -> Bool {
5151
return { r in l && r }
5252
}
5353
}

Algebra/Magma.swift

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,62 @@
66
// Copyright (c) 2014 TypeLift. All rights reserved.
77
//
88

9+
import Operadics
10+
911
/// A magma is a set and a closed binary operator. It is usually not studied because it forms the
1012
/// basis of more interesting structures.
1113
protocol Magma {
12-
associatedtype M
13-
func <>(_ : M, _ : M) -> M
14+
static func <>(_ : Self, _ : Self) -> Self
1415
}
1516

16-
extension Bool : Magma { typealias M = Bool }
17-
public func <>(l : Bool, r : Bool) -> Bool { return l || r }
17+
extension Bool : Magma {
18+
public static func <>(l : Bool, r : Bool) -> Bool { return l || r }
19+
}
1820

19-
extension UInt : Magma { typealias M = UInt }
20-
public func <>(l : UInt, r : UInt) -> UInt { return l &+ r }
21+
extension UInt : Magma {
22+
public static func <>(l : UInt, r : UInt) -> UInt { return l &+ r }
23+
}
2124

22-
extension UInt8 : Magma { typealias M = UInt8 }
23-
public func <>(l : UInt8, r : UInt8) -> UInt8 { return l &+ r }
25+
extension UInt8 : Magma {
26+
public static func <>(l : UInt8, r : UInt8) -> UInt8 { return l &+ r }
27+
}
2428

25-
extension UInt16 : Magma { typealias M = UInt16 }
26-
public func <>(l : UInt16, r : UInt16) -> UInt16 { return l &+ r }
29+
extension UInt16 : Magma {
30+
public static func <>(l : UInt16, r : UInt16) -> UInt16 { return l &+ r }
31+
}
2732

28-
extension UInt32 : Magma { typealias M = UInt32 }
29-
public func <>(l : UInt32, r : UInt32) -> UInt32 { return l &+ r }
33+
extension UInt32 : Magma {
34+
public static func <>(l : UInt32, r : UInt32) -> UInt32 { return l &+ r }
35+
}
3036

31-
extension UInt64 : Magma { typealias M = UInt64 }
32-
public func <>(l : UInt64, r : UInt64) -> UInt64 { return l &+ r }
37+
extension UInt64 : Magma {
38+
public static func <>(l : UInt64, r : UInt64) -> UInt64 { return l &+ r }
39+
}
3340

34-
extension Int : Magma { typealias M = Int }
35-
public func <>(l : Int, r : Int) -> Int { return l &+ r }
41+
extension Int : Magma {
42+
public static func <>(l : Int, r : Int) -> Int { return l &+ r }
43+
}
3644

37-
extension Int8 : Magma { typealias M = Int8 }
38-
public func <>(l : Int8, r : Int8) -> Int8 { return l &+ r }
45+
extension Int8 : Magma {
46+
public static func <>(l : Int8, r : Int8) -> Int8 { return l &+ r }
47+
}
3948

40-
extension Int16 : Magma { typealias M = Int16 }
41-
public func <>(l : Int16, r : Int16) -> Int16 { return l &+ r }
49+
extension Int16 : Magma {
50+
public static func <>(l : Int16, r : Int16) -> Int16 { return l &+ r }
51+
}
4252

43-
extension Int32 : Magma { typealias M = Int32 }
44-
public func <>(l : Int32, r : Int32) -> Int32 { return l &+ r }
53+
extension Int32 : Magma {
54+
public static func <>(l : Int32, r : Int32) -> Int32 { return l &+ r }
55+
}
4556

46-
extension Int64 : Magma { typealias M = Int64 }
47-
public func <>(l : Int64, r : Int64) -> Int64 { return l &+ r }
57+
extension Int64 : Magma {
58+
public static func <>(l : Int64, r : Int64) -> Int64 { return l &+ r }
59+
}
4860

49-
extension Float : Magma { typealias M = Float }
50-
public func <>(l : Float, r : Float) -> Float { return l + r }
61+
extension Float : Magma {
62+
public static func <>(l : Float, r : Float) -> Float { return l + r }
63+
}
5164

52-
extension Double : Magma { typealias M = Double }
53-
public func <>(l : Double, r : Double) -> Double { return l + r }
65+
extension Double : Magma {
66+
public static func <>(l : Double, r : Double) -> Double { return l + r }
67+
}

Algebra/Module.swift

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,38 @@
77
//
88

99
/// If R is a Ring and M is an abelian group, a Left Module defines a binary operation R *<> M -> M.
10-
protocol LeftModule {
11-
associatedtype R : Semiring
12-
associatedtype A : Additive
13-
func *<>(_ : R, _ : A) -> A
10+
struct LeftModule<R: Semiring, A: Additive> {
11+
let multiply: (R, A) -> A
12+
}
13+
enum LeftModules {
14+
static let int = LeftModule<Int, Int>(multiply: *)
15+
static let int8 = LeftModule<Int, Int8>(multiply: { Int8($0) * $1 })
16+
static let int16 = LeftModule<Int, Int16>(multiply: { Int16($0) * $1 })
17+
static let int32 = LeftModule<Int, Int32>(multiply: { Int32($0) * $1 })
18+
static let int64 = LeftModule<Int, Int64>(multiply: { Int64($0) * $1 })
1419
}
1520

1621
/// If R is a Ring and M is an abelian group, a Right Module defines a binary operation M <>* R -> M.
17-
protocol RightModule {
18-
associatedtype R : Semiring
19-
associatedtype M : Additive
20-
func <>* (_ : M, _ : R) -> M
22+
struct RightModule<A: Additive, R: Semiring> {
23+
let multiply: (A, R) -> A
24+
}
25+
enum RightModules {
26+
static let int = RightModule<Int, Int>(multiply: *)
27+
static let int8 = RightModule<Int8, Int>(multiply: { $0 * Int8($1) })
28+
static let int16 = RightModule<Int16, Int>(multiply: { $0 * Int16($1) })
29+
static let int32 = RightModule<Int32, Int>(multiply: { $0 * Int32($1) })
30+
static let int64 = RightModule<Int64, Int>(multiply: { $0 * Int64($1) })
2131
}
2232

2333
/// A bimodule is a module with compatible left and right operations.
24-
protocol Bimodule : LeftModule, RightModule {}
25-
26-
extension Int : LeftModule {
27-
typealias R = Int
28-
typealias A = Int
29-
}
30-
public func *<>(l : Int, r : Int) -> Int { return l * r }
31-
extension Int8 : LeftModule {
32-
typealias R = Int
33-
typealias A = Int8
34+
struct Bimodule<R: Semiring, A: Additive> {
35+
let left: LeftModule<R, A>
36+
let right: RightModule<A, R>
3437
}
35-
public func *<>(l : Int, r : Int8) -> Int8 { return Int8(l) * r }
36-
extension Int16 : LeftModule {
37-
typealias R = Int
38-
typealias A = Int16
38+
enum Bimodules {
39+
static let int = Bimodule(left: LeftModules.int, right: RightModules.int)
40+
static let int8 = Bimodule(left: LeftModules.int8, right: RightModules.int8)
41+
static let int16 = Bimodule(left: LeftModules.int16, right: RightModules.int16)
42+
static let int32 = Bimodule(left: LeftModules.int32, right: RightModules.int32)
43+
static let int64 = Bimodule(left: LeftModules.int64, right: RightModules.int64)
3944
}
40-
public func *<>(l : Int, r : Int16) -> Int16 { return Int16(l) * r }
41-
extension Int32 : LeftModule {
42-
typealias R = Int
43-
typealias A = Int32
44-
}
45-
public func *<>(l : Int, r : Int32) -> Int32 { return Int32(l) * r }
46-
extension Int64 : LeftModule {
47-
typealias R = Int
48-
typealias A = Int64
49-
}
50-
public func *<>(l : Int, r : Int64) -> Int64 { return Int64(l) * r }
51-
52-
53-
extension Int : RightModule { }
54-
public func <>*(l : Int, r : Int) -> Int { return l * r }
55-
56-
extension Int8 : RightModule { }
57-
public func <>*(l : Int8, r : Int) -> Int8 { return l * Int8(r) }
58-
59-
extension Int16 : RightModule { }
60-
public func <>*(l : Int16, r : Int) -> Int16 { return l * Int16(r) }
61-
62-
extension Int32 : RightModule { }
63-
public func <>*(l : Int32, r : Int) -> Int32 { return l * Int32(r) }
64-
65-
extension Int64 : RightModule { }
66-
public func <>*(l : Int64, r : Int) -> Int64 { return l * Int64(r) }
67-
68-
69-
extension Int : Bimodule { }
70-
extension Int8 : Bimodule { }
71-
extension Int16 : Bimodule { }
72-
extension Int32 : Bimodule { }
73-
extension Int64 : Bimodule { }

0 commit comments

Comments
 (0)