forked from AndrasKovacs/smalltt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathderiveCanIO.h
145 lines (137 loc) · 7.01 KB
/
deriveCanIO.h
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#define COMMA ,
#define CAN_IO(ty, reprep, rep, ctr, coe)\
type instance UIO.RepRep (ty) = (reprep);\
type family coe (p :: Proxy (ty))(x :: TYPE (reprep)) :: TYPE (UIO.RepRep (ty)) where{\
coe dum x = x;};\
type instance UIO.Rep (ty) = coe ('Proxy :: Proxy (ty)) (rep);\
\
instance UIO.CanIO (ty) where {\
bind :: forall r (out :: TYPE r). (UIO.RW -> (# UIO.RW, (rep) #))\
-> ((ty) -> UIO.RW -> (# UIO.RW, out #)) -> UIO.RW -> (# UIO.RW, out #);\
bind f g s = case f s of {(# s, x #) -> g (ctr) s};\
\
pure# :: (ty) -> UIO.RW -> (# UIO.RW, rep #);\
pure# (ctr) s = (# s, x #);\
\
{-# inline bind #-};\
{-# inline pure# #-};\
}
#define CAN_IO2(ty, rrep1, rrep2, rep1, rep2, ctr, coe)\
type instance UIO.RepRep (ty) = (TupleRep [rrep1 COMMA rrep2]);\
type family coe (p :: Proxy (ty))(x :: TYPE (TupleRep [rrep1 COMMA rrep2])) :: TYPE (UIO.RepRep (ty)) where{\
coe dum x = x;};\
type instance UIO.Rep (ty) = coe ('Proxy :: Proxy (ty)) (# rep1, rep2 #);\
\
instance UIO.CanIO (ty) where {\
bind :: forall r (out :: TYPE r). (UIO.RW -> (# UIO.RW, (# rep1, rep2 #) #)) \
-> ((ty) -> UIO.RW -> (# UIO.RW, out #)) -> UIO.RW -> (# UIO.RW, out #);\
bind f g s = case f s of {(# s, (# x, y #) #) -> g (ctr) s};\
\
pure# :: (ty) -> UIO.RW -> (# UIO.RW, (# rep1, rep2 #) #);\
pure# (ctr) s = (# s, (# x, y #) #);\
\
{-# inline bind #-};\
{-# inline pure# #-};\
}
#define CAN_IO3(ty, rrep1, rrep2, rrep3, rep1, rep2, rep3, ctr, coe)\
type instance UIO.RepRep (ty) = (TupleRep [rrep1 COMMA rrep2 COMMA rrep3]);\
type family coe (p :: Proxy (ty))(x :: TYPE (TupleRep [rrep1 COMMA rrep2 COMMA rrep3])) :: TYPE (UIO.RepRep (ty)) where{\
coe dum x = x;};\
type instance UIO.Rep (ty) = coe ('Proxy :: Proxy (ty)) (# rep1, rep2, rep3 #);\
\
instance UIO.CanIO (ty) where {\
bind :: forall r (out :: TYPE r). (UIO.RW -> (# UIO.RW, (# rep1, rep2, rep3 #) #))\
-> ((ty) -> UIO.RW -> (# UIO.RW, out #)) -> UIO.RW -> (# UIO.RW, out #);\
bind f g s = case f s of {(# s, (# x, y, z #) #) -> g (ctr) s};\
\
pure# :: (ty) -> UIO.RW -> (# UIO.RW, (# rep1, rep2, rep3 #) #);\
pure# (ctr) s = (# s, (# x, y, z #) #);\
\
{-# inline bind #-};\
{-# inline pure# #-};\
}
#define CAN_IO4(ty, rrep1, rrep2, rrep3, rrep4, rep1, rep2, rep3, rep4, ctr, coe)\
type instance UIO.RepRep (ty) = (TupleRep [rrep1 COMMA rrep2 COMMA rrep3 COMMA rrep4]);\
type family coe (p :: Proxy (ty))(x :: TYPE (TupleRep [rrep1 COMMA rrep2 COMMA rrep3 COMMA rrep4])) :: TYPE (UIO.RepRep (ty)) where{\
coe dum x = x;};\
type instance UIO.Rep (ty) = coe ('Proxy :: Proxy (ty)) (# rep1, rep2, rep3, rep4 #);\
\
instance UIO.CanIO (ty) where {\
bind :: forall r (out :: TYPE r). (UIO.RW -> (# UIO.RW, (# rep1, rep2, rep3, rep4 #) #))\
-> ((ty) -> UIO.RW -> (# UIO.RW, out #)) -> UIO.RW -> (# UIO.RW, out #);\
bind f g s = case f s of {(# s, (# a, b, c, d #) #) -> g (ctr) s};\
\
pure# :: (ty) -> UIO.RW -> (# UIO.RW, (# rep1, rep2, rep3, rep4 #) #);\
pure# (ctr) s = (# s, (# a, b, c, d #) #);\
\
{-# inline bind #-};\
{-# inline pure# #-};\
}
#define CAN_IO5(ty, rrep1, rrep2, rrep3, rrep4, rrep5, rep1, rep2, rep3, rep4, rep5, ctr, coe)\
type instance UIO.RepRep (ty) = (TupleRep [rrep1 COMMA rrep2 COMMA rrep3 COMMA rrep4 COMMA rrep5]);\
type family coe (p :: Proxy (ty))(x :: TYPE (TupleRep [rrep1 COMMA rrep2 COMMA rrep3 COMMA rrep4 COMMA rrep5])) :: TYPE (UIO.RepRep (ty)) where{\
coe dum x = x;};\
type instance UIO.Rep (ty) = coe ('Proxy :: Proxy (ty)) (# rep1, rep2, rep3, rep4, rep5 #);\
\
instance UIO.CanIO (ty) where {\
bind :: forall r (out :: TYPE r). (UIO.RW -> (# UIO.RW, (# rep1, rep2, rep3, rep4, rep5 #) #))\
-> ((ty) -> UIO.RW -> (# UIO.RW, out #)) -> UIO.RW -> (# UIO.RW, out #);\
bind f g s = case f s of {(# s, (# a, b, c, d, e #) #) -> g (ctr) s};\
\
pure# :: (ty) -> UIO.RW -> (# UIO.RW, (# rep1, rep2, rep3, rep4, rep5 #) #);\
pure# (ctr) s = (# s, (# a, b, c, d, e #) #);\
\
{-# inline bind #-};\
{-# inline pure# #-};\
}
#define CAN_IO6(ty, rrep1, rrep2, rrep3, rrep4, rrep5, rrep6, rep1, rep2, rep3, rep4, rep5, rep6, ctr, coe)\
type instance UIO.RepRep (ty) = (TupleRep [rrep1 COMMA rrep2 COMMA rrep3 COMMA rrep4 COMMA rrep5 COMMA rrep6]);\
type family coe (p :: Proxy (ty))(x :: TYPE (TupleRep [rrep1 COMMA rrep2 COMMA rrep3 COMMA rrep4 COMMA rrep5 COMMA rrep6])) :: TYPE (UIO.RepRep (ty)) where{\
coe dum x = x;};\
type instance UIO.Rep (ty) = coe ('Proxy :: Proxy (ty)) (# rep1, rep2, rep3, rep4, rep5, rep6 #);\
\
instance UIO.CanIO (ty) where {\
bind :: forall r (out :: TYPE r). (UIO.RW -> (# UIO.RW, (# rep1, rep2, rep3, rep4, rep5, rep6 #) #))\
-> ((ty) -> UIO.RW -> (# UIO.RW, out #)) -> UIO.RW -> (# UIO.RW, out #);\
bind f g s = case f s of {(# s, (# a, b, c, d, e, f #) #) -> g (ctr) s};\
\
pure# :: (ty) -> UIO.RW -> (# UIO.RW, (# rep1, rep2, rep3, rep4, rep5, rep6 #) #);\
pure# (ctr) s = (# s, (# a, b, c, d, e, f #) #);\
\
{-# inline bind #-};\
{-# inline pure# #-};\
}
#define CAN_IO7(ty, rrep1, rrep2, rrep3, rrep4, rrep5, rrep6, rrep7, rep1, rep2, rep3, rep4, rep5, rep6, rep7, ctr, coe) \
type instance UIO.RepRep (ty) = (TupleRep [rrep1 COMMA rrep2 COMMA rrep3 COMMA rrep4 COMMA rrep5 COMMA rrep6 COMMA rrep7]);\
type family coe (p :: Proxy (ty))(x :: TYPE (TupleRep [rrep1 COMMA rrep2 COMMA rrep3 COMMA rrep4 COMMA rrep5 COMMA rrep6 COMMA rrep7])) :: TYPE (UIO.RepRep (ty)) where{\
coe dum x = x;};\
type instance UIO.Rep (ty) = coe ('Proxy :: Proxy (ty)) (# rep1, rep2, rep3, rep4, rep5, rep6, rep7 #);\
\
instance UIO.CanIO (ty) where {\
bind :: forall r (out :: TYPE r). (UIO.RW -> (# UIO.RW, (# rep1, rep2, rep3, rep4, rep5, rep6, rep7 #) #))\
-> ((ty) -> UIO.RW -> (# UIO.RW, out #)) -> UIO.RW -> (# UIO.RW, out #);\
bind f fun s = case f s of {(# s, (# a, b, c, d, e, f, g #) #) -> fun (ctr) s};\
\
pure# :: (ty) -> UIO.RW -> (# UIO.RW, (# rep1, rep2, rep3, rep4, rep5, rep6, rep7 #) #);\
pure# (ctr) s = (# s, (# a, b, c, d, e, f, g #) #);\
\
{-# inline bind #-};\
{-# inline pure# #-};\
}
#define CAN_IO8(ty, rrep1, rrep2, rrep3, rrep4, rrep5, rrep6, rrep7, rrep8, rep1, rep2, rep3, rep4, rep5, rep6, rep7, rep8, ctr, coe)\
type instance UIO.RepRep (ty) = (TupleRep [rrep1 COMMA rrep2 COMMA rrep3 COMMA rrep4 COMMA rrep5 COMMA rrep6 COMMA rrep7 COMMA rrep8]);\
type family coe (p :: Proxy (ty))(x :: TYPE (TupleRep [rrep1 COMMA rrep2 COMMA rrep3 COMMA rrep4 COMMA rrep5 COMMA rrep6 COMMA rrep7 COMMA rrep8])) :: TYPE (UIO.RepRep (ty)) where{\
coe dum x = x;};\
type instance UIO.Rep (ty) = coe ('Proxy :: Proxy (ty)) (# rep1, rep2, rep3, rep4, rep5, rep6, rep7, rep8 #);\
\
instance UIO.CanIO (ty) where {\
bind :: forall r (out :: TYPE r). (UIO.RW -> (# UIO.RW, (# rep1, rep2, rep3, rep4, rep5, rep6, rep7, rep8 #) #))\
-> ((ty) -> UIO.RW -> (# UIO.RW, out #)) -> UIO.RW -> (# UIO.RW, out #);\
bind f fun s = case f s of {(# s, (# a, b, c, d, e, f, g, h #) #) -> fun (ctr) s};\
\
pure# :: (ty) -> UIO.RW -> (# UIO.RW, (# rep1, rep2, rep3, rep4, rep5, rep6, rep7, rep8 #) #);\
pure# (ctr) s = (# s, (# a, b, c, d, e, f, g, h #) #);\
\
{-# inline bind #-};\
{-# inline pure# #-};\
}