silo:std.traits
Source src/silo:std.traits
1
2
3
4
5
6
7
8
9:use
10 :open core AnyInt AnyFloat Bool Str Symbol Unit Result Vec Ordering Less Equal Greater
11:end
12
13
14
15
16
17
18
19
20@lang(add)
21:trait(pub) Add rhs | result
22
23 .+ ( Self rhs -> result )
24
25 .zero ( -> result )
26:end
27
28
29@lang(sub)
30:trait(pub) Sub rhs | result
31
32 .- ( Self rhs -> result )
33:end
34
35
36@lang(mul)
37:trait(pub) Mul rhs | result
38
39 .* ( Self rhs -> result )
40
41 .one ( -> result )
42:end
43
44
45@lang(div)
46:trait(pub) Div rhs | result
47
48 ./ ( Self rhs -> result )
49:end
50
51:impl Add AnyInt AnyInt | AnyInt
52 @host
53 .+ ( AnyInt AnyInt -> AnyInt ) ;
54 .zero ( -> AnyInt ) 0 ;
55:end
56:impl Add AnyFloat AnyFloat | AnyFloat
57 @host
58 .+ ( AnyFloat AnyFloat -> AnyFloat ) ;
59 .zero ( -> AnyFloat ) 0.0 ;
60:end
61:impl Add AnyInt AnyFloat | AnyFloat
62 @host
63 .+ ( AnyInt AnyFloat -> AnyFloat ) ;
64 .zero ( -> AnyFloat ) 0.0 ;
65:end
66:impl Add AnyFloat AnyInt | AnyFloat
67 @host
68 .+ ( AnyFloat AnyInt -> AnyFloat ) ;
69 .zero ( -> AnyFloat ) 0.0 ;
70:end
71:impl Add Str Str | Str
72 @host
73 .+ ( Str Str -> Str ) ;
74 .zero ( -> Str ) "" ;
75:end
76
77:impl Sub AnyInt AnyInt | AnyInt
78 @host
79 .- ( AnyInt AnyInt -> AnyInt ) ;
80:end
81:impl Sub AnyFloat AnyFloat | AnyFloat
82 @host
83 .- ( AnyFloat AnyFloat -> AnyFloat ) ;
84:end
85:impl Sub AnyInt AnyFloat | AnyFloat
86 @host
87 .- ( AnyInt AnyFloat -> AnyFloat ) ;
88:end
89:impl Sub AnyFloat AnyInt | AnyFloat
90 @host
91 .- ( AnyFloat AnyInt -> AnyFloat ) ;
92:end
93
94:impl Mul AnyInt AnyInt | AnyInt
95 @host
96 .* ( AnyInt AnyInt -> AnyInt ) ;
97 .one ( -> AnyInt ) 1 ;
98:end
99:impl Mul AnyFloat AnyFloat | AnyFloat
100 @host
101 .* ( AnyFloat AnyFloat -> AnyFloat ) ;
102 .one ( -> AnyFloat ) 1.0 ;
103:end
104:impl Mul AnyInt AnyFloat | AnyFloat
105 @host
106 .* ( AnyInt AnyFloat -> AnyFloat ) ;
107 .one ( -> AnyFloat ) 1.0 ;
108:end
109:impl Mul AnyFloat AnyInt | AnyFloat
110 @host
111 .* ( AnyFloat AnyInt -> AnyFloat ) ;
112 .one ( -> AnyFloat ) 1.0 ;
113:end
114
115:impl Div AnyInt AnyInt | AnyInt
116 @host
117 ./ ( AnyInt AnyInt -> AnyInt ) ;
118:end
119:impl Div AnyFloat AnyFloat | AnyFloat
120 @host
121 ./ ( AnyFloat AnyFloat -> AnyFloat ) ;
122:end
123:impl Div AnyInt AnyFloat | AnyFloat
124 @host
125 ./ ( AnyInt AnyFloat -> AnyFloat ) ;
126:end
127:impl Div AnyFloat AnyInt | AnyFloat
128 @host
129 ./ ( AnyFloat AnyInt -> AnyFloat ) ;
130:end
131
132
133
134
135@lang(eq)
136:trait(pub) Eq other
137
138 .= ( Self other -> Bool )
139
140 .≠ ( Self other -> Bool )
141 .= not ;
142:end
143:impl Eq AnyInt AnyInt
144 @host
145 .= ( AnyInt AnyInt -> Bool ) ;
146 @host
147 .≠ ( AnyInt AnyInt -> Bool ) ;
148:end
149:impl Eq AnyFloat AnyFloat
150 @host
151 .= ( AnyFloat AnyFloat -> Bool ) ;
152 @host
153 .≠ ( AnyFloat AnyFloat -> Bool ) ;
154:end
155:impl Eq Bool Bool
156 @host
157 .= ( Bool Bool -> Bool ) ;
158 @host
159 .≠ ( Bool Bool -> Bool ) ;
160:end
161:impl Eq Str Str
162 @host
163 .= ( Str Str -> Bool ) ;
164 @host
165 .≠ ( Str Str -> Bool ) ;
166:end
167:impl Eq Symbol Symbol
168 @host
169 .= ( Symbol Symbol -> Bool ) ;
170:end
171
172
173@lang(ord)
174:trait(pub) Ord other
175
176 .< ( Self other -> Bool )
177
178 .> ( Self other -> Bool )
179
180 .≤ ( Self other -> Bool )
181 .> not ;
182
183 .≥ ( Self other -> Bool )
184 .< not ;
185:end
186:impl Ord AnyInt AnyInt
187 @host
188 .< ( AnyInt AnyInt -> Bool ) ;
189 @host
190 .> ( AnyInt AnyInt -> Bool ) ;
191 @host
192 .≤ ( AnyInt AnyInt -> Bool ) ;
193 @host
194 .≥ ( AnyInt AnyInt -> Bool ) ;
195:end
196:impl Ord AnyFloat AnyFloat
197 @host
198 .< ( AnyFloat AnyFloat -> Bool ) ;
199 @host
200 .> ( AnyFloat AnyFloat -> Bool ) ;
201 @host
202 .≤ ( AnyFloat AnyFloat -> Bool ) ;
203 @host
204 .≥ ( AnyFloat AnyFloat -> Bool ) ;
205:end
206:impl Ord Str Str
207 @host
208 .< ( Str Str -> Bool ) ;
209 @host
210 .> ( Str Str -> Bool ) ;
211 @host
212 .≤ ( Str Str -> Bool ) ;
213 @host
214 .≥ ( Str Str -> Bool ) ;
215:end
216:impl Ord Symbol Symbol
217 @host
218 .< ( Symbol Symbol -> Bool ) ;
219 @host
220 .> ( Symbol Symbol -> Bool ) ;
221:end
222
223
224
225
226@lang(not)
227:trait(pub) Not .not ( Self -> Self ) :end
228:impl Not Bool
229 @host
230 .not ( Bool -> Bool ) ;
231:end
232
233
234
235
236
237
238
239
240
241@lang(from)
242:trait(pub) From source .from ( source -> Self ) :end
243
244
245@lang(into)
246:trait(pub) Into target .into ( Self -> target ) :end
247
248
249
250:trait(pub) TryFrom source | error .try-from ( source -> (Result Self error) ) :end
251
252
253
254:trait(pub) TryInto target | error .try-into ( Self -> (Result target error) ) :end
255
256:impl From AnyFloat AnyInt .from ( AnyInt -> AnyFloat ) int>float ; :end
257:impl Into AnyInt AnyFloat .into ( AnyInt -> AnyFloat ) int>float ; :end
258:impl From AnyInt AnyInt .from ( AnyInt -> AnyInt ) identity ; :end
259:impl Into AnyInt AnyInt .into ( AnyInt -> AnyInt ) identity ; :end
260:impl From AnyFloat AnyFloat .from ( AnyFloat -> AnyFloat ) identity ; :end
261:impl Into AnyFloat AnyFloat .into ( AnyFloat -> AnyFloat ) identity ; :end
262:impl From Bool Bool .from ( Bool -> Bool ) identity ; :end
263:impl Into Bool Bool .into ( Bool -> Bool ) identity ; :end
264:impl From Str Str .from ( Str -> Str ) identity ; :end
265:impl Into Str Str .into ( Str -> Str ) identity ; :end
266:impl From Symbol Symbol .from ( Symbol -> Symbol ) identity ; :end
267:impl Into Symbol Symbol .into ( Symbol -> Symbol ) identity ; :end
268
269
270
271
272
273
274@lang(display)
275:trait(pub) Display .fmt ( Self -> Str ) :end
276:impl Display AnyInt .fmt ( AnyInt -> Str ) int>str ; :end
277:impl Display AnyFloat .fmt ( AnyFloat -> Str ) float>str ; :end
278:impl Display Bool .fmt ( Bool -> Str ) bool>str ; :end
279:impl Display Str .fmt ( Str -> Str ) identity ; :end
280:impl Display Symbol .fmt ( Symbol -> Str ) symbol>str ; :end
281
282
283
284
285
286@lang(debug)
287:trait(pub) Debug .fmt-debug ( Self -> Str ) :end
288:impl Debug AnyInt .fmt-debug ( AnyInt -> Str ) int>str ; :end
289:impl Debug AnyFloat .fmt-debug ( AnyFloat -> Str ) float>str ; :end
290:impl Debug Bool .fmt-debug ( Bool -> Str ) bool>str ; :end
291:impl Debug Str .fmt-debug ( Str -> Str ) identity ; :end
292:impl Debug Symbol .fmt-debug ( Symbol -> Str ) symbol>str ; :end
293
294
295
296
297
298
299@lang(hash)
300:trait(pub) Hash .hash ( Self -> AnyInt ) :end
301:impl Hash AnyInt .hash ( AnyInt -> AnyInt ) hash-int ; :end
302:impl Hash AnyFloat .hash ( AnyFloat -> AnyInt ) hash-float ; :end
303:impl Hash Bool .hash ( Bool -> AnyInt ) hash-bool ; :end
304:impl Hash Str .hash ( Str -> AnyInt ) hash-str ; :end
305:impl Hash Symbol .hash ( Symbol -> AnyInt ) hash-symbol ; :end
306
307
308
309
310
311
312@lang(default)
313:trait(pub) Default .default ( -> Self ) :end
314:impl Default AnyInt .default ( -> AnyInt ) default-int ; :end
315:impl Default AnyFloat .default ( -> AnyFloat ) default-float ; :end
316:impl Default Bool .default ( -> Bool ) default-bool ; :end
317:impl Default Str .default ( -> Str ) default-str ; :end
318:impl Default Unit .default ( -> Unit ) default-unit ; :end
319:impl Default (Vec elem len)
320 .default ( -> (Vec elem len) ) vec-empty-intrinsic ;
321:end
322
323
324
325
326
327
328
329
330
331
332
333
334@lang(error)
335:trait(pub) Error .message ( Self -> Str ) :end
336
337
338
339
340:trait(pub) LowerHex .fmt-hex ( Self -> Str ) :end
341:impl LowerHex AnyInt .fmt-hex ( AnyInt -> Str ) int>hex ; :end
342
343
344
345
346:trait(pub) Binary .fmt-bin ( Self -> Str ) :end
347:impl Binary AnyInt .fmt-bin ( AnyInt -> Str ) int>bin ; :end