aboutsummaryrefslogtreecommitdiffstats
path: root/examples/types-concept.milch
blob: 8359c6bf7e92c8ee46fa6f8f2cc7817fae1a7420 (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
; 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 is-even (\[Int] Bool))
(let! is-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))