~jojo/Carth

ref: 55fb4f948f1f3797078b584dc60b4f7dd68b37ed Carth/std/std.carth -rw-r--r-- 2.2 KiB
55fb4f94JoJo Check `cast` in Infer instead of Gen 5 months ago
                                                                                
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
(import macros)
(import iter)
(import list)
(import maybe)
(import either)
(import math)
(import lazy)
(import mem)
(import array)
(import string)
(import queue)
(import io)

(define (car      [x . _])           x)
(define (cadr     [_ x . _])         x)
(define (caddr    [_ _ x . _])       x)
(define (cadddr   [_ _ _ x . _])     x)
(define (caddddr  [_ _ _ _ x . _])   x)

(define (cdr      [_ . x])           x)
(define (cddr     [_ _ . x])         x)
(define (cdddr    [_ _ _ . x])       x)
(define (cddddr   [_ _ _ _ . x])     x)
(define (cdddddr  [_ _ _ _ _ . x])   x)

(define (map-car     f [a . b]) [(f a) . b])
(define (map-cadr    f [a . b]) [a . (map-car f b)])
(define (map-caddr   f [a . b]) [a . (map-cadr f b)])
(define (map-cadddr  f [a . b]) [a . (map-caddr f b)])
(define (map-caddddr f [a . b]) [a . (map-cadddr f b)])

(define (map-cdr     f [a . b]) [a . (f b)])
(define (map-cddr    f [a . b]) [a . (map-cdr f b)])
(define (map-cdddr   f [a . b]) [a . (map-cddr f b)])
(define (map-cddddr  f [a . b]) [a . (map-cdddr f b)])
(define (map-cdddddr f [a . b]) [a . (map-cddddr f b)])

(define (map-cons f g [a . b]) [(f a) . (g b)])

(define (map-two f g [a b]) [(f a) (g b)])
(define (map-three f g h [a b c]) [(f a) (g b) (h c)])

(define: (undefined x)
    (forall (a) (Fun Unit a))
  (panic "undefined"))

(extern -panic (Fun Str Unit))
(define (panic msg)
  (seq (-panic msg) (undefined Unit)))

(data Cmp
  Lt Eq Gt)

(define (int/cmp a b)
  (if (< a b) Lt
    (if (= a b) Eq
      Gt)))

;;; Strings

(extern show-int (Fun Int Str))
(extern show-nat (Fun Nat Str))
(extern show-f64 (Fun F64 Str))

(define show-bool (fmatch (case True "True") (case False "False")))

(extern str-append (Fun Str Str Str))

;;; Function

(define (uncurry f [a b]) (f a b))
(define (curry f a b) (f [a b]))

(define (app f a) (f a))
(define (rapp a f) (f a))

(define (const a b) a)
(define (seq   a b) b)

(define (<o f g a) (f (g a)))
(define (<oo f g a b) (f (g a b)))
(define (<ooo f g a b c) (f (g a b c)))
(define (o> f g a) (g (f a)))
(define (oo> f g a b) (g (f a b)))
(define (ooo> f g a b c) (g (f a b c)))

(define (flip f a b) (f b a))

(define (id x) x)

(data Void)

(define: void-elim
    (forall (a) (Fun Void a))
  (fmatch))