-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.tn
57 lines (39 loc) · 877 Bytes
/
sketch.tn
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
struct A {
pub i32 f1
}
impl A {
(&self)i32 repr = self.f1
}
trait Iterator {
type Item
(&mut self)?Self.Item next
}
impl Iterator for A {
type Item = i32
(&mut self)?Self.Item next {
let value = self.f1
self.f1 = self.f1.saturating_sub 1
value
}
}
(type T, type U, T)U force_cast value {
if !std.canCast T U => @compile_error & @fmt("cannot cast {} to {}", std.typeName T, std.typeName U)
unsafe { std.force_cast T U value }
}
trait Monad {
type Item
}
(type A, type B)bool TypeEq = A == B
trait Functor where TypeEq(Self, Self.This[Self.Item]) {
type Item
type This[T]: Functor[Item = T]
(type U, self, impl Fn(Self.Item, Output = U))Self.This[U] fmap
}
trait Applicative: Functor[Item = Self.Item] {
type Item
(Self.Item)Self pure
}
trait Semigroup: Functor[Item = Self.Item] {
type Item
(self, Self)Self <>
}