on master help sign in
Implement basic010.
b8d355cMatus Tejiscak
test/basic010/Main.idr+31−5
@@ -1,12 +1,38 @@
1module Main
1module Main
2
2
3+%default total
4+
5+-- An expensive function.
3qib : Nat -> Nat
6qib : Nat -> Nat
4−qib Z = 1
7+qib Z = 2
5−qib (S Z) = 1
8+qib (S Z) = 2
6qib (S (S n)) = qib n * qib (S n)
9qib (S (S n)) = qib n * qib (S n)
7
10
11+-- An equality whose size reflects the size of numbers.
12+data equals : Nat -> Nat -> Type where
13+ eqZ : Z `equals` Z
14+ eqS : m `equals` n -> S m `equals` S n
15+
16+eq_refl : {n : Nat} -> n `equals` n
17+eq_refl {n = Z} = eqZ
18+eq_refl {n = S n} = eqS eq_refl
19+
20+-- Here, the proof is very expensive to compute.
21+-- We add a recursive argument to prevent Idris from inlining it.
22+f : (r, n : Nat) -> Subset Nat (\k => qib n `equals` qib k)
23+f Z n = element n eq_refl
24+f (S r) n = f r n
25+
26+-- Here, the witness is very expensive to compute.
27+-- We add a recursive argument to prevent Idris from inlining it.
8−f : (n : Nat) -> Exists (\k : Nat => qib n = k)
28+g : (r, n : Nat) -> Exists (\k : Nat => k = qib n)
9−f n = evidence (qib n) refl
29+g Z n = evidence (qib n) refl
30+g (S r) n = g r n
31+
32+nod : a -> IO ()
33+nod _ = putStrLn "*nod*"
10
34
11main : IO ()
35main : IO ()
12−main = print "hello world"
36+main = do
37+ nod $ getWitness (f 4 2)
38+ nod $ getProof (g 4 2)
test/basic010/expected+2−5
@@ -1,5 +1,2 @@
1−MAIN-PASS
1+*nod*
2−Faulty.idr:6:7:When elaborating type of Faulty.fault:
2+*nod*
3−When elaborating an application of type constructor =:
4− Can't disambiguate name: A.num, B.C.num
5−Multiple.idr:3:1:import alias not unique: "X"