An experimental Higher Kinded Types in Swift.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Sources/HigherKindSwift
Tests
.gitignore
.swift-version Add sources & tests Jun 21, 2018
LICENSE
Package.resolved
Package.swift
README.md

README.md

HigherKindSwift

An experimental Higher Kinded Types in Swift, originally from the paper: Lightweight Higher-Kinded Polymorphism.

Slide: Swiftで高カインド多相 - Speaker Deck (in Japanese 🇯🇵)

Examples

Monad

let arr = [1, 2, 3].kind
                 .bind { [$0 * 3, $0 * 5 ].kind }.value

arr == [3, 5, 6, 10, 9, 15]


let list = List<Int>.cons(1, .cons(2, .cons(3, .nil))).kind
               .bind { List.cons($0 * 3, .cons($0 * 5, .nil)).kind }
               .value

list == List.cons(3, .cons(5, .cons(6,
                  .cons(10, .cons(9, .cons(15, .nil))))))

Natural Transformation

let list = [1, 2, 3].kind
               .naturalTransform {
                    List($0.value).kind
                }
               .value

list == List.cons(1, .cons(2, .cons(3, .nil)))

References

License

MIT