aboutsummaryrefslogtreecommitdiffstats
path: root/examples/types-concept.milch
blob: a2126d94ca1e8024709ee3e93bc882c5b57f0938 (plain)
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
; Probably not going to implement this,
; just writing down ideas

; lowercase types: polymorphic
; everything else: monomorphic

(type compose (\[
    (\[b] c)  ; f
    (\[a] b)] ; g
    (\[a] c)))
(let
    compose (\[f g] (\[x] (f (g x)))))

((compose (+ 1) (+ 2)) 3)

(type id (\[a] a))
(let id (\[a] a))

(type mod (\[Int Int] Int))
(let mod (\[n k]
    (- n (* k (/ n k)))))

(type not (\[Bool] Bool))
(let not (\[b]
    (match b
        true false
        false true)))

(type even? (\[Int] Bool))
(let even? (\[n]
    (match (mod n 2)
        0 true
        1 false)))

; match cannot be type annotated because its variadic
; but the match above is inferred as this:
(type match (\[a a b a b] b))