-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample.nosh
107 lines (92 loc) · 2.68 KB
/
Example.nosh
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
(* type is a "variadic keyword" *)
(* type <name> ... *)
@type ; Void : Type
(* ; @type (: Void Type) *)
(* @type (: Void Type) *)
@type ; Unit : Type
Un : Unit
(* @type (: Unit Type) (: Un Unit) *)
@type ; Bool : Type
False : Bool
True : Bool
(* @type (: Bool Type) (: False Bool) (: True Bool) *)
@type ; Bool3 : Type
Yes : Bool3
No : Bool3
Maybe : Bool3
(* @type (: Bool3 Type) (: Yes Bool3) (: No Bool3) (: Maybe Bool3) *)
@type ; Maybe : 'a -> Type
None : Maybe _
Some : 'a -> Maybe 'a
(* @type (: Maybe ('a -> Type)) (: None (Maybe _)) (: Some ('a -> Maybe 'a)) *)
(* @type (: Maybe (-> 'a Type)) (: None (Maybe _)) (: Some (-> 'a (Maybe 'a))) *)
@let ; map : -> 'a 'b -> Maybe 'a -> Maybe 'b
f . x .
@match x
None => None
Some y => Some ; f y
(* @let (: map (-> 'a 'b -> Maybe 'a -> Maybe 'b)) (...) *)
(* @let (: map (-> 'a 'b -> Maybe 'a -> Maybe 'b)) (...) *)
(* @let (: map ((-> 'a 'b) -> (Maybe 'a -> Maybe 'b))) (...) *)
(* @let (: map ((-> 'a 'b) -> (-> (Maybe 'a) (Maybe 'b)))) (...) *)
(* . f (x . (@match x (None => None) (Some y => Some ; f y))) *)
(* . f (. x (@match x (=> None None) (=> (Some y) (Some ; f y)))) *)
(* . f (. x (@match x (=> None None) (=> (Some y) (Some (f y))))) *)
@type ; Result : 'e -> 'o -> Type
Error : 'e -> Result 'e _
Ok : 'o -> Result _ 'o
(* @type (: Result ('e -> 'o -> Type)) (: Error ('e -> Result 'e _)) (: Ok ('o -> Result _ 'o)) *)
(* @type (: Result (-> 'e (-> 'o Type))) (: Error (-> 'e (Result 'e _))) (: Ok (-> 'o (Result _ 'o))) *)
@let ; notTrue : Bool
False
(* = notTrue (: Bool) False *)
@let ; id : 'a -> 'a
x . x
(* = id (: 'a -> 'a) (x . x) *)
(* = id (: (-> 'a 'a)) (. x x) *)
@let ; const : 'a -> 'b -> 'a
x . _ . x
(* = const (: 'a -> 'b -> 'a) (x . _ . x) *)
(* = const (: (-> 'a ('b -> 'a))) (. x (_ . x)) *)
(* = const (: (-> 'a (-> 'b 'a))) (. x (. _ x)) *)
@type Int8 : Type
B0 : Int8
B1 : Int8
B2 : Int8
B3 : Int8
B4 : Int8
B5 : Int8
B6 : Int8
B- : Int8
@let ; + : Int8 -> Int8 -> Int8
x . y .
@match ; x , y
, B0 x => x
, x B0 => x
, B1 B1 => B2
, B1 B2 => B3
, B1 B3 => B4
, B1 B4 => B5
, B1 B5 => B6
, B2 B1 => B3
, B2 B2 => B4
, B2 B3 => B5
, B2 B4 => B6
, B3 B1 => B4
, B3 B2 => B5
, B3 B3 => B6
, B4 B1 => B5
, B4 B2 => B6
, B5 B1 => B6
, _ _ => B-
@let ; * : Int8 -> Int8 -> Int8
x . y .
@match ; x , y
, B0 _ => B0
, _ B0 => B0
, B1 x => x
, x B1 => x
, B2 B2 => B4
, B2 B3 => B6
, B3 B2 => B6
, _ _ => B-