Some typed latka syntax changes
Getty Ritter
8 years ago
7 | 7 | puts syll (rep.6.syll) |
8 | 8 | |
9 | 9 | (* We can now define rep in-language as |
10 | * rep (fixed n : Nat) (s : String) : String = | |
11 | case n of | |
12 | 0 . "" | |
13 | 1 . s | |
14 | _ . s (rep.(pred.n).s) | |
15 | *) | |
10 | ||
11 | rep : Num -> String -> String | |
12 | !0 _ = "" | |
13 | !1 s = s | |
14 | !n s = s rep.(pred.n).s | |
15 | *) | |
16 | 16 | |
17 | 17 | (* It is acceptable that all arguments must be explicitly specified. *) |
18 | 18 | |
19 | fact (fixed n : Nat) : Nat= | |
20 | case n of | |
21 | 0 . 0 | |
22 | _ . mul.n.(fact.(pred.n)) | |
19 | fact : Num -> Num | |
20 | !0 = 0 | |
21 | !n = mul.n.(fact.(pred.n)) | |
23 | 22 | |
24 | 23 | (* We have both labeled sums and records, where the records are closer to |
25 | 24 | * the ML style than the Haskell style. `alias` is Haskell's `type` *) |
26 | 25 | |
27 | alias Person = | |
28 | { name : String | |
29 | , age : Nat | |
26 | type Person = | |
27 | { .name String | |
28 | , .age Nat | |
30 | 29 | } |
31 | 30 | |
32 | data Character = | |
33 | Character Person | |
31 | type Character = [ Character Person ] | |
34 | 32 | |
35 | 33 | (* Type variables work as in Haskell *) |
36 | 34 | |
37 | data List a = Nil | Cons a (List a) | |
35 | type List a = [ Nil | |
36 | | Cons a (List a) | |
37 | ] | |
38 | 38 | |
39 | map (f : a -> b) (ls : List a) = | |
40 | case ls of | |
41 | Cons x xs . Cons.(f.x).xs | |
42 | _ . Nil | |
39 | map : (a -> b) -> List a -> List b | |
40 | !f !(Cons x xs) = Cons.(f.x).(map.f.xs) | |
41 | !f !Nil = Nil | |
43 | 42 | |
44 | 43 | (* We can explicitly indicate a subtyping (convertibility) |
45 | 44 | * relationship, so long as our conv instances form a DAG. *) |