-
Notifications
You must be signed in to change notification settings - Fork 1
/
prelude.frea
169 lines (109 loc) · 3.06 KB
/
prelude.frea
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
module Main where
{ data () = ()
-- (\ x -> let { plus = \ a b -> ((#+) (a, b)) ; numnum = (plus x 1) } in numnum)
; data Bool
= True
| False
; data Either a b
= Left a
| Right b
; data Maybe a
= Nothing
| Just a
; data List a
= []
| a : (List a)
-- ; type Infinite a = a a
; type String = List Char
-- ; type A = B -- BAD CYCLE
-- ; type B = A -- BAD CYCLE
-- ; type Foo = Foo -- cycle
-- ; type Bar = Either Bar Int -- cycle
-- ; type Rehtie a b = Either b a
-- ; type Identity a = a
-- ; type AAA a b = BBB b a -- BAD CYCLE
-- ; type BBB x y = AAA y x -- BAD CYCLE
; type Klo a b = Pop (Eith a) b
; type Pop t p = t p
; type Eith a b = Either a b
-- ; type Eith g h = Either g h
-- ; data Test a b c = One -- (a b c)
-- ; data ConContainer a b
-- = Container (a b)
-- ; int :: Identity Int
-- ; int = 23
-- ; str :: String
-- ; str = "hello world!"
-- ; foobar :: Rehtie Int Char
-- ; foobar = bar
-- ; bar :: Either Char Int
-- ; bar = Left 'a'
; concat :: String -> String -> String
; concat left right = left ++ right
; tt :: Klo Char Int
; tt = Left 'a'
; oo :: Klo Char String
; oo = ll
; ll :: Either Char String
; ll = Right "hello"
; (&&) :: Bool -> Bool -> Bool
; a && b = (which-Bool a
b
False)
; (||) :: Bool -> Bool -> Bool
; a || b = (which-Bool a
True
b)
; (==) :: h -> h -> Bool
; a == b = (#= (a, b))
; a < b = (#< (a, b))
; a > b = (#> (a, b))
; a + b = (#+ (a, b))
; a +. b = (#+. (a, b))
; a - b = (#- (a, b))
; a -. b = (#-. (a, b))
; a * b = (#* (a, b))
; a *. b = (#*. (a, b))
; a `div` b = (#div (a, b))
; a / b = (#/ (a, b))
; nil? a = (which-List a
True
(\ h t -> False))
; show a = ((#show) a)
; undefined = undefined
; lst !! ix = if (ix == 0)
then (which-List lst Nothing (\ h t -> (Just h)))
else (which-List lst Nothing (\ h t -> (t !! (ix - 1))))
; fst a = (#fst a)
; inj1 = fst (23, 42) -- incorrect type -- it is correct now
; snd a = (#snd a)
; la ++ lb = (which-List la
lb
(\ ha ta -> (ha : (ta ++ lb))))
; head lst = (which-List lst
Nothing
(\ h t -> (Just h)))
; tail lst = (which-List lst
Nothing
(\ h t -> (Just t)))
; show-List list = (which-List list
"[]"
( \ head tail -> ( ((show head) ++ " : ") ++ (show-List tail) ) ))
; map fn lst = (which-List lst
[]
(\ h t -> ((fn h) : (map fn t)) ))
; show-Maybe m = (which-Maybe m
"Nothing"
(\ v -> (show v)))
; fact n = if n == 0 then 1 else n * (fact (n - 1))
; test = 'c' == 'a' -- just for the future "regression prevention"
-- I would like to fix the following bug in the future
; wrong :: Int -> a
; wrong n = badbad n
; badbad o = 23
; plus a b = a + b
; numnum = plus 23 42 -- this will have an incorrect type -- it is correct now
; add = (+)
; munmun = add 23 42 -- this will have an incorrect type -- it is correct now
; nnum = #+ (23, 42)
}