on master help sign in
Fix silly error in termination checker :)
commit98395627b255c0b213f18c8066e32e90f1232dab authorEdwin Brady <eb@cs.st-andrews.ac.uk> dateWed 1 Feb 2012, 18:38 (15 years ago) parent86c2bee
5 files changed+52−4
CHANGELOG+5−4 src/Idris/Coverage.hs+1 tutorial/examples/theorems.idr+17 tutorial/starting.tex+1 tutorial/theorems.tex+28
CHANGELOG+5−4
@@ -3,15 +3,16 @@ New in 0.9.1:
33
44User visible changes:
55
6−* dsl notation
7−* record projection and update
8−* auto implicits and default argument values {auto n : T}, {default val n : T}
6+* DSL notation
7+* Record projection and update
8+* Totality checking and 'total' keyword
9+* Auto implicits and default argument values {auto n : T}, {default val n : T}
910* Additions to prelude, including Nat and List theorems
1011* New libs: control.monad.identity, control.monad.state
1112
1213Internal changes:
1314
14−* faster compilation (only compiling names which are used)
15+* Faster compilation (only compiling names which are used)
1516
16170.1.x to 0.9.0:
1718
src/Idris/Coverage.hs+1
@@ -253,6 +253,7 @@ calcTotality path fc n pats
253253 Total _ -> return ords
254254 p@(Partial (Mutual x)) -> return ((Left p) : ords)
255255 _ -> return (Left (Partial (Other [fn])) : ords)
256+ | null args = return (Left (Partial Itself) : ords)
256257 chkOrd ords args _ = return ords
257258
258259 lexOrd x y | x == y = LexEQ
tutorial/examples/theorems.idr+17
@@ -5,6 +5,23 @@ fiveIsFive = refl
55twoPlusTwo : 2 + 2 = 4
66twoPlusTwo = refl
77
8+total imp : (n : Nat) -> O = S n -> _|_
9+imp n p = replace {P = impTy} p ()
10+ where
11+ impTy : Nat -> Set
12+ impTy O = ()
13+ impTy (S k) = _|_
14+
15+empty1 : _|_
16+empty1 = let xs : List _|_ = [] in hd xs
17+ where
18+ hd : List a -> a
19+ hd (x :: xs) = x
20+
21+
22+empty2 : _|_
23+empty2 = empty2
24+
825plusReduces : (n:Nat) -> plus O n = n
926plusReduces n = refl
1027
tutorial/starting.tex+1
@@ -109,6 +109,7 @@ Idris version 0.9.1
109109
110110 <expr> Evaluate an expression
111111 :t <expr> Check the type of an expression
112+ :total <name> Check the totality of a name
112113 :r :reload Reload current file
113114 :e :edit Edit current file using $EDITOR or $VISUAL
114115 :m :metavars Show remaining proof obligations (metavariables)
tutorial/theorems.tex+28
@@ -29,6 +29,34 @@ twoPlusTwo = refl
2929\end{SaveVerbatim}
3030\useverb{eqprf}
3131
32+\subsection{The Empty Type}
33+
34+There is an empty type, \texttt{\_|\_}, which has no constructors. It is
35+therefore impossible to construct an element of the empty type, at least
36+without using a partially defined or general recursive function (see Section
37+\ref{sect:totality} for more details). We can therefore use the empty type
38+to prove that something is impossible, for example zero is never equal
39+to a successor:
40+
41+\begin{SaveVerbatim}{natdisjoint}
42+
43+imp : (n : Nat) -> O = S n -> _|_
44+imp n p = replace {P = impTy} p ()
45+ where
46+ impTy : Nat -> Set
47+ impTy O = ()
48+ impTy (S k) = _|_
49+
50+\end{SaveVerbatim}
51+\useverb{natdisjoint}
52+
53+\noindent
54+There is no need to worry too much about how this function works --- essentially,
55+it applies the library function \texttt{replace}, which uses an equality proof to
56+transform a predicate. Here we use it to transform a value of a type which can exist,
57+the empty tuple, to a value of a type which can't, by using a proof of something
58+which can't exist.
59+
3260\subsection{Simple Theorems}
3361
3462When type checking dependent types, the type itself gets \emph{normalised}. So imagine