Skip to content

Instantly share code, notes, and snippets.

@ukitaka
Created January 25, 2018 08:37
Show Gist options
  • Save ukitaka/4904d9a88e7edaefeb696476663ea1e8 to your computer and use it in GitHub Desktop.
Save ukitaka/4904d9a88e7edaefeb696476663ea1e8 to your computer and use it in GitHub Desktop.
NEHL.swift
protocol NonEmptyHList {
associatedtype Head
associatedtype Tail
}
struct NEHLCons<H, T: NonEmptyHList>: NonEmptyHList {
typealias Head = H
typealias Tail = T
let head: H
let tail: T
init(_ head: H, _ tail: T) {
self.head = head
self.tail = tail
}
}
struct NEHLLast<H>: NonEmptyHList {
typealias Head = H
typealias Tail = Never
let head: H
init(_ head: H) {
self.head = head
}
}
typealias NEHL1<A> = NEHLLast<A>
typealias NEHL2<A, B> = NEHLCons<A, NEHLLast<B>>
typealias NEHL3<A, B, C> = NEHLCons<A, NEHLCons<B, NEHLLast<C>>>
typealias NEHL4<A, B, C, D> = NEHLCons<A, NEHLCons<B, NEHLCons<C, NEHLLast<D>>>>
struct ErrorA: Error {}
struct ErrorB: Error {}
let hnel: NEHL2<ErrorA, ErrorB> = NEHLCons(ErrorA(), NEHLLast(ErrorB()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment