-
-
Notifications
You must be signed in to change notification settings - Fork 501
/
HKT.ts
126 lines (107 loc) · 2.46 KB
/
HKT.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* Type defunctionalization (as describe in [Lightweight higher-kinded polymorphism](https://www.cl.cam.ac.uk/~jdy22/papers/lightweight-higher-kinded-polymorphism.pdf))
*
* @since 2.0.0
*/
/**
* `* -> *` constructors
* @since 2.0.0
*/
export interface HKT<URI, A> {
readonly _URI: URI
readonly _A: A
}
/**
* `* -> * -> *` constructors
* @since 2.0.0
*/
export interface HKT2<URI, E, A> extends HKT<URI, A> {
readonly _E: E
}
/**
* `* -> * -> * -> *` constructors
* @since 2.0.0
*/
export interface HKT3<URI, R, E, A> extends HKT2<URI, E, A> {
readonly _R: R
}
/**
* `* -> * -> * -> * -> *` constructors
* @since 2.0.0
*/
export interface HKT4<URI, S, R, E, A> extends HKT3<URI, R, E, A> {
readonly _S: S
}
//
// inj: type-level dictionaries for HKTs: URI -> concrete type
//
/**
* `* -> *` constructors
* @since 2.0.0
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface URItoKind<A> {}
/**
* `* -> * -> *` constructors
* @since 2.0.0
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface URItoKind2<E, A> {}
/**
* `* -> * -> * -> *` constructors
* @since 2.0.0
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface URItoKind3<R, E, A> {}
/**
* `* -> * -> * -> * -> *` constructors
* @since 2.0.0
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface URItoKind4<S, R, E, A> {}
//
// unions of URIs
//
/**
* `* -> *` constructors
* @since 2.0.0
*/
export type URIS = keyof URItoKind<any>
/**
* `* -> * -> *` constructors
* @since 2.0.0
*/
export type URIS2 = keyof URItoKind2<any, any>
/**
* `* -> * -> * -> *` constructors
* @since 2.0.0
*/
export type URIS3 = keyof URItoKind3<any, any, any>
/**
* `* -> * -> * -> * -> *` constructors
* @since 2.0.0
*/
export type URIS4 = keyof URItoKind4<any, any, any, any>
//
// prj
//
/**
* `* -> *` constructors
* @since 2.0.0
*/
export type Kind<URI extends URIS, A> = URI extends URIS ? URItoKind<A>[URI] : any
/**
* `* -> * -> *` constructors
* @since 2.0.0
*/
export type Kind2<URI extends URIS2, E, A> = URI extends URIS2 ? URItoKind2<E, A>[URI] : any
/**
* `* -> * -> * -> *` constructors
* @since 2.0.0
*/
export type Kind3<URI extends URIS3, R, E, A> = URI extends URIS3 ? URItoKind3<R, E, A>[URI] : any
/**
* `* -> * -> * -> * -> *` constructors
* @since 2.0.0
*/
export type Kind4<URI extends URIS4, S, R, E, A> = URI extends URIS4 ? URItoKind4<S, R, E, A>[URI] : any