|
| 1 | +import Prelude |
| 2 | + |
1 | 3 | -- File for small illustrative telomare programs and for testing |
2 | 4 |
|
3 | 5 | -- Hello World example. |
4 | | -aux = "Hello" |
5 | | --- main = \input -> (aux, 0) |
6 | | -main = \input -> ("Hello", 0) |
| 6 | +-- aux = "Hello" |
| 7 | +-- -- main = \input -> (aux, 0) |
| 8 | +-- main = \input -> ("Hello", 0) |
7 | 9 |
|
8 | | --- -- refinement fail |
| 10 | +-- refinement fail |
9 | 11 | -- main : (\x -> if x then "fail" else 0) = 1 |
| 12 | +-- main : (\x -> assert 1 "fail") = 1 |
| 13 | +-- main : (\x -> assert (not (left x)) "fail") = 1 |
| 14 | + |
| 15 | +-- main : (\x -> assert (not x) "fail") = 1 |
10 | 16 |
|
11 | 17 | -- Ad hoc user defined types example: |
12 | 18 |
|
13 | | --- MyInt = let wrapper = \h -> ( \i -> if not i |
14 | | --- then abort "MyInt cannot be 0" |
15 | | --- else i |
16 | | --- , \i -> if dEqual (left i) h |
17 | | --- then 0 |
18 | | --- else abort "Not a MyInt" |
19 | | --- ) |
20 | | --- in wrapper (# wrapper) |
21 | | - |
22 | | --- aux = \x -> if dEqual x 8 then "Success" else "Failure" |
23 | | --- main = \i -> (aux ((left MyInt) 8), 0) |
24 | | - |
25 | | --- aux2 = [1,2,3] |
26 | | - |
27 | | --- something |
28 | | --- main = |
29 | | --- let toCase = (("a string", 99),(8,"pattern-match")) |
30 | | --- caseTest = |
31 | | --- case toCase of |
32 | | --- (0,(8,2)) -> "Failure 1" |
33 | | --- ("a string",(8,x)) -> concat [x, " failure 2"] |
34 | | --- (("a string", 99),(8,x)) -> concat [x, " success with ints, strings and variables"] |
35 | | --- in \input -> (caseTest, 0) |
| 19 | +-- Plain list assignments bind multiple names from a list-shaped value: |
| 20 | +-- [leftName, rightName] = ["left", "right"] |
| 21 | +-- [keep, drop] = \x -> [\_ -> x, \z -> z] |
| 22 | + |
| 23 | +[MyInt, mkMyInt, unMyInt] = \h -> |
| 24 | + [ \i -> if not i |
| 25 | + then abort "MyInt cannot be 0" |
| 26 | + else (h, i) |
| 27 | + , \(i : MyInt) -> i |
| 28 | + ] |
| 29 | + |
| 30 | +aux = \x -> if dEqual x 8 then "Success" else "Failure" |
| 31 | +main = \i -> (aux (unMyInt (mkMyInt 8)), 0) |
| 32 | + |
| 33 | +-- User-defined type example used by the test suite: |
| 34 | +-- [Nat, toNat, nPlus, nMinus] = \h -> |
| 35 | +-- [ \x -> (h, x) |
| 36 | +-- , \(aa : Nat) (bb : Nat) -> (h, d2c aa succ bb) |
| 37 | +-- , \(aa : Nat) (bb : Nat) -> ... |
| 38 | +-- ] |
0 commit comments