on master help sign in
Merge branch 'master' into bitstring
commit4c5b1bd96d26f8dae4125c527069635acdef0e63 authorBenjamin Saunders <besaunde@sfu.ca> dateTue 12 Feb 2013, 14:11 (14 years ago) parent5be5c84f31c76a
63 files changed+4938−2581
CHANGELOG+11 idris.cabal+2 js/Runtime.js+400 lib/Builtins.idr+4 lib/Control/Arrow.idr+5−4 lib/Prelude.idr+2−3 lib/Prelude/Fin.idr+3−5 lib/Prelude/Heap.idr+1−1 lib/Prelude/Strings.idr+2−2 lib/Prelude/Vect.idr+2−2 papers/impl-paper/conclusions.tex+72−49 papers/impl-paper/elaboration.tex+793−408 papers/impl-paper/hll.tex+131−109 papers/impl-paper/impldtp.tex+7−6 papers/impl-paper/intro.tex+35−41 papers/impl-paper/library.bib+1993−1039 papers/impl-paper/macros.ltx+4−4 papers/impl-paper/typechecking.tex+273−210 samples/binary.idr+2−2 samples/interp-alt.idr+4−4 samples/interp.idr+4−4 src/Core/CaseTree.hs+1−1 src/Core/Elaborate.hs+45−21 src/Core/Evaluate.hs+1−1 src/Core/ProofShell.hs+21−17 src/Core/ProofState.hs+98−45 src/Core/TT.hs+7−3 src/Core/Typecheck.hs+3−1 src/Core/Unify.hs+109−44 src/IRTS/CodegenJavaScript.hs+169−181 src/IRTS/Compiler.hs+3−3 src/Idris/AbsSyntax.hs+92−92 src/Idris/AbsSyntaxTree.hs+5−2 src/Idris/Completion.hs+143 src/Idris/Coverage.hs+18−16 src/Idris/DataOpts.hs+2−2 src/Idris/ElabDecls.hs+155−50 src/Idris/ElabTerm.hs+145−59 src/Idris/Error.hs+3−3 src/Idris/IBC.hs+6−4 src/Idris/Parser.hs+12−11 src/Idris/Prover.hs+30−13 src/Idris/REPL.hs+53−46 src/Idris/UnusedArgs.hs+2−2 src/Main.hs+1−1 test/reg002/reg002.idr+2−2 test/reg005/reg005.idr+1−1 test/reg008/reg008.idr+1−1 test/reg009/reg009.lidr+1−1 test/test005/test005.idr+6−7 test/test006/test006.idr+4−4 test/test007/test007.idr+1−2 test/test014/Resimp.idr+2 test/test015/test015.idr+2−4 test/test018/test018a.idr+2−2 tutorial/classes.tex+25−18 tutorial/examples/binary.idr+3−5 tutorial/examples/interp.idr+3 tutorial/idris-tutorial.pdf tutorial/interp.tex+1−1 tutorial/intro.tex+1−1 tutorial/starting.tex+3−3 tutorial/typesfuns.tex+6−18
CHANGELOG+11
@@ -1,3 +1,14 @@
1+New in 0.9.7:
2+-------------
3+
4+User visible changes:
5+
6+Internal changes:
7+
8+* Change unification so that it keeps track of failed constraints in case
9+ later information helps to resolve them
10+* Distinguishing parameters and indices in data types
11+
112New in 0.9.6:
213-------------
314
idris.cabal+2
@@ -47,6 +47,7 @@ Build-type: Custom
4747Data-files: rts/libidris_rts.a rts/idris_rts.h rts/idris_gc.h
4848 rts/idris_stdfgn.h rts/idris_main.c rts/idris_gmp.h
4949 rts/libtest.c
50+ js/Runtime.js
5051Extra-source-files: lib/Makefile lib/*.idr lib/Prelude/*.idr
5152 lib/Network/*.idr lib/Control/*.idr
5253 lib/Control/Monad/*.idr lib/Language/*.idr
@@ -55,6 +56,7 @@ Extra-source-files: lib/Makefile lib/*.idr lib/Prelude/*.idr
5556 tutorial/examples/*.idr lib/base.ipkg
5657 config.mk
5758 rts/*.c rts/*.h rts/Makefile
59+ js/*.js
5860
5961source-repository head
6062 type: git
js/Runtime.jsnew file+400
@@ -0,0 +1,400 @@
1+var require;
2+var __IDRRT__ = {};
3+
4+/** @constructor */
5+__IDRRT__.Type = function(type) {
6+ this.type = type;
7+};
8+
9+__IDRRT__.Int = new __IDRRT__.Type('Int');
10+__IDRRT__.Char = new __IDRRT__.Type('Char');
11+__IDRRT__.String = new __IDRRT__.Type('String');
12+__IDRRT__.Integer = new __IDRRT__.Type('Integer');
13+__IDRRT__.Float = new __IDRRT__.Type('Float');
14+__IDRRT__.Forgot = new __IDRRT__.Type('Forgot');
15+
16+/** @constructor */
17+__IDRRT__.Tailcall = function(f) { this.f = f };
18+
19+/** @constructor */
20+__IDRRT__.Con = function(i,vars) {
21+ this.i = i;
22+ this.vars = vars;
23+};
24+
25+__IDRRT__.tailcall = function(f) {
26+ var __f = f;
27+ var ret;
28+ while (__f) {
29+ f = __f;
30+ __f = null;
31+ ret = f();
32+
33+ if (ret instanceof __IDRRT__.Tailcall) {
34+ __f = ret.f;
35+ } else {
36+ return ret;
37+ }
38+ }
39+};
40+
41+__IDRRT__.print = (function(){
42+ if (require) {
43+ var util = require('util');
44+ return function(s) {
45+ util.print(s);
46+ };
47+ } else {
48+ return function(s) {
49+ console.log(s);
50+ };
51+ }
52+})();
53+
54+/*
55+ BigInteger Javascript code taken from:
56+ https://github.com/peterolson
57+*/
58+__IDRRT__.bigInt = (function () {
59+ var base = 10000000, logBase = 7;
60+ var sign = {
61+ positive: false,
62+ negative: true
63+ };
64+
65+ var normalize = function (first, second) {
66+ var a = first.value, b = second.value;
67+ var length = a.length > b.length ? a.length : b.length;
68+ for (var i = 0; i < length; i++) {
69+ a[i] = a[i] || 0;
70+ b[i] = b[i] || 0;
71+ }
72+ for (var i = length - 1; i >= 0; i--) {
73+ if (a[i] === 0 && b[i] === 0) {
74+ a.pop();
75+ b.pop();
76+ } else break;
77+ }
78+ if (!a.length) a = [0], b = [0];
79+ first.value = a;
80+ second.value = b;
81+ };
82+
83+ var parse = function (text, first) {
84+ if (typeof text === "object") return text;
85+ text += "";
86+ var s = sign.positive, value = [];
87+ if (text[0] === "-") {
88+ s = sign.negative;
89+ text = text.slice(1);
90+ }
91+ var text = text.split("e");
92+ if (text.length > 2) throw new Error("Invalid integer");
93+ if (text[1]) {
94+ var exp = text[1];
95+ if (exp[0] === "+") exp = exp.slice(1);
96+ exp = parse(exp);
97+ if (exp.lesser(0)) throw new Error("Cannot include negative exponent part for integers");
98+ while (exp.notEquals(0)) {
99+ text[0] += "0";
100+ exp = exp.prev();
101+ }
102+ }
103+ text = text[0];
104+ if (text === "-0") text = "0";
105+ var isValid = /^([0-9][0-9]*)$/.test(text);
106+ if (!isValid) throw new Error("Invalid integer");
107+ while (text.length) {
108+ var divider = text.length > logBase ? text.length - logBase : 0;
109+ value.push(+text.slice(divider));
110+ text = text.slice(0, divider);
111+ }
112+ var val = bigInt(value, s);
113+ if (first) normalize(first, val);
114+ return val;
115+ };
116+
117+ var goesInto = function (a, b) {
118+ var a = bigInt(a, sign.positive), b = bigInt(b, sign.positive);
119+ if (a.equals(0)) throw new Error("Cannot divide by 0");
120+ var n = 0;
121+ do {
122+ var inc = 1;
123+ var c = bigInt(a.value, sign.positive), t = c.times(10);
124+ while (t.lesser(b)) {
125+ c = t;
126+ inc *= 10;
127+ t = t.times(10);
128+ }
129+ while (c.lesserOrEquals(b)) {
130+ b = b.minus(c);
131+ n += inc;
132+ }
133+ } while (a.lesserOrEquals(b));
134+
135+ return {
136+ remainder: b.value,
137+ result: n
138+ };
139+ };
140+
141+ var bigInt = function (value, s) {
142+ var self = {
143+ value: value,
144+ sign: s
145+ };
146+ var o = {
147+ value: value,
148+ sign: s,
149+ negate: function (m) {
150+ var first = m || self;
151+ return bigInt(first.value, !first.sign);
152+ },
153+ abs: function (m) {
154+ var first = m || self;
155+ return bigInt(first.value, sign.positive);
156+ },
157+ add: function (n, m) {
158+ var s, first = self, second;
159+ if (m) (first = parse(n)) && (second = parse(m));
160+ else second = parse(n, first);
161+ s = first.sign;
162+ if (first.sign !== second.sign) {
163+ first = bigInt(first.value, sign.positive);
164+ second = bigInt(second.value, sign.positive);
165+ return s === sign.positive ?
166+ o.subtract(first, second) :
167+ o.subtract(second, first);
168+ }
169+ normalize(first, second);
170+ var a = first.value, b = second.value;
171+ var result = [],
172+ carry = 0;
173+ for (var i = 0; i < a.length || carry > 0; i++) {
174+ var sum = (a[i] || 0) + (b[i] || 0) + carry;
175+ carry = sum >= base ? 1 : 0;
176+ sum -= carry * base;
177+ result.push(sum);
178+ }
179+ return bigInt(result, s);
180+ },
181+ plus: function (n, m) {
182+ return o.add(n, m);
183+ },
184+ subtract: function (n, m) {
185+ var first = self, second;
186+ if (m) (first = parse(n)) && (second = parse(m));
187+ else second = parse(n, first);
188+ if (first.sign !== second.sign) return o.add(first, o.negate(second));
189+ if (first.sign === sign.negative) return o.subtract(o.negate(second), o.negate(first));
190+ if (o.compare(first, second) === -1) return o.negate(o.subtract(second, first));
191+ var a = first.value, b = second.value;
192+ var result = [],
193+ borrow = 0;
194+ for (var i = 0; i < a.length; i++) {
195+ a[i] -= borrow;
196+ borrow = a[i] < b[i] ? 1 : 0;
197+ var minuend = (borrow * base) + a[i] - b[i];
198+ result.push(minuend);
199+ }
200+ return bigInt(result, sign.positive);
201+ },
202+ minus: function (n, m) {
203+ return o.subtract(n, m);
204+ },
205+ multiply: function (n, m) {
206+ var s, first = self, second;
207+ if (m) (first = parse(n)) && (second = parse(m));
208+ else second = parse(n, first);
209+ s = first.sign !== second.sign;
210+ var a = first.value, b = second.value;
211+ var resultSum = [];
212+ for (var i = 0; i < a.length; i++) {
213+ resultSum[i] = [];
214+ var j = i;
215+ while (j--) {
216+ resultSum[i].push(0);
217+ }
218+ }
219+ var carry = 0;
220+ for (var i = 0; i < a.length; i++) {
221+ var x = a[i];
222+ for (var j = 0; j < b.length || carry > 0; j++) {
223+ var y = b[j];
224+ var product = y ? (x * y) + carry : carry;
225+ carry = product > base ? Math.floor(product / base) : 0;
226+ product -= carry * base;
227+ resultSum[i].push(product);
228+ }
229+ }
230+ var max = -1;
231+ for (var i = 0; i < resultSum.length; i++) {
232+ var len = resultSum[i].length;
233+ if (len > max) max = len;
234+ }
235+ var result = [], carry = 0;
236+ for (var i = 0; i < max || carry > 0; i++) {
237+ var sum = carry;
238+ for (var j = 0; j < resultSum.length; j++) {
239+ sum += resultSum[j][i] || 0;
240+ }
241+ carry = sum > base ? Math.floor(sum / base) : 0;
242+ sum -= carry * base;
243+ result.push(sum);
244+ }
245+ return bigInt(result, s);
246+ },
247+ times: function (n, m) {
248+ return o.multiply(n, m);
249+ },
250+ divmod: function (n, m) {
251+ var s, first = self, second;
252+ if (m) (first = parse(n)) && (second = parse(m));
253+ else second = parse(n, first);
254+ s = first.sign !== second.sign;
255+ if (bigInt(first.value, first.sign).equals(0)) return {
256+ quotient: bigInt([0], sign.positive),
257+ remainder: bigInt([0], sign.positive)
258+ };
259+ if (second.equals(0)) throw new Error("Cannot divide by zero");
260+ var a = first.value, b = second.value;
261+ var result = [], remainder = [];
262+ for (var i = a.length - 1; i >= 0; i--) {
263+ var n = [a[i]].concat(remainder);
264+ var quotient = goesInto(b, n);
265+ result.push(quotient.result);
266+ remainder = quotient.remainder;
267+ }
268+ result.reverse();
269+ return {
270+ quotient: bigInt(result, s),
271+ remainder: bigInt(remainder, first.sign)
272+ };
273+ },
274+ divide: function (n, m) {
275+ return o.divmod(n, m).quotient;
276+ },
277+ over: function (n, m) {
278+ return o.divide(n, m);
279+ },
280+ mod: function (n, m) {
281+ return o.divmod(n, m).remainder;
282+ },
283+ pow: function (n, m) {
284+ var first = self, second;
285+ if (m) (first = parse(n)) && (second = parse(m));
286+ else second = parse(n, first);
287+ var a = first, b = second;
288+ if (b.lesser(0)) return ZERO;
289+ if (b.equals(0)) return ONE;
290+ var result = bigInt(a.value, a.sign);
291+
292+ if (b.mod(2).equals(0)) {
293+ var c = result.pow(b.over(2));
294+ return c.times(c);
295+ } else {
296+ return result.times(result.pow(b.minus(1)));
297+ }
298+ },
299+ next: function (m) {
300+ var first = m || self;
301+ return o.add(first, 1);
302+ },
303+ prev: function (m) {
304+ var first = m || self;
305+ return o.subtract(first, 1);
306+ },
307+ compare: function (n, m) {
308+ var first = self, second;
309+ if (m) (first = parse(n)) && (second = parse(m, first));
310+ else second = parse(n, first);
311+ normalize(first, second);
312+ if (first.value.length === 1 && second.value.length === 1 && first.value[0] === 0 && second.value[0] === 0) return 0;
313+ if (second.sign !== first.sign) return first.sign === sign.positive ? 1 : -1;
314+ var multiplier = first.sign === sign.positive ? 1 : -1;
315+ var a = first.value, b = second.value;
316+ for (var i = a.length - 1; i >= 0; i--) {
317+ if (a[i] > b[i]) return 1 * multiplier;
318+ if (b[i] > a[i]) return -1 * multiplier;
319+ }
320+ return 0;
321+ },
322+ compareAbs: function (n, m) {
323+ var first = self, second;
324+ if (m) (first = parse(n)) && (second = parse(m, first));
325+ else second = parse(n, first);
326+ first.sign = second.sign = sign.positive;
327+ return o.compare(first, second);
328+ },
329+ equals: function (n, m) {
330+ return o.compare(n, m) === 0;
331+ },
332+ notEquals: function (n, m) {
333+ return !o.equals(n, m);
334+ },
335+ lesser: function (n, m) {
336+ return o.compare(n, m) < 0;
337+ },
338+ greater: function (n, m) {
339+ return o.compare(n, m) > 0;
340+ },
341+ greaterOrEquals: function (n, m) {
342+ return o.compare(n, m) >= 0;
343+ },
344+ lesserOrEquals: function (n, m) {
345+ return o.compare(n, m) <= 0;
346+ },
347+ isPositive: function (m) {
348+ var first = m || self;
349+ return first.sign === sign.positive;
350+ },
351+ isNegative: function (m) {
352+ var first = m || self;
353+ return first.sign === sign.negative;
354+ },
355+ isEven: function (m) {
356+ var first = m || self;
357+ return first.value[0] % 2 === 0;
358+ },
359+ isOdd: function (m) {
360+ var first = m || self;
361+ return first.value[0] % 2 === 1;
362+ },
363+ toString: function (m) {
364+ var first = m || self;
365+ var str = "", len = first.value.length;
366+ while (len--) {
367+ str += (base.toString() + first.value[len]).slice(-logBase);
368+ }
369+ while (str[0] === "0") {
370+ str = str.slice(1);
371+ }
372+ if (!str.length) str = "0";
373+ var s = first.sign === sign.positive ? "" : "-";
374+ return s + str;
375+ },
376+ toJSNumber: function (m) {
377+ return +o.toString(m);
378+ },
379+ valueOf: function (m) {
380+ return o.toJSNumber(m);
381+ }
382+ };
383+ return o;
384+ };
385+
386+ var ZERO = bigInt([0], sign.positive);
387+ var ONE = bigInt([1], sign.positive);
388+ var MINUS_ONE = bigInt([1], sign.negative);
389+
390+ var fnReturn = function (a) {
391+ if (typeof a === "undefined") return ZERO;
392+ return parse(a);
393+ };
394+ fnReturn.zero = ZERO;
395+ fnReturn.one = ONE;
396+ fnReturn.minusOne = MINUS_ONE;
397+ return fnReturn;
398+})();
399+
400+var __IDR__ = {};
lib/Builtins.idr+4
@@ -38,6 +38,10 @@ abstract
3838believe_me : a -> b -- compiled specially as id, use with care!
3939believe_me x = prim__believe_me _ _ x
4040
41+public -- reduces at compile time, use with extreme care!
42+really_believe_me : a -> b
43+really_believe_me x = prim__believe_me _ _ x
44+
4145namespace Builtins {
4246
4347id : a -> a
lib/Control/Arrow.idr+5−4
@@ -24,16 +24,17 @@ instance Arrow Homomorphism where
2424
2525instance Monad m => Arrow (Kleislimorphism m) where
2626 arrow f = Kleisli (return . f)
27− first (Kleisli f) = Kleisli $ \(a, b) => do x <- f a
28− return (x, b)
27+ first (Kleisli f) = Kleisli $ \(a, b) => do x <- f a
28+ return (x, b)
2929
3030 second (Kleisli f) = Kleisli $ \(a, b) => do x <- f b
3131 return (a, x)
3232
33− (Kleisli f) *** (Kleisli g) = Kleisli $ \(a, b) => do x <- f a
33+ (Kleisli f) *** (Kleisli g) = Kleisli $ \(a, b) => do x <- f a
3434 y <- g b
3535 return (x, y)
3636
37− (Kleisli f) &&& (Kleisli g) = Kleisli $ \a => do x <- f a
37+ (Kleisli f) &&& (Kleisli g) = Kleisli $ \a => do x <- f a
3838 y <- g a
3939 return (x, y)
40+
lib/Prelude.idr+2−3
@@ -59,14 +59,13 @@ instance (Show a, Show b) => Show (a, b) where
5959
6060instance Show a => Show (List a) where
6161 show xs = "[" ++ show' "" xs ++ "]" where
62− show' : String -> List a -> String
6362 show' acc [] = acc
6463 show' acc [x] = acc ++ show x
6564 show' acc (x :: xs) = show' (acc ++ show x ++ ", ") xs
6665
6766instance Show a => Show (Vect a n) where
6867 show xs = "[" ++ show' xs ++ "]" where
69− show' : Vect a m -> String
68+ show' : Vect a n -> String
7069 show' [] = ""
7170 show' [x] = show x
7271 show' (x :: xs) = show x ++ ", " ++ show' xs
@@ -335,7 +334,7 @@ readFile fn = do h <- openFile fn Read
335334 c <- readFile' h ""
336335 closeFile h
337336 return c
338− where
337+ where
339338 partial
340339 readFile' : File -> String -> IO String
341340 readFile' h contents =
lib/Prelude/Fin.idr+3−5
@@ -8,11 +8,9 @@ data Fin : Nat -> Type where
88 fS : Fin k -> Fin (S k)
99
1010instance Eq (Fin n) where
11− (==) = eq where
12− eq : Fin m -> Fin m -> Bool
13− eq fO fO = True
14− eq (fS k) (fS k') = eq k k'
15− eq _ _ = False
11+ (==) fO fO = True
12+ (==) (fS k) (fS k') = k == k'
13+ (==) _ _ = False
1614
1715finToNat : Fin n -> Nat -> Nat
1816finToNat fO a = a
lib/Prelude/Heap.idr+1−1
@@ -106,7 +106,7 @@ toList (Node s l e r) = toList' (Node s l e r) refl
106106 where
107107 %assert_total -- relies on deleteMinimum making heap smaller
108108 toList' : Ord a => (h : MaxiphobicHeap a) -> (isEmpty h = False) -> List a
109− toList' heap p = findMinimum heap p :: (toList $ deleteMinimum heap p)
109+ toList' heap p = findMinimum heap p :: (toList (deleteMinimum heap p))
110110
111111fromList : Ord a => List a -> MaxiphobicHeap a
112112fromList = foldr insert empty
lib/Prelude/Strings.idr+2−2
@@ -25,8 +25,8 @@ strTail' x p = prim__strTail x
2525%assert_total
2626strM : (x : String) -> StrM x
2727strM x with (choose (not (x == "")))
28− strM x | (Left p) = believe_me $ StrCons (strHead' x p) (strTail' x p)
29− strM x | (Right p) = believe_me StrNil
28+ strM x | (Left p) = really_believe_me $ StrCons (strHead' x p) (strTail' x p)
29+ strM x | (Right p) = really_believe_me StrNil
3030
3131-- annoyingly, we need these assert_totals because StrCons doesn't have
3232-- a recursive argument, therefore the termination checker doesn't believe
lib/Prelude/Vect.idr+2−2
@@ -129,10 +129,10 @@ total or : Vect Bool m -> Bool
129129or = foldr (||) False
130130
131131total any : (a -> Bool) -> Vect a m -> Bool
132−any p = or . map p
132+any p = Vect.or . map p
133133
134134total all : (a -> Bool) -> Vect a m -> Bool
135−all p = and . map p
135+all p = Vect.and . map p
136136
137137--------------------------------------------------------------------------------
138138-- Transformations
papers/impl-paper/conclusions.tex+72−49
@@ -4,27 +4,58 @@
44
55Dependently typed programming languages have becoming more prominent in recent
66years as tools for verifying software correctness, and several experimental
7−languages are being developed, in particular Agda \cite{norell2007thesis}, Epigram
8−\cite{McBride2004a,Levitation2010} and Trellys \cite{Kimmell2012}.
9−
10−An earlier implementation of \Idris{} was built on the \Ivor{} proof engine
7+languages are being developed, in particular Agda \cite{norell2007thesis},
8+Epigram \cite{McBride2004a,Levitation2010} and Trellys \cite{Kimmell2012}.
9+Furthermore, recent extensions to Haskell~\cite{Haskell98}, implemented in the
10+Glasgow Haskell Compiler, are bringing more of the power of dependent types to
11+Haskell. The problem of refining high level syntax to a core type theory also
12+applies to theorem provers based on dependent types such as
13+Coq~\cite{Bertot2004} and Matita~\cite{Asperti2011}.
14+
15+Checking advanced type system features in Haskell involves a type system
16+parameterised over an underlying constraint system $X$ which captures
17+constraints such as type classes, constrained data types and type families.
18+Types are checked using an inference algorithm
19+\textsc{OutsideIn(X)}~\cite{Vytiniotis2011}, which is stratified into an
20+inference engine independent of the constraint
21+system, and a constraint solver for $X$. An additional difficulty faced by
22+Haskell, and hence any extensions, is the desire to support type \emph{inference}, in
23+which principal types may be inferred for top level functions. We have avoided
24+such difficulties since, in general, type
25+inference is undecidable for full dependent types. Indeed, it is not clear
26+that type inference is even desirable in many cases, as programmers
27+can use dependent types to state their intentions (hence a program
28+specification) more precisely. However in future work we
29+may consider adapting the \textsc{OutsideIn} approach to provide limited type
30+inference.
31+
32+An earlier implementation of \Idris{} was built on the \Ivor{} proof engine
1133\cite{Brady2006b}. This implementation differed in one important way --- unlike
12−the present implementation, there was limited separation between the type theory
13−and the high level language. The type theory itself supported implicit syntax and
14−unification, with high level constructs such as the \texttt{with} rule implemented
15−directly. Two important disadvantages were found with this approach, however:
16−firstly, the type checker is much more complicated when combined with
17−unification, making it harder to maintain; secondly, adding new high level features
18−requires the type checker to support those features directly. In contrast, elaboration
19−by tactics gives a clean separation between the low level and high level languages.
34+the present implementation, there was limited separation between the type
35+theory and the high level language. The type theory itself supported implicit
36+syntax and unification, with high level constructs such as the \texttt{with}
37+rule implemented directly. Two important disadvantages were found with this
38+approach, however: firstly, the type checker is much more complicated when
39+combined with unification, making it harder to maintain; secondly, adding new
40+high level features requires the type checker to support those features
41+directly. In contrast, elaboration by tactics gives a clean separation between
42+the low level and high level languages.
43+
44+Matita uses a bi-directional refinement algorithm~\cite{Asperti}. This is a
45+type directed approach, maintaining a set of yet to be solved unification
46+problems and relying on a small kernel, similar to the approach we now take
47+with \Idris{}, However, their approach uses refinement rules rather than
48+actics. This leads to good error messages though it is not clear how
49+easy it would be to extend to additional high level language features, unlike
50+the tactic based approach.
2051
2152The Agda implementation is based on a type theory with
2253implicit syntax and pattern matching --- Norell gives an algorithm for type checking
2354a dependently typed language with pattern matching and metavariables
2455\cite{norell2007thesis}. Unlike the present \Idris{} implementation, metavariables
2556and implicit arguments are part of the type theory. This has the advantage that
26−implicit arguments can be used more freely, at the expense of complicating the type
27−system.
57+implicit arguments can be used more freely (for example, in higher order
58+function arguments) at the expense of complicating the type system.
2859
2960Epigram \cite{McBride2004a} and Oleg \cite{McBride1999}
3061have provided much of the inspiration for the \Idris{} elaborator. Indeed,
@@ -38,7 +69,7 @@ optimisation opportunities \cite{Brady2003}. However, it requires the
3869implementation of extra machinery for constructor manipulation
3970\cite{McBride2006} and so we have avoided it in the present implementation.
4071
41−%Comparison with GHC's type system and type checker. \cite{Vytiniotis2011}
72+
4273
4374%[Observation: separate elaboration and type checking, sort of like in GHC which
4475%type checks the high level language and produces a type correct core language.
@@ -61,16 +92,17 @@ in under 1000 lines of Haskell code. It is important that this kernel remains sm
6192the correctness of the underlying type system, and keeping the implementation small
6293reduces the possibility of errors.
6394
64−The approach we have taken to implementing the high level language, implementing
65−a tactic language as an embedded DSL, allows us to
66−build programs on top of a small and unchanging kernel, rather than extending
67−the core language to deal with implicit syntax, unification and type classes.
68−High level \Idris{} features are implemented by describing the corresponding
69−sequence of tactics to build an equivalent program in \TT{}, via a development
70−calculus of incomplete terms, \TTdev{}. A significant advantage we have found with
71−this approach is that higher level features can easily be implemented in terms
72−of existing elaborator components. For example, once we have implemented elaboration
73−for data types and functions, it is easy to add several features:
95+The approach we have taken to implementing the high level language,
96+implementing an elaboration monad with tactics for program construction, allows
97+us to build programs on top of a small and unchanging kernel, rather than
98+extending the core language to deal with implicit syntax, unification and type
99+classes. High level \Idris{} features are implemented by describing the
100+corresponding sequence of tactics to build an equivalent program in \TT{}, via
101+a development calculus of incomplete terms, \TTdev{}. A significant advantage
102+we have found with this approach is that higher level features can easily be
103+implemented in terms of existing elaborator components. For example, once we
104+have implemented elaboration for data types and functions, it is easy to add
105+several features:
74106
75107\begin{itemize}
76108\item \textbf{Type classes}: A dictionary is merely a record containing the
@@ -89,19 +121,19 @@ implement these high level features.
89121Other high level features such as dependent records, tuples and monad comprehensions
90122can be added equally easily --- and indeed have been added in the full implementation.
91123Furthermore,
92−since we have used a tactic-based EDSL to elaborate \Idris{} to \TT{}, it is
93−possible to expose the tactic language to the programmer. This opens up the
94−possibility of implementing domain specific decision procedures, or implementing
95−user defined tactics in a style similar to Coq's \texttt{Ltac} language \cite{Delahaye2000}.
96−Although \TT{} is primarily intended as a core language for \Idris{},
97−its rich type system also allows it to capture a number of high level languages, especially
98−when augmented with primitive operators.
124+since we have taken a tactic-based approach to elaborating \Idris{} to \TT{},
125+it is possible to expose tactics to the programmer. This opens up
126+the possibility of implementing domain specific decision procedures, or
127+implementing user defined tactics in a style similar to Coq's \texttt{Ltac}
128+language \cite{Delahaye2000}. Although \TT{} is primarily intended as a core
129+language for \Idris{}, its rich type system also allows it to capture a number
130+of high level languages, especially when augmented with primitive operators.
99131
100132We have not discussed the performance of the elaboration
101133algorithm, or described how \Idris{} compiles to executable code. In practice,
102134we have found performance to be acceptable --- for example, the \Idris{}
103−library (25 files, 3532 lines of code in total at the time of writing)
104−elaborates in around 10 seconds\footnote{On a MacBook Pro, 2.8GHz Intel Core 2
135+library (31 files, 3718 lines of code in total at the time of writing)
136+elaborates in around 12 seconds\footnote{On a MacBook Pro, 2.8GHz Intel Core 2
105137Duo, 4Gb RAM}. Profiling suggests that the main bottleneck is locating holes
106138in a proof term, which can be improved by choosing a better representation
107139for proof terms, perhaps based on a zipper \cite{Huet1997}. Compilation is made
@@ -118,19 +150,10 @@ theory.
118150However, a programming language implementation is not an end in itself.
119151Programming languages exist to support research and practice in many different
120152domains. In future work, therefore, I plan to apply domain specific
121−language based techniques to realistic problems
122−in important safety critical domains such as security and network protocol
123−design and implementation. In order to be successful, this will require a language which
124−is expressive enough to describe protocol specifications at a high level, and robust
125−enough to guarantee correct implementation of those protocols. \Idris{}, I believe,
126−is the right tool for this work.
127−
128−
129−
130−%\subsection{Further Work}
153+language based techniques to realistic problems in important safety critical
154+domains such as security and network protocol design and implementation. In
155+order to be successful, this will require a language which is expressive enough
156+to describe protocol specifications at a high level, and robust enough to
157+guarantee correct implementation of those protocols. \Idris{}, I believe, is
158+the right tool for this work.
131159
132−%[Would the EDSL approach work in other languages? Adding components of DTP
133−%to imperative languages, say, using \TT{} as a verified core.
134−%\Idris{} implementation as the beginning of a project to explore practical
135−%DTP --- systems, protocols, security especially. And just having full
136−%dependent types for lightweight correctness guarantees.]
papers/impl-paper/elaboration.tex+793−408
@@ -1,4 +1,5 @@
11\newcommand{\ttinterp}[1]{\mathcal{E}\interp{#1}}
2+\newcommand{\ttpinterp}[1]{\mathcal{P}\interp{#1}}
23\newcommand{\uninterp}[1]{\mathcal{T}\interp{#1}}
34
45\section{Elaborating \Idris{}}
@@ -41,33 +42,42 @@ similar to a $\LET$ binding, but without any computational force,
4142i.e. there are no reduction rules for guess bindings.
4243Using binders to represent holes is useful in a dependently typed setting since
4344one value may determine another. Attaching a guess to a binder ensures that
44−instantiating one such value also instantiates all of its dependencies. The
45−typing rules for binders ensure that no $?$ bindings leak into types.
45+instantiating one such variable also instantiates all of its dependencies.
46+%The
47+%typing rules for binders ensure that no $?$ bindings leak into types.
4648
4749\FFIG{
48−\AR{
50+\begin{array}{c}
4951\vb ::= \ldots
50− \:\mid\: \hole{\vx}{\vt} \:\:(\mbox{hole binding}) \:\:
51− \:\mid\: \guess{\vx}{\vt}{\vt} \:\:(\mbox{guess})
52+ \;\mid\; \hole{\vx}{\vt} \;\;(\mbox{hole binding}) \;\;
53+ \;\mid\; \guess{\vx}{\vt}{\vt} \;\;(\mbox{guess})
5254\medskip\\
55+\mathsf{HoleVar}\;
56+\Rule{(\hole{\vx}{\vS})\in\Gamma}
57+{\Gamma\vdash\vx\Hab\vS}
58+\hg
59+\mathsf{GuessVar}\;
60+\Rule{(\guess{\vx}{\vS}{\vs})\in\Gamma}
61+{\Gamma\vdash\vx\Hab\vS}
62+\\
63+\mathsf{Hole}\;
5364\Rule{
5465\Gamma;\hole{\vx}{\vS}\proves\ve\Hab\vT
5566}
5667{
5768\Gamma\proves\hole{\vx}{\vS}\SC\ve\Hab\vT
5869}
59−\hspace*{0.1cm}\vx\not\in\vT
60−\hspace*{0.1in}\mathsf{Hole}
70+%\hspace*{0.1cm}\vx\not\in\vT
6171\hg
72+\mathsf{Guess}\;
6273\Rule{
6374\Gamma;\guess{\vx}{\vS}{\ve_1}\proves\ve_2\Hab\vT
6475}
6576{
6677\Gamma\proves\guess{\vx}{\vS}{\ve_1}\SC\ve_2\Hab\vT
6778}
68−\hspace*{0.1cm}\vx\not\in\vT
69−\hspace*{0.1in}\mathsf{Guess}
70−}
79+%\hspace*{0.1cm}\vx\not\in\vT
80+\end{array}
7181}
7282{\TTdev{} extensions}
7383{ttdev}
@@ -77,12 +87,23 @@ typing rules for binders ensure that no $?$ bindings leak into types.
7787
7888\label{sect:prfstate}
7989
80−A proof state is a tuple, $(\vC, \Delta, \ve, \vQ)$, containing:
90+We will build expressions in \TT{} from high level \Idris{} expressions by
91+creating a top level hole binding with the appropriate type, and refining it
92+according to the structure of the \Idris{} expression. Noting the Curry-Howard
93+correspondence between programs and proofs, and the relationship between our
94+method for elaboration and tactic
95+based theorem proving, we refer to a development as a \emph{proof}.
96+A proof state is a tuple, $(\vC, \Delta, \ve, \vP, \vQ)$, containing:
8197
8298\begin{itemize}
8399\item A global context, $\vC$, containing pattern matching definitions and their types
84100\item A local context, $\Delta$, containing pattern bindings
85101\item A proof term, $\ve$, in \TTdev{}
102+\item Unsolved unification problems, $\vP$
103+\begin{itemize}
104+\item These take the form $(\Gamma,\ve_1,\ve_2)$, i.e. the context in which
105+the problem is run, and the expressions to be unified.
106+\end{itemize}
86107\item A hole queue, $\vQ$
87108%\item \remph{Deferred} definitions, $\vD$, for introducing global metavariables
88109\end{itemize}
@@ -91,29 +112,49 @@ The \remph{hole queue} is a priority queue of names of hole and guess binders
91112$\langle\vx_1,\vx_2,\ldots,\vx_n\rangle$
92113in the proof term ---
93114ensuring that each bound name is unique. Holes refer to \remph{sub goals}
94−in the proof.
95−When this queue is empty, the proof term is complete.
115+in the proof. As a proof develops, unification problems arising from unsolved
116+holes may be introduced, and may be solved when those holes are instantiated.
117+When the hole queue is empty, and there are no remaining unification
118+problems, the proof term is complete.
119+
96120Creating a \TT{} expression from an \Idris{} expression involves creating
97121a new proof state, with an empty proof term, and using the high level definition
98122to direct the building of a final proof state, with a complete proof term.
99123
100124In the implementation, the proof state is captured in an elaboration monad,
101−\texttt{Elab}, which includes various operations for querying and updating
102−the proof state, manipulating terms, generating fresh names, etc. However, we will
103−describe \Idris{} elaboration in terms of meta-operations on the proof state,
104−in order to capture the essence of the elaboration process without being distracted
105−by implementation details. These meta-operations include:
125+\texttt{Elab}, which is simply a state monad with exceptions.
126+Exceptions are captured by the option type $\MO{Result}$ which
127+either indicates success, or reports an error $\MO{Err}$:
128+
129+\DM{
130+\RW{data}\;\MO{Result}\;\vt\;=\;\MO{Success}\;\vt\;\mid\;\MO{Failure}\;\MO{Err}
131+}
132+
133+\noindent
134+If any operation fails during a proof (e.g. a subterm fails to type check)
135+then the entire proof fails (i.e. returns $\MO{Failure}\;\ve$ with some error
136+message $\ve$) unless otherwise handled.
137+
138+The \texttt{Elab} monad supports various operations for querying and updating
139+the proof state, manipulating terms, generating fresh names, etc. However, we
140+will describe \Idris{} elaboration in terms of meta-operations on the proof
141+state, in order to capture the essence of the elaboration process without being
142+distracted by implementation details. These meta-operations include:
106143
107144\begin{itemize}
108145\item \demph{Queries} which retrieve values from the proof state, without modifying
109146the state. For example, we can:
110147\begin{itemize}
111−\item Get the type of the current sub goal ($\MO{Type}$)
112−\item Retrieve the local context $\Gamma$ at the current sub goal ($\MO{Context}$)
113−\item Type check ($\MO{Check}$) or normalise ($\MO{Normalise}$) a term relative to $\Gamma$
148+\item Get the type of the current sub goal ($\MO{Type}$).
149+\item Get the current proof term ($\MO{Term}$).
150+\item Retrieve the local context $\Gamma$ at the current sub goal
151+($\MO{Context}$).
152+\item Type check ($\MO{Check}$) or normalise ($\MO{Normalise}$) a term relative
153+to $\Gamma$.
114154\end{itemize}
115−\item \demph{Unification}, which unifies two terms (potentially solving sub goals)
116−relative to $\Gamma$
155+\item \demph{Unification}, which unifies two terms (potentially solving sub
156+goals) relative to $\Gamma$. This may introduce new unification problems
157+to the proof state.
117158\item \demph{Tactics} which update the proof term. Tactics operate on the sub term
118159at the binder specified by the head of the hole queue $\vQ$.
119160\item \demph{Focussing} on a specific sub goal, which brings a different sub goal to the
@@ -122,117 +163,122 @@ head of the hole queue.
122163%$\vC$ which solves the sub goal.
123164\end{itemize}
124165
125−Elaboration of an \Idris{} expression involves creating a new proof state, running
126−a series of tactics to build a complete proof term, then retrieving and \remph{rechecking}
127−the final proof term, which must be a \TT{} program (i.e. does not contain any of the
128−\TTdev{} extensions). We call a sub-term which contains no hole or guess bindings
129−\demph{pure}. Although a pure term does not contain hole or guess bindings, it may
130−nevertheless \remph{refer} to hole- or guess-bound variables.
166+Elaboration of an \Idris{} expression involves creating a new proof state,
167+running a series of tactics to build a complete proof term, then retrieving and
168+\remph{rechecking} the final proof term, which must be a \TT{} program (i.e.
169+does not contain any of the \TTdev{} extensions). We call a sub-term which
170+contains no hole or guess bindings \demph{pure}. Although a pure term does not
171+contain hole or guess bindings, it may nevertheless \remph{refer} to hole- or
172+guess-bound variables.
131173
132−The proof state is initialised with the $\MO{NewProof}$ operation. Given a global
133−context $\vC$, $\MO{NewProof}\:\vt$ sets up the proof state as:
174+The proof state is initialised with the $\MO{NewProof}$ operation. Given a
175+global context $\vC$, $\MO{NewProof}\;\vt$ sets up the proof state as:
134176
135177\DM{
136−(\vC, \cdot, \hole{\vx}{\vt}\SC\vx, \langle\vx\rangle)
178+(\vC, \cdot, \hole{\vx}{\vt}\SC\vx, \langle\rangle, \langle\vx\rangle)
137179}
138180
139181The local context is initially empty, and the initial hole queue is the $\vx$ standing for
140182the entire expression. The proof term is reset with the $\MO{NewTerm}$ operation.
141183In an existing proof state $(\vC, \Delta, \ve, \vQ)$,
142−$\MO{NewTerm}\:\vt$ discards the proof term and hole queue, and
184+$\MO{NewTerm}\;\vt$ discards the proof term and hole queue, and
143185updates the proof state to:
144186
145187\DM{
146−(\vC, \Delta, \hole{\vx}{\vt}\SC\vx, \langle\vx\rangle)
188+(\vC, \Delta, \hole{\vx}{\vt}\SC\vx, \langle\rangle, \langle\vx\rangle)
147189}
148190
149−
150−This allows the elaborator to use pattern bindings from the left
191+Resetting the term and queue but retaining pattern bindings
192+allows the elaborator to use pattern bindings from the left
151193hand side of a pattern matching definition in the term on the right hand side.
152194
153−\subsection{System State}
154−
155−\label{sect:sysstate}
156−
157−The system state is a tuple, $(\vC,\vA,\vI)$, containing:
158−
159−\begin{itemize}
160−\item A global context, $\vC$, containing pattern matching definitions and their types
161−\item Implicit arguments, $\vA$, recording which arguments are implicit for each global name
162−\item Type class instances, $\vI$, containing dictionaries for type classes
163−\end{itemize}
164−
165−In the implementation, the system state is captured in a monad, \texttt{Idris},
166−which also wraps the current proof state. This monad
167−includes additional information such as syntax overloadings,
168−command line options, and optimisations, which do not concern us here. Elaboration
169−of expressions requires access to the system state in particular in order to expand
170−implicit arguments and resolve type classes.
171−
172−For each global name, $\vA$ records whether its arguments are explicit, implicit,
173−or type class constraints. For example, recall the declaration
174−of \texttt{vAdd}:
175−
176−\begin{SaveVerbatim}{vAddImpT}
177−
178−vAdd : Num a => Vect a n -> Vect a n -> Vect a n
179−
180−\end{SaveVerbatim}
181−\useverb{vAddImpT}
182−
183−\noindent
184−Written in full, and giving each argument an explicit name, we get the
185−type declaration:
186−
187−\begin{SaveVerbatim}{vAddImpT}
188−
189−vAdd : (a : _) -> (n : _) -> (c : Num a) ->
190− (xs : Vect a n) -> (ys : Vect a n) -> Vect a n
191−
192−\end{SaveVerbatim}
193−\useverb{vAddImpT}
194−
195−\noindent
196−For \tFN{vAdd}, the state records that \texttt{a} and \texttt{n} are implicit,
197−\texttt{c} is a constraint, and \texttt{xs} and \texttt{ys} are explicit. When
198−the elaborator encounters an application of \tFN{vAdd}, it knows that unless these arguments
199−are given explicitly, the application must be expanded.
200195
201196\newcommand{\Check}{\MO{Check}_\Gamma}
202197\newcommand{\Eval}{\MO{Normalise}_\Gamma}
203198\newcommand{\Unify}{\MO{Unify}_\Gamma}
199+\newcommand{\PrimUnify}{\MO{PrimUnify}_\Gamma}
200+\newcommand{\Subst}{\MO{Subst}}
204201
205202\subsection{Tactics}
206203
207204% Meta-operations Check, Normalise, Unify
208205In order to build \TT{} expressions from \Idris{} programs, we define a collection
209206of meta-operations for querying and modifying the proof state. Meta-operations
210−may have side-effects including failure, or updating the proof state. We have the following
211−primitive meta-operations:
207+may have side-effects including failure, or updating the proof state, and
208+may fail. We have the following primitive meta-operations:
212209
213210\begin{itemize}
214−\item $\MO{Focus}\:\vn$, which moves $\vn$ to the head of the hole queue.
215−\item $\MO{Unfocus}$, which moves the current hole to the back of the hole queue.
216−\item $\Check\:\ve$, which type checks an expression $\ve$ relative to a context
211+\item $\MO{Get}$ and $\MO{Put}$ which allow direct access to the proof state.
212+% Focus and Unfocus don't need to be primitive, we could show in terms of
213+% Get and Put
214+%\item $\MO{Focus}\;\vn$, which moves $\vn$ to the head of the hole queue.
215+%\item $\MO{Unfocus}$, which moves the current hole to the back of the hole queue.
216+\item $\Check\;\ve$, which type checks an expression $\ve$ relative to a context
217217$\Gamma$, returning its type.
218218$\MO{Check}$ will fail
219219if the expression is not well-typed.
220−\item $\Eval\:\ve$, which evaluates a well-typed expression $\ve$ relative to a context
221−$\Gamma$, returning its normal form.
220+\item $\Eval\;\ve$, which evaluates a well-typed expression $\ve$ relative to a context
221+$\Gamma$, returning its normal form. $\MO{Normalise}$ reduces under binders,
222+but does not reduce definitions which are not total.
222223\item
223−$\Unify\:\ve_1\:\ve_2$,
224−which unifies $\ve_1$ and $\ve_2$ by finding the values with which holes must be instantiated
225−for $\ve_1$ and $\ve_2$ to be convertible relative to $\Gamma$
226−(i.e. for $\Gamma\proves\ve_1\converts\ve_2$ to hold). $\MO{Unify}$ will fail
227−if it cannot find such values. If successful, $\MO{Unify}$ will update the proof state.
224+$\PrimUnify\;\ve_1\;\ve_2$,
225+which attempts to unify $\ve_1$ and $\ve_2$ by finding the values with which
226+holes must be instantiated for $\ve_1$ and $\ve_2$ to be convertible relative
227+to $\Gamma$ (i.e. for $\Gamma\proves\ve_1\converts\ve_2$ to hold).
228+\item $\Subst\;\vx\;\ve$, which instantiates a hole $\vx$ directly with a term
229+$\ve$, typically arising from unification.
228230\end{itemize}
229231
230−\demph{Tactics} are meta-operations which operate on the sub-term given
231−by the hole at the head of the hole queue in the proof state. They take the following form:
232+\noindent
233+Additionally, we have $\MO{Focus}$, $\MO{Unfocus}$, $\MO{NewHole}$
234+and $\MO{NextHole}$
235+operations which manipulate and inspect
236+the hole queue. $\MO{Focus}\;\vn$ moves a hole to the head of the hole queue:
237+
238+\DM{
239+\MO{Focus}\;\vn\;=\;\RW{do}\;\AR{
240+(\vC,\Delta,\vP,\vQ;\vn;\vQ')\gets\MO{Get}\\
241+\MO{Put}\;(\vC,\Delta,\vP,\vn;\vQ;\vQ')\\
242+}
243+}
244+
245+\noindent
246+Correspondingly, $\MO{Unfocus}$ moves the currently in focus hole to the
247+end of the hole queue:
248+
249+\DM{
250+\MO{Unfocus}\;=\;\RW{do}\;\AR{
251+(\vC,\Delta,\vP,\vn;\vQ)\gets\MO{Get}\\
252+\MO{Put}\;(\vC,\Delta,\vP,\vQ;\vn)\\
253+}
254+}
255+
256+\noindent
257+$\MO{NewHole}$ declares that a new hole has been created and is to be solved
258+next, and $\MO{NextHole}$ returns the next hole to be solved:
259+
260+\DM{
261+\AR{
262+\MO{NewHole}\;=\;\RW{do}\;\AR{
263+(\vC,\Delta,\vP,\vQ)\gets\MO{Get}\\
264+\MO{Put}\;(\vC,\Delta,\vP,\vn;\vQ)\\
265+}
266+\\
267+\MO{NextHole}\;=\;\RW{do}\;\AR{
268+(\vC,\Delta,\vP,\vn;\vQ)\gets\MO{Get}\\
269+\MO{Return}\;\vn
270+}
271+}
272+}
273+
274+\noindent
275+\demph{Tactics} are meta-operations which operate on the sub-term given by the
276+hole at the head of the hole queue in the proof state. They take the following
277+form:
232278
233279\DM{
234280\PA{\A\A}{
235−\MO{Tactic}_\Gamma & \:\vec{\VV{args}} & \:\vt & \MoRet{\vt'}
281+\MO{Tactic}_\Gamma & \;\vec{\VV{args}} & \;\vt & \MoRet{\vt'}
236282}
237283}
238284
@@ -246,9 +292,117 @@ well-typed, with a type convertible to the type of $\vt$.
246292Tactics may also have the side effect of updating the proof state,
247293therefore we will describe tactics in a pseudo-code with $\RW{do}$ notation.
248294
249−We define a set of primitive tactics: $\MO{Claim}$, $\MO{Fill}$ and $\MO{Solve}$
250−which are used to create and destroy holes; and $\MO{Lambda}$, $\MO{Pi}$, $\MO{Let}$
251−and $\MO{Attack}$ which are used to create binders.
295+Tactics are executed by a higher level meta-operation $\MO{Tactic}$,
296+given in Figure \ref{runtac} which
297+locates the appropriate sub-term, applies the tactic with the context
298+local to this sub-term, and
299+replaces the sub-term with the term returned by the
300+tactic.
301+% It then updates the hole queue in the proof state, and updates holes which have
302+% been solved by unification. If the tactic creates new holes, these are automatically
303+% added to the \remph{head} of the hole queue.
304+
305+\FFIG{
306+\AR{
307+\MO{Tactic}\;\VV{tac}\;=\;\RW{do}\;\AR{
308+\ve\Gets\MO{Term}\\
309+\vh\Gets\MO{NextHole}\\
310+\ve'\Gets\MO{Tactic'}\;\langle\rangle\;\ve\;\VV{tac}\;\vh\\
311+\MO{SetTerm}\;\ve'
312+}
313+\medskip
314+\\
315+\PA{\A\A\A}{
316+\RW{where} \\
317+& \MO{Tactic'} & \Gamma & (\hole{\vx}{\vT}\SC\ve)
318+& \MoRet{\VV{tac}_\Gamma\;(\hole{\vx}{\vT}\SC\ve)\hg\mbox{if}\;\vx=\vh} \\
319+& \MO{Tactic'} & \Gamma & (\guess{\vx}{\vT}{\vv}\SC\ve)
320+& \MoRet{\VV{tac}_\Gamma\;(\guess{\vx}{\vT}{\vv}\SC\ve)\hg\mbox{if}\;\vx=\vh} \\
321+& \MO{Tactic'} & \Gamma & (\lam{\vx}{\vT}\SC\ve)
322+& \MoRet{
323+\RW{do}\; \AR{\vT'\Gets\;\MO{Tactic'}\;\Gamma\;\vT\\
324+\lam{\vx}{\vT'}\SC \MO{Tactic'}\;(\Gamma;\lam{\vx}{\vT'})\;\ve}
325+}
326+\\
327+& \MO{Tactic'} & \Gamma & (\all{\vx}{\vT}\SC\ve)
328+& \MoRet{
329+\RW{do}\; \AR{\vT'\Gets\;\MO{Tactic'}\;\Gamma\;\vT\\
330+\all{\vx}{\vT'}\SC \MO{Tactic'}\;(\Gamma;\all{\vx}{\vT'})\;\ve}
331+}
332+\\
333+& \MO{Tactic'} & \Gamma & (\LET\;\vx\defq\vt\Hab\vT\SC\ve)
334+& \MoRet{\RW{do}\;\AR{\vt'\Gets\;\MO{Tactic'}\;\Gamma\;\vt\\
335+\vT'\Gets\;\MO{Tactic'}\;\Gamma\;\vT\\
336+\LET\;\vx\defq\vt'\Hab\vT'\SC
337+\MO{Tactic'}\;(\Gamma;\LET\;\vx\defq\vt'\Hab\vT')\;\ve}} \\
338+& \MO{Tactic'} & \Gamma & (\vf\;\va) &
339+\MoRet{\MO{Return}\;(\MO{Tactic'}\;\Gamma\;\vf)\; (\MO{Tactic'}\;\Gamma\;\va)}\\
340+& \MO{Tactic'} & \Gamma & \vt & \MoRet{\MO{Return}\;\vt}
341+}
342+}
343+}
344+{Applying tactics to the proof state}
345+{runtac}
346+
347+In the remainder of this section, we will define a set of primitive tactics:
348+$\MO{Claim}$, $\MO{Fill}$ and $\MO{Solve}$ which are used to create and destroy
349+holes; and $\MO{Lambda}$, $\MO{Pi}$, $\MO{Let}$ and $\MO{Attack}$ which are
350+used to create binders. First, however, we must explain how unification is
351+applied during elaboration.
352+
353+\subsubsection{Unification}
354+
355+Unification is crucial to the success of elaboration --- it is unification
356+which finds values of implicit arguments, in particular. We do not require
357+unification to succeed immediately, in general, as instantiating a hole may
358+affect the solution to other unification problems. Instead,
359+$\MO{PrimUnify}$ may give one of the following results:
360+
361+\begin{itemize}
362+\item $\MO{Success}\;(\tx=\te, \tp)$, containing the solved holes mapping
363+$\vx$ to $\ve$, and a possibly empty set of blocked unification problems $\tp$.
364+If $\tp$ is empty, there is a solution for $\ve_1$ and $\ve_2$.
365+\item $\MO{Failure}\;\ve$, if no solution is found due to a failure to unify
366+sub-terms in normal form.
367+\end{itemize}
368+
369+$\MO{Unify}$ attempts to solve the given unification problem using
370+$\MO{PrimUnify}$,
371+then attempts to further refine existing problems in the proof
372+state. This operation is given in Figure \ref{unifyps}. After attempting to
373+solve the problem with $\MO{PrimUnify}$ and updating the proof term with
374+any solutions found, it updates the existing problems (with $\MO{SubstProblems}$
375+which applies $\MO{Subst}$ across the terms in the problems), then attempts to
376+resolve the existing problems with $\MO{ReUnify}$.
377+
378+\FFIG{
379+%\mbox{\textbf{[UNIFY ALGORITHM GOES HERE] }}
380+%Show how it uses a PrimUnify
381+%operation to update
382+%the proof state with new problems, and solve the old ones
383+\AR{
384+\Unify\;\ve_1\;\ve_2\;=\;\RW{do}\;
385+\AR{
386+(\tx=\te,\tp)\gets\PrimUnify\;\ve_1\;\ve_2\\
387+\vec{\MO{Subst}}\;\tx\;\te\\
388+\MO{SubstProblems}\;(\tx=\te)\\
389+(\vC,\Delta,\VV{term},\tP,\vQ)\gets\MO{Get}\\
390+\vec{\MO{ReUnify}}\;\tP
391+}
392+\medskip
393+\\
394+\AR{
395+\MO{ReUnify}\;(\Gamma,\ve_1,\ve_2)\;=\;\RW{do}\;\AR{
396+(\tx=\te,\tp)\Gets\PrimUnify\;\ve_1\;\ve_2\\
397+\vec{\MO{Subst}}\;\tx\;\te\\
398+\MO{Return}\;\tp
399+}
400+}
401+}
402+}
403+{The $\MO{Unify}$ meta-operation}
404+{unifyps}
405+
252406
253407\subsubsection{Creating and destroying holes}
254408
@@ -259,7 +413,7 @@ keeping $\vx$ at the head:
259413\DM{
260414\PA{\A\A}{
261415\MO{Claim}_\Gamma & (\vy \Hab\vS) & (\hole{\vx}{\vT}\SC\ve) &
262− \MoRet{\RW{return}\:\hole{\vx}{\vT}\SC\hole{\vy}{\vS}\SC\ve} \\
416+ \MoRet{\RW{return}\;\hole{\vx}{\vT}\SC\hole{\vy}{\vS}\SC\ve} \\
263417}
264418}
265419
@@ -275,10 +429,10 @@ solve other holes by unifying the expected type of $\vx$ with the type of $\vv$:
275429\DM{
276430\PA{\A\A}{
277431\MO{Fill}_\Gamma & \vv & (\hole{\vx}{\vT}\SC\ve) &
278− \MoRet{\RW{do}\:\AR{
279− \vT' \leftarrow \Check\:\vv\\
280− \Unify\:\vT\:\vT'\\
281− \RW{return}\:\guess{\vx}{\vT}{\vv'}\SC\ve}
432+ \MoRet{\RW{do}\;\AR{
433+ \vT' \leftarrow \Check\;\vv\\
434+ \Unify\;\vT\;\vT'\\
435+ \RW{return}\;\guess{\vx}{\vT}{\vv}\SC\ve}
282436 } \\
283437}
284438}
@@ -288,10 +442,10 @@ For example, consider the following proof term:
288442
289443\DM{
290444\AR{
291−\hole{\vA}{\Set}\SC\hole{\vk}{\Nat}\SC
292−\hole{\vx}{\vA}\SC\hole{\vxs}{\Vect\:\vA\:\vk}\SC
445+\hole{\vA}{\Type}\SC\hole{\vk}{\Nat}\SC
446+\hole{\vx}{\vA}\SC\hole{\vxs}{\Vect\;\vA\;\vk}\SC
293447\\
294−\hole{\vys}{\Vect\:\vA\:(\suc\:\vk)}\SC\vys
448+\hole{\vys}{\Vect\;\vA\;(\suc\;\vk)}\SC\vys
295449}
296450}
297451
@@ -301,9 +455,9 @@ attempts to
301455$\MO{Fill}$ it with an $\TC{Int}$ value $42$, we have:
302456
303457\begin{itemize}
304−\item $\Check\:42\:\mq\:\TC{Int}$
458+\item $\Check\;42\;\mq\;\TC{Int}$
305459\item Unifying $\TC{Int}$ with $\vA$ (the type of $\vx$) is only possible if
306−$\vA\:=\:\TC{Int}$, so solve $\vA$.
460+$\vA\;=\;\TC{Int}$, so solve $\vA$.
307461\end{itemize}
308462
309463\noindent
@@ -312,9 +466,9 @@ Therefore the resulting proof term is:
312466\DM{
313467\AR{
314468\hole{\vk}{\Nat}\SC
315−\guess{\vx}{\TC{Int}}{42}\SC\hole{\vxs}{\Vect\:\TC{Int}\:\vk}\SC
469+\guess{\vx}{\TC{Int}}{42}\SC\hole{\vxs}{\Vect\;\TC{Int}\;\vk}\SC
316470\\
317−\hole{\vys}{\Vect\:\TC{Int}\:(\suc\:\vk)}\SC\vys
471+\hole{\vys}{\Vect\;\TC{Int}\;(\suc\;\vk)}\SC\vys
318472}
319473}
320474
@@ -325,7 +479,7 @@ the guess is substituted into its scope:
325479\DM{
326480\PA{\A}{
327481\MO{Solve}_\Gamma & (\guess{\vx}{\vT}{\vv}\SC\ve) &
328− \MoRet{\RW{return}\:\ve[\vv/\vx]\hg\mbox{(if $\MO{Pure}\:\vv$)}}
482+ \MoRet{\RW{return}\;\ve[\vv/\vx]\hg\mbox{(if $\MO{Pure}\;\vv$)}}
329483}
330484}
331485
@@ -335,14 +489,16 @@ computational force. Once a term is complete in a guess binding, it may be subst
335489scope of the binding safely.
336490In each of these tactics, if any step fails, or the term in focus does not take
337491the correct form (e.g. is not a guess in the case of $\MO{Solve}$ or not a hole
338−in the case of $\MO{Claim}$ and $\MO{Fill}$, the entire tactic fails. We can
492+in the case of $\MO{Claim}$ and $\MO{Fill}$) the entire tactic fails. We can
339493handle failure using the $\MO{Try}$ tactic combinator:
340494
341495\DM{
342496\PA{\A\A\A}{
343497\MO{Try}_\Gamma & \VV{t1} & \VV{t2} & \vt &
344− \MoRet{\AR{\VV{t1}_\Gamma\:\vt\hg\mbox{(if $\VV{t1}$ succeeds)} \\
345− \VV{t2}_\Gamma\:\vt\hg\mbox{(otherwise)}}}
498+ \MoRet{\RW{case}\;\AR{\VV{t1}_\Gamma\;\vt\;\RW{of}\\
499+ \MO{Success}\;\vt'\cq\MO{Success}\;\vt'\\
500+ \MO{Failure}\;\_\cq\VV{t2}_\Gamma\;\vt\\
501+ }}
346502}
347503}
348504
@@ -358,23 +514,23 @@ binding requires that the goal normalises to a function type:
358514\DM{
359515\PA{\A\A}{
360516\MO{Lambda}_\Gamma & \vn & (\hole{\vx}{\vT}\SC\vx) &
361− \MoRet{\RW{do}\:\AR{
362− \all{\vy}{\vS}\SC\vT'\:\leftarrow\:\Eval\:\vT \\
363− \RW{return}\:\lam{\vn}{\vS}\SC\hole{\vx}{\vT'[\vn/\vy]}\SC\vx
517+ \MoRet{\RW{do}\;\AR{
518+ \all{\vy}{\vS}\SC\vT'\;\leftarrow\;\Eval\;\vT \\
519+ \RW{return}\;\lam{\vn}{\vS}\SC\hole{\vx}{\vT'[\vn/\vy]}\SC\vx
364520 }
365521 }
366522}
367523}
368524
369525\noindent
370−Creating a $\forall$ binding requires that the goal is a $\TC{Set}$:
526+Creating a $\forall$ binding requires that the goal is a $\TC{Type}$:
371527
372528\DM{
373529\PA{\A\A}{
374−\MO{Pi}_\Gamma & (\vn\Hab\vS) & (\hole{\vx}{\Set}\SC\vx) &
375− \MoRet{\RW{do}\:\AR{
376− \Set\:\leftarrow\:\Check\:\vS\\
377− \RW{return}\:\all{\vn}{\vS}\SC\hole{\vx}{\Set}\SC\vx
530+\MO{Pi}_\Gamma & (\vn\Hab\vS) & (\hole{\vx}{\Type}\SC\vx) &
531+ \MoRet{\RW{do}\;\AR{
532+ \Type\;\leftarrow\;\Check\;\vS\\
533+ \RW{return}\;\all{\vn}{\vS}\SC\hole{\vx}{\Type}\SC\vx
378534 }
379535 }
380536}
@@ -386,11 +542,11 @@ Creating a $\LET$ binding requires a type and a value.
386542\DM{
387543\PA{\A\A}{
388544\MO{Let}_\Gamma & (\vn\Hab\vS\defq\vv) & (\hole{\vx}{\vT}\SC\vx) &
389− \MoRet{\RW{do}\:\AR{
390− \Set\:\leftarrow\:\Check\:\vS\\
391− \vS'\:\leftarrow\:\Check\:\vv\\
392− \Unify\:\vS\:\vS'\\
393− \RW{return}\:\LET\:\vn\Hab\vS\defq\vv\SC\hole{\vx}{\vT}\SC\vx
545+ \MoRet{\RW{do}\;\AR{
546+ \Type\;\leftarrow\;\Check\;\vS\\
547+ \vS'\;\leftarrow\;\Check\;\vv\\
548+ \Unify\;\vS\;\vS'\\
549+ \RW{return}\;\LET\;\vn\Hab\vS\defq\vv\SC\hole{\vx}{\vT}\SC\vx
394550 }
395551 }
396552}
@@ -400,17 +556,56 @@ Each of these tactics require the term in focus to be of the form $\hole{\vx}{\v
400556This is important, because if the scope of the binding were an arbitrary expression $\ve$,
401557the binder would be scoped across this \emph{whole} expression rather than the subexpression
402558$\vx$ as intended.
403−The $\MO{attack}$ tactic ensures that a hole
404−is in the appropriate form, creating a new hole $\vh$ which is placed at the head
405−of the queue:
559+The $\MO{Attack}$ tactic ensures that a hole
560+is in the appropriate form, creating a new hole $\vx'$ which is placed at the
561+head of the queue:
406562
407563\DM{
408564\PA{\A}{
409565\MO{Attack}_\Gamma & (\hole{\vx}{\vT}\SC\ve) &
410− \MoRet{\RW{return}\:\guess{\vx}{\vT}{(\hole{\vh}{\vT}\SC\vh)}\SC\ve}
566+ \MoRet{\RW{do}\;\AR{
567+ \MO{NewHole}\;\vx'\\
568+ \RW{return}\;\guess{\vx}{\vT}{(\hole{\vx'}{\vT}\SC\vx')}\SC\ve}}
569+}
570+}
571+
572+\noindent
573+For example, consider the following proof term:
574+
575+\DM{
576+\hole{\vx}{\va\to\vb}\SC\vx\;\ve
411577}
578+
579+\noindent
580+If we try to instantiate $\vx$ with a $\lambda$-binding $\vn$ immediately,
581+without applying $\MO{Attack}$ first, the $\lambda$ will scope over the
582+entirety of $\vx\;\ve$, and the resulting term is not well-typed:
583+
584+\DM{
585+\AR{
586+\lam{\vn}{\va}\SC\hole{\vx}{\vb}\SC\vx\;\ve
587+}
588+}
589+
590+\noindent
591+If, on the other hand, we $\MO{Attack}$ the hole then instantiate it with
592+a $\lambda$ binding $\vn$, we get:
593+
594+\DM{
595+\begin{array}{ll}
596+\guess{\vx}{\va\to\vb}{\hole{\vx'}{\va\to\vb}\SC\vx'}\SC\vx\;\ve
597+& \hg\mbox{(after $\MO{Attack}$)}\\
598+\guess{\vx}{\va\to\vb}{\lam{\vn}{\va}\SC\hole{\vx'}{\vb}\SC\vx'}\SC\vx\;\ve
599+& \hg\mbox{(after $\MO{Lambda}\;\vn$)}
600+\end{array}
412601}
413602
603+\noindent
604+Now, once $\vx'$ has been instantiated, the guess for $\vx$ can safely be
605+closed with $\MO{Solve}$.
606+
607+\subsubsection{Pattern Binders}
608+
414609Finally, we can convert a hole binding to a pattern binding by giving the
415610pattern variable a name. This solves a hole
416611by adding the pattern binding to the proof state, and updating the proof term
@@ -419,9 +614,9 @@ with the pattern variable directly:
419614\DM{
420615\PA{\A\A}{
421616\MO{Pat}_\Gamma & \vn & (\hole{\vx}{\vT}\SC\ve) &
422− \MoRet{\RW{do}\:\AR{
423− \MO{PatBind}\:(\vx\Hab\vT)\\
424− \RW{return}\:\ve[\vn/\vx]
617+ \MoRet{\RW{do}\;\AR{
618+ \MO{PatBind}\;(\vn\Hab\vT)\\
619+ \RW{return}\;\ve[\vn/\vx]
425620 }}
426621}
427622}
@@ -433,54 +628,174 @@ building the right hand side.
433628
434629\subsubsection{Example}
435630
436−Tactics are executed by a higher level meta-operation $\MO{RunTac}$, which
437−locates the appropriate sub-term, applies the tactic with the context
438−local to this sub-term, and
439−replaces the sub-term with the term returned by the
440−tactic. It then updates the hole queue in the proof state, and updates holes which have
441−been solved by unification. If the tactic creates new holes, these are automatically
442−added to the \remph{head} of the hole queue.
443−For example, consider the following simple
631+To illustrate how tactics are applied, using $\MO{Tactic}$, to build a
632+complete term by refining a proof state, let us consider the following
444633\TT{} definition for the identify function:
445634
446635\DM{
447636\AR{
448−\FN{id}\Hab\all{\vA}{\Set}\SC\all{\va}{\vA}\SC\vA \\
449−\FN{id}\:=\:\lam{\vA}{\Set}\SC\lam{\va}{\vA}\SC\va
637+\FN{id}\Hab\all{\vA}{\Type}\SC\all{\va}{\vA}\SC\vA \\
638+\FN{id}\;=\;\lam{\vA}{\Type}\SC\lam{\va}{\vA}\SC\va
450639}
451640}
452641
453−We can build $\FN{id}$ either as a complete term, or by applying a sequence of tactics.
454−To achieve this, we create a proof state initialised with the type of $\FN{id}$ and
455−apply a series of $\MO{Lambda}$ and $\MO{Fill}$ operations using $\MO{RunTac}$.
456−Note that the types on each $\MO{Lambda}$ are solved by unification:
642+We can build $\FN{id}$ either as a complete term, or by applying a sequence of
643+tactics. To achieve this, we create a proof state initialised with the type of
644+$\FN{id}$ and apply a series of $\MO{Lambda}$ and $\MO{Fill}$ operations using
645+$\MO{Tactic}$. Note that the types on each $\MO{Lambda}$ are taken from
646+the goal type.
457647
458648\DM{
459649\AR{
460−\MO{MkId}\:\mq\:\RW{do}\:
650+\MO{MkId}\;\mq\;\RW{do}\;
461651 \AR{
462− \MO{NewProof}\:\all{\vA}{\Set}\SC\all{\va}{\vA}\SC\vA \\
463− \MO{RunTac}\;\MO{Attack} \\
464− \MO{RunTac}\;(\MO{Lambda}\;\vA) \\
465− \MO{RunTac}\;\MO{Attack} \\
466− \MO{RunTac}\;(\MO{Lambda}\;\va) \\
467− \MO{RunTac}\;(\MO{Fill}\;\va)\\
468− \MO{RunTac}\;\MO{Solve}\\
469− \MO{RunTac}\;\MO{Solve}\\
470− \MO{RunTac}\;\MO{Solve}\\
652+ \MO{NewProof}\;\all{\vA}{\Type}\SC\all{\va}{\vA}\SC\vA \\
653+ \MO{Tactic}\;\MO{Attack} \\
654+ \MO{Tactic}\;(\MO{Lambda}\;\vA) \\
655+ \MO{Tactic}\;\MO{Attack} \\
656+ \MO{Tactic}\;(\MO{Lambda}\;\va) \\
657+ \MO{Tactic}\;(\MO{Fill}\;\va)\\
658+ \MO{Tactic}\;\MO{Solve}\\
659+ \MO{Tactic}\;\MO{Solve}\\
660+ \MO{Tactic}\;\MO{Solve}\\
471661 \MO{Term}
472662 }
473663}
474664}
475665
476−To aid readability, we will elide $\MO{RunTac}$, and use a semi-colon to indicate
666+\FFIG{
667+\begin{array}{lll}
668+\mbox{\textbf{Tactic}} & \mbox{\textbf{Resulting Proof Term}} &
669+\mbox{\textbf{Queue}}
670+\medskip
671+\\
672+\mbox{Initial state}
673+& \hole{\vx}{\all{\vA}{\Type}\SC\all{\va}{\vA}\SC\vA}\SC\vx
674+& \langle\vx\rangle \\
675+%
676+\MO{Attack} &
677+\underline{
678+\guess{\vx}{\all{\vA}{\Type}\SC\all{\va}{\vA}\SC\vA}{
679+\hole{\vh_0}{\all{\vA}{\Type}\SC\all{\va}{\vA}\SC\vA}\SC\vh_0
680+}
681+\SC\vx
682+}
683+&
684+\langle\vh_0,\vx\rangle\\
685+%
686+\MO{Lambda}\;\vA &
687+\guess{\vx}{\all{\vA}{\Type}\SC\all{\va}{\vA}\SC\vA}{
688+\underline{
689+\lam{\vA}{\Type}\SC\hole{\vh_0}{\all{\va}{\vA}\SC\vA}\SC\vh_0
690+}
691+}
692+\SC\vx
693+&
694+\langle\vh_0,\vx\rangle\\
695+%
696+\MO{Attack} &
697+\guess{\vx}{\all{\vA}{\Type}\SC\all{\va}{\vA}\SC\vA}{
698+\lam{\vA}{\Type}\SC
699+\underline{
700+\guess{\vh_0}{\all{\va}{\vA}\SC\vA}
701+{\hole{\vh_1}{\all{\va}{\vA}\SC\vA}\SC\vh_1}
702+\SC\vh_0
703+}
704+}
705+\SC\vx
706+&
707+\langle\vh_1,\vh_0,\vx\rangle\\
708+%
709+\MO{Lambda}\;\va &
710+\guess{\vx}{\all{\vA}{\Type}\SC\all{\va}{\vA}\SC\vA}{
711+\lam{\vA}{\Type}\SC
712+\guess{\vh_0}{\all{\va}{\vA}\SC\vA}
713+{
714+\underline{
715+\lam{\va}{\vA}\SC\hole{\vh_1}{\vA}\SC\vh_1
716+}
717+}
718+\SC\vh_0
719+}
720+\SC\vx
721+&
722+\langle\vh_1,\vh_0,\vx\rangle\\
723+%
724+\MO{Fill}\;\va &
725+\guess{\vx}{\all{\vA}{\Type}\SC\all{\va}{\vA}\SC\vA}{
726+\lam{\vA}{\Type}\SC
727+\\
728+&
729+\hg\hg\hg\hg\hg\hg\hg\guess{\vh_0}{\all{\va}{\vA}\SC\vA}
730+{
731+\lam{\va}{\vA}\SC
732+\underline{
733+\guess{\vh_1}{\vA}{\va}\SC\vh_1
734+}
735+}
736+\SC\vh_0
737+}
738+\SC\vx
739+&
740+\langle\vh_1,\vh_0,\vx\rangle\\
741+%
742+\MO{Solve} &
743+\guess{\vx}{\all{\vA}{\Type}\SC\all{\va}{\vA}\SC\vA}{
744+\lam{\vA}{\Type}\SC
745+\guess{\vh_0}{\all{\va}{\vA}\SC\vA}
746+{
747+\lam{\va}{\vA}\SC
748+\underline{
749+\va
750+}
751+}
752+\SC\vh_0
753+}
754+\SC\vx
755+&
756+\langle\vh_0,\vx\rangle\\
757+%
758+\MO{Solve} &
759+\guess{\vx}{\all{\vA}{\Type}\SC\all{\va}{\vA}\SC\vA}{
760+\lam{\vA}{\Type}\SC
761+\underline{
762+\lam{\va}{\vA}\SC
763+\va
764+}
765+}
766+\SC\vx
767+&
768+\langle\vx\rangle\\
769+%
770+\MO{Solve} &
771+\underline{
772+\lam{\vA}{\Type}\SC
773+\lam{\va}{\vA}\SC
774+\va
775+}
776+&
777+\langle\rangle\\
778+
779+\end{array}
780+}
781+{Proof state development for $\MO{MkId}$}
782+{mkidrefine}
783+
784+Figure \ref{mkidrefine} shows how each step of this sequence of tactics affects
785+the proof state and hole queue. In each step, the underlined fragment of the
786+term is the fragment in focus. One might observe that the
787+$\MO{Attack}$/$\MO{Solve}$ pairs are unnecessary in this case, as the term
788+is already in a form suitable for introduction. However, we retain these for
789+uniform treatment of introductions.
790+
791+To aid readability, we will elide $\MO{Tactic}$, and use a semi-colon to indicate
477792sequencing --- in the implementation we use wrapper functions for each tactic to
478−apply $\MO{RunTac}$.
793+apply $\MO{Tactic}$.
479794Using this convention, we can build $\FN{id}$'s type and definition as shown
480795in Figure \ref{idelab}. Note that $\MO{Term}$ retrieves the proof term from the current proof
481796state. Both $\MO{MkIdType}$ and $\MO{MkId}$ finish by returning a completed \TT{} term.
482−Note in particular that each $\MO{Attack}$ and each $\MO{Fill}$, which create new guesses,
483−are closed with a $\MO{Solve}$.
797+Note in particular that each tactic which introduces a guess ($\MO{Fill}$
798+and $\MO{Solve}$ is closed with a $\MO{Solve}$).
484799
485800Setting up elaboration in this way, with a proof state captured in a monad,
486801and a primitive collection of tactics,
@@ -492,19 +807,19 @@ a Coq proof script.
492807
493808\FFIG{
494809\AR{
495−\MO{MkIdType}\:\mq\:\RW{do}\;
810+\MO{MkIdType}\;\mq\;\RW{do}\;
496811 \AR{
497− \MO{NewProof}\:\Set\\
498− \MO{Attack} ; \MO{Pi}\:(\vA\Hab\Set) ;
499− \MO{Attack} ; \MO{Pi}\:(\va\Hab\vA) \\
812+ \MO{NewProof}\;\Type\\
813+ \MO{Attack} ; \MO{Pi}\;(\vA\Hab\Type) ;
814+ \MO{Attack} ; \MO{Pi}\;(\va\Hab\vA) \\
500815 \MO{Fill}\;\vA \\
501816 \MO{Solve} ; \MO{Solve} ; \MO{Solve} \\
502817 \MO{Term}
503818 }
504819 \medskip\\
505−\MO{MkId}\:\mq\:\RW{do}\;
820+\MO{MkId}\;\mq\;\RW{do}\;
506821 \AR{
507− \vt\:\leftarrow\:\MO{MkIdType}; \MO{NewProof}\:\vt\\
822+ \vt\;\leftarrow\;\MO{MkIdType}; \MO{NewProof}\;\vt\\
508823 \MO{Attack} ; \MO{Lambda}\;\vA ;
509824 \MO{Attack} ; \MO{Lambda}\;\va \\
510825 \MO{Fill}\;\va \\
@@ -535,11 +850,61 @@ a Coq proof script.
535850%\DM{
536851%}
537852
853+\subsection{System State}
854+
855+\label{sect:sysstate}
856+
857+To elaborate \Idris{} programs we will build expressions from high level
858+declarations of functions, data types and classes, and add the resulting
859+definitions to a global system state.
860+The system state is a tuple, $(\vC,\vA,\vI)$, containing:
861+
862+\begin{itemize}
863+\item A global context, $\vC$, containing pattern matching definitions and their types
864+\item Implicit arguments, $\vA$, recording which arguments are implicit for each global name
865+\item Type class information, $\vI$, containing method signatures and dictionaries for type classes
866+\end{itemize}
867+
868+In the implementation, the system state is captured in a monad, \texttt{Idris}.
869+This monad includes additional information such as syntax overloadings,
870+command line options, and optimisations, which do not concern us here. Elaboration
871+of expressions requires access to the system state in particular in order to expand
872+implicit arguments and resolve type classes.
873+
874+For each global name, $\vA$ records whether its arguments are explicit, implicit,
875+or type class constraints. For example, recall the declaration
876+of \texttt{vAdd}:
877+
878+\begin{SaveVerbatim}{vAddImpT}
879+
880+vAdd : Num a => Vect a n -> Vect a n -> Vect a n
881+
882+\end{SaveVerbatim}
883+\useverb{vAddImpT}
884+
885+\noindent
886+Written in full, and giving each argument an explicit name, we get the
887+type declaration:
888+
889+\begin{SaveVerbatim}{vAddImpT}
890+
891+vAdd : (a : _) -> (n : _) -> (c : Num a) ->
892+ (xs : Vect a n) -> (ys : Vect a n) -> Vect a n
893+
894+\end{SaveVerbatim}
895+\useverb{vAddImpT}
896+
897+\noindent
898+For \tFN{vAdd}, the state records that \texttt{a} and \texttt{n} are implicit,
899+\texttt{c} is a constraint, and \texttt{xs} and \texttt{ys} are explicit. When
900+the elaborator encounters an application of \tFN{vAdd}, it knows that unless these arguments
901+are given explicitly, the application must be expanded.
902+
538903\subsection{Elaborating Expressions}
539904
540−\newcommand{\piimp}[2]{\mbox{\texttt{\{ $#1$ : $#2$ \} -> }}}
905+\newcommand{\piimp}[2]{\mbox{\texttt{\{$#1$ : $#2$\} -> }}}
541906%\mathtt{\{}#1\mathtt{:}#2\mbox{\texttt{\} -> }}}
542−\newcommand{\piexp}[2]{\mbox{\texttt{( $#1$ : $#2$ ) -> }}}
907+\newcommand{\piexp}[2]{\mbox{\texttt{($#1$ : $#2$) -> }}}
543908%\newcommand{\piexp}[2]{\mathtt{(}#1\mathtt{:}#2\mbox{\texttt{) -> }}}
544909\newcommand{\piconst}[1]{\mbox{\texttt{$#1$ => }}}
545910\newcommand{\icase}{\mathtt{case}}
@@ -563,11 +928,11 @@ a Coq proof script.
563928\begin{array}{rll@{\hg}rll}
564929\ve ::= & \vc & (\mbox{constant}) &
565930\mid & \vx & (\mbox{variable}) \\
566−\mid & \vt & (\mbox{type}) &
567−\mid & \ve\:\ta & (\mbox{function application}) \\
568−\mid & \ilam{\vx}\:\ve & (\mbox{lambda abstraction}) &
569−\mid & \ilet{\vx}{\ve}\:\ve & (\mbox{let binding}) \\
570−%\mid & \icase\:\ve\:\iof\:\vec{\VV{alt}} & (\mbox{case expression}) &
931+\mid & \ilam{\vx}\;\ve & (\mbox{lambda abstraction}) &
932+\mid & \ve\;\ta & (\mbox{function application}) \\
933+\mid & \ilet{\vx}{\ve}\;\ve & (\mbox{let binding}) &
934+\mid & \piexp{\vx}{\vt}\vt & (\mbox{explicit function space}) \\
935+%\mid & \icase\;\ve\;\iof\;\vec{\VV{alt}} & (\mbox{case expression}) &
571936%\mid & \mvar{\vx} & (\mbox{metavariable}) \\
572937\mid & \_ & (\mbox{placeholder})
573938\end{array}
@@ -579,11 +944,6 @@ a Coq proof script.
579944\end{array}
580945\medskip\\
581946\begin{array}{rll}
582−\vt ::= & \ve & (\mbox{expression}) \\
583−\mid & \piexp{\vx}{\vt}\vt & (\mbox{explicit function space}) \\
584−\end{array}
585−\medskip\\
586−\begin{array}{rll}
587947\VV{declty} ::= & \ve & (\mbox{expression}) \\
588948\mid & \piexp{\vx}{\vt}\VV{declty} & (\mbox{explicit function space}) \\
589949\mid & \piimp{\vx}{\vt}\VV{declty} & (\mbox{implicit function space}) \\
@@ -611,9 +971,9 @@ a Coq proof script.
611971\begin{array}{ll}
612972\begin{array}{rll}
613973\VV{pclause} ::= &
614−\vx\:\ttt\:[\ibar\;\te]\mbox{\texttt{ = }}\ve \hg[\iwhere\;\td]\\
974+\vx\;\ttt\;[\ibar\;\te]\mbox{\texttt{ = }}\ve \hg[\iwhere\;\td]\\
615975\mid & \AR{
616−\vx\:\ttt\:[\ibar\;\te]\;\iwith\;\ve\\
976+\vx\;\ttt\;[\ibar\;\te]\;\iwith\;\ve\\
617977\hg\vec{\VV{pclause}}
618978}
619979\end{array}
@@ -624,7 +984,7 @@ a Coq proof script.
624984\medskip\\
625985\VV{cdecl} ::= & \iclass\;[\VV{constr}]\;\vx\;(\ihab{\tx}{\ttt})\;\iwhere\;\td
626986\\
627−\VV{idecl} ::= & \iinstance\:[\VV{constr}]\;\vx\;\ttt\;\iwhere\;\td
987+\VV{idecl} ::= & \iinstance\;[\VV{constr}]\;\vx\;\ttt\;\iwhere\;\td
628988\end{array}
629989\end{array}
630990}
@@ -632,13 +992,14 @@ a Coq proof script.
632992{\IdrisM{} declarations}
633993{idrismd}
634994
635−We define a language \IdrisM{}, with expression syntax given in Figure \ref{idrism}
636−and declaration syntax given in Figure \ref{idrismd}.
995+We will use a subset of full \Idris{}, which we call \IdrisM{}, to explain
996+elaboration of expressions. \IdrisM{} expression syntax is given in Figure
997+\ref{idrism} and declaration syntax given in Figure \ref{idrismd}.
637998\IdrisM{} is a subset of \Idris{} without syntactic sugar --- that is, without
638999tuple syntax, \texttt{do}-notation or infix operators --- and with implicit
6391000arguments in types bound explicitly
640−(e.g. $\piimp{\va}{\_}\piimp{\vn}{\_}\TC{Vect}\:\va\:\vn$
641−instead of simply $\Vect\:\va\:\vn$).
1001+(e.g. $\piimp{\va}{\_}\piimp{\vn}{\_}\TC{Vect}\;\va\;\vn$
1002+instead of simply $\Vect\;\va\;\vn$).
6421003Note that we separate implicit and type constraint bindings, to ensure that they
6431004only appear in top level declarations.
6441005It is in general straightforward to
@@ -659,14 +1020,21 @@ than one at a time.
6591020%Implicit and type class arguments? Expanded at the application site (we need to know
6601021%it's the global name after all and we do that by type).
6611022
662−To elaborate expressions, we define a meta-operation $\ttinterp{\cdot}$ which
663−runs relative to a proof state (see Section \ref{sect:prfstate}). Its effect is
1023+To elaborate expressions, we define meta-operations $\ttinterp{\cdot}$ and
1024+$\ttpinterp{\cdot}$, which run relative to a proof state (see Section
1025+\ref{sect:prfstate}). $\ttpinterp{\cdot}$ elaborates \remph{patterns}, i.e.
1026+expressions on the left hand side of a pattern matching definition, whereas
1027+$\ttinterp{\cdot}$ elaborates expressions on the right hand side.
1028+Their effect is
6641029to update the proof state so that the hole in focus contains a representation
6651030of the given expression, by applying tactics. We assume that the proof state
6661031has already been set up, which means that elaboration can always be
6671032\remph{type-directed} since the proof state contains the type of the expression we
6681033are building.
6691034
1035+In all cases except the elaboration of variables and constantes,
1036+$\ttpinterp{\vx}\;=\;\ttinterp{\vx}$.
1037+
6701038\subsubsection{Elaborating variables and constants}
6711039
6721040In the simplest cases, there is a direct translation from an \IdrisM{} expression to
@@ -675,24 +1043,27 @@ the \MO{Fill} tactic:
6751043
6761044\DM{
6771045\AR{
678−\ttinterp{\vx}\:\mq\:\RW{do}\:\MO{Fill}\:\vx;\:\MO{Solve}\\
679−\ttinterp{\vc}\:\mq\:\RW{do}\:\MO{Fill}\:\vc;\:\MO{Solve}\\
1046+\ttinterp{\vx}\;\mq\;\RW{do}\;\MO{Fill}\;\vx;\;\MO{Solve}\\
1047+\ttinterp{\vc}\;\mq\;\RW{do}\;\MO{Fill}\;\vc;\;\MO{Solve}\\
6801048}
6811049}
6821050
683−We need not concern ourselves with type checking variables or constants here --- $\MO{Fill}$
684−will handle this, type checking $\vx$ or $\vc$ and unifying the result with the
685−hole type. If there are any errors, elaboration will fail.
1051+Since $\MO{Fill}$ creates a guess binding, we use $\MO{Solve}$ to instantiate
1052+the guess. We need not concern ourselves with type checking variables or
1053+constants here --- $\MO{Fill}$ will handle this, type checking $\vx$ or $\vc$
1054+and unifying the result with the hole type. If there are any errors,
1055+elaboration will fail.
6861056
687−If we are building the left hand side of a pattern clause, however, there is a problem,
688−as it is the left hand side which \remph{defines} variables. In this context, we assume
689−that attempting to elaborate a variable which does not type check means that the variable
690−is a pattern variable:
1057+If we are building the left hand side of a pattern clause, however, there is a
1058+problem, as it is the left hand side which \remph{defines} variables. In this
1059+context, we assume that attempting to elaborate a variable which does not type
1060+check means that the variable is a pattern variable:
6911061
6921062\DM{
693−\ttinterp{\vx}\:\mq\:
694−\MO{Try}\:\AR{(\RW{do}\:\MO{Fill}\:\vx;\:\MO{Solve})\\
695−(\MO{Pat}\:\vx)\hg\hg\mbox{(If elaborating a left hand side)}}
1063+\ttpinterp{\vx}\;\mq\;
1064+\MO{Try}\;\AR{(\RW{do}\;\MO{Fill}\;\vx;\;\MO{Solve})\\
1065+(\MO{Pat}\;\vx)
1066+}
6961067}
6971068
6981069We also need to elaborate \remph{placeholders}, which are subexpressions we expect to
@@ -700,25 +1071,26 @@ solve by unification. In this case, we simply move on to the next hole in the qu
7001071the current hole to the end of the queue with $\MO{Unfocus}$:
7011072
7021073\DM{
703−\ttinterp{\_}\:\mq\:\MO{Unfocus}
1074+\ttinterp{\_}\;\mq\;\MO{Unfocus}
7041075}
7051076
706−On encountering a placeholder, our assumption is that unification will eventually solve
707−the hole. At the end of elaboration, any holes remaining unsolved on the left hand side
708−become pattern variables. If there are any unsolved on the right hand side, elaboration
709−fails.
1077+On encountering a placeholder, our assumption is that unification will
1078+eventually solve the hole. At the end of elaboration, any holes remaining
1079+unsolved on the left hand side become pattern variables. If there are any
1080+unsolved on the right hand side, elaboration is incomplete and an error will
1081+be reported when the resulting term is type checked.
7101082
7111083\subsubsection{Elaborating bindings}
7121084
713−To elaborate a $\lambda$-binding, we $\MO{Attack}$ the hole, which must be a function type,
714−apply the $\MO{Lambda}$ tactic, elaborate the scope, then $\MO{Solve}$, which discharges
715−the $\MO{Attack}$:
1085+To elaborate a $\lambda$-binding, we $\MO{Attack}$ the hole, then apply the
1086+$\MO{Lambda}$ tactic, which will fail if the goal is not a function type. We
1087+then elaborate the scope and $\MO{Solve}$, which discharges the $\MO{Attack}$:
7161088
7171089\DM{
718−\ttinterp{\ilam{\vx}\ve}\:\mq\:
719−\RW{do}\:
1090+\ttinterp{\ilam{\vx}\ve}\;\mq\;
1091+\RW{do}\;
7201092\AR{
721−\MO{Attack};\;\MO{Lambda}\:\vx\\
1093+\MO{Attack};\;\MO{Lambda}\;\vx\\
7221094\ttinterp{\ve}\\
7231095\MO{Solve}
7241096}
@@ -738,12 +1110,12 @@ scope of the binding.
7381110
7391111\DM{
7401112\AR{
741−\ttinterp{\piexp{\vx}{\vt}\ve}\:\mq\:
742−\RW{do}\:
1113+\ttinterp{\piexp{\vx}{\vt}\ve}\;\mq\;
1114+\RW{do}\;
7431115\AR{
744−\MO{Attack};\;\MO{Claim}\:(\vX\Hab\Set)\\
745−\MO{Pi}\:(\vx\Hab\vX)\\
746−\MO{Focus}\:\vX\\
1116+\MO{Attack};\;\MO{Claim}\;(\vX\Hab\Type)\\
1117+\MO{Pi}\;(\vx\Hab\vX)\\
1118+\MO{Focus}\;\vX\\
7471119\ttinterp{\vt};\;
7481120\ttinterp{\ve}\\
7491121\MO{Solve}
@@ -764,13 +1136,13 @@ if elaborating the scope is successful, unification will solve the claimed varia
7641136$\vV$ and $\vX$.
7651137
7661138\DM{
767−\ttinterp{\ilet{\vx}{\vv}\:{\ve}}\:\mq\:\RW{do}\:
1139+\ttinterp{\ilet{\vx}{\vv}\;{\ve}}\;\mq\;\RW{do}\;
7681140\AR{
7691141\MO{Attack};\;
770−\MO{Claim}\:(\vX\Hab\Set);\;
771−\MO{Claim}\:(\vV\Hab\vX)\\
772−\MO{Let}\:(\vx\Hab\vX\defq\vV)\\
773−\MO{Focus}\:\vV\\
1142+\MO{Claim}\;(\vX\Hab\Type);\;
1143+\MO{Claim}\;(\vV\Hab\vX)\\
1144+\MO{Let}\;(\vx\Hab\vX\defq\vV)\\
1145+\MO{Focus}\;\vV\\
7741146\ttinterp{\vv};\;
7751147\ttinterp{\ve}
7761148}
@@ -788,7 +1160,7 @@ In the first case, the elaborator must expand the application to include implici
7881160For example \texttt{vAdd xs ys} is expanded to
7891161\texttt{vAdd \{a=\_\} \{n=\_\} \{\{\_\}\} xs ys}, adding the implicit arguments
7901162\texttt{a} and \texttt{n} and a type class instance argument. The meta-operation
791−$\MO{Expand}\:\vx\:\ta$, given a global function name $\vx$ and the
1163+$\MO{Expand}\;\vx\;\ta$, given a global function name $\vx$ and the
7921164arguments supplied by the programmer $\ta$, returns a new argument list
7931165$\ta'$ with implicit and type class arguments added. Each value in
7941166$\ta'$ is paired with an explicit name for the argument.
@@ -802,57 +1174,42 @@ forms:
8021174
8031175\DM{
8041176\AR{
805−\MO{Unify}_\Gamma\;\vf\:\TC{Int}\\
806−\MO{Unify}_\Gamma\;(\vf\:\vx)\:\TC{Int}\\
807−\MO{Unify}_\Gamma\;(\vf\:\vx)\:(\vg\:\vx)\\
808−}
809−}
810−
811−The first problem has a solution: $\vf=\TC{Int}$. The second and third problems have
812−no solution without further information. In the second case, we cannot conclude
813−anything about $\vf$ or $\vx$ just from knowing that $\vf\:\vx\:=\:\TC{Int}$.
814−In the third case, although we have $\vx\:=\:\vx$ in argument position, we cannot
815−conclude that $\vf\:=\:\vg$ unless we know that the function which solves $\vf$ or
816−$\vg$ is injective.
817−
818−Once $\vf$ or $\vg$ is solved in some other way, perhaps by being given explicitly
819−in another argument, these unification problems can make progress. Otherwise, unification
820−fails. As a result, the order in which functions and arguments are
821−elaborated matters. Sometimes, we may learn more by elaborating a function first
822−and the arguments later, sometimes it may be the other way around.
823−
824−One option when unification fails is to store the problem (i.e. the expressions to be
825−unified with their local context) and refine it with further information when it becomes
826−available. In practice, we have found a simpler approach to be effective: try
827−elaborating the function first, then arguments. If that fails, try elaborating the
828−arguments first.
829−
830−Elaborating a global function application makes a $\MO{Claim}$ for each argument
831−in turn. Then the function is elaborated, applied to each of the claimed arguments.
832−Finally, each argument which has been given explicitly is elaborated. If this fails,
833−elaboration tries again in the opposite order. Finally, any type
834−class instance arguments are resolved with the built-in $\MO{Instance}$ tactic.
1177+\MO{Unify}_\Gamma\;\vf\;\TC{Int}\\
1178+\MO{Unify}_\Gamma\;(\vf\;\vx)\;\TC{Int}\\
1179+\MO{Unify}_\Gamma\;(\vf\;\vx)\;(\vg\;\vx)\\
1180+}
1181+}
1182+
1183+The first problem has a solution: $\vf=\TC{Int}$. The second and third problems
1184+have no solution without further information. In the second case, we cannot
1185+conclude anything about $\vf$ or $\vx$ just from knowing that
1186+$\vf\;\vx\;=\;\TC{Int}$. In the third case, although we have $\vx\;=\;\vx$ in
1187+argument position, we cannot conclude that $\vf\;=\;\vg$ in general as a
1188+result.
1189+
1190+Once $\vf$ or $\vg$ is solved in some other way, perhaps by being given
1191+explicitly in another argument, these unification problems can make progress.
1192+Otherwise, unification blocks. In such a case, the elaborator stores the
1193+problem (i.e. the expressions to be unified with their local context) and
1194+refines it with further information when it becomes available.
1195+Elaborating a global function application makes a $\MO{Claim}$ for each
1196+argument in turn. Then the function is elaborated, applied to each of the
1197+claimed arguments. Each argument which has been given explicitly is
1198+elaborated.
1199+Finally, any type class instance arguments are resolved with the
1200+built-in $\MO{Instance}$ tactic.
8351201
8361202\DM{
837−\ttinterp{\vx\:\ta}\:\mq\:
1203+\ttinterp{\vx\;\ta}\;\mq\;
8381204\AR{
839−\RW{do}\:
1205+\RW{do}\;
8401206\AR{
841−(\tn,\tv)\:\gets\:\MO{Expand}\:\vx\:\ta\\
842−\vec{\MO{Claim}}\:(\tn\Hab\tT)\\
843−\MO{Try}\:\AR{
844−(\RW{do}\:\AR{
845−\MO{Fill}\:\vx\:\tn\\
846−\vec{\MO{Focus}}\:\tn;\:\ttinterp{\tv}\hg\mbox{(for non-placeholder $\vv$)}\\
847−\MO{Solve})
848−}\\
849−(\RW{do}\:\AR{
850−\vec{\MO{Focus}}\:\tn;\:\ttinterp{\tv}\hg\mbox{(for non-placeholder $\vv$)}\\
851−\MO{Fill}\:\vx\:\tn\\
852−\MO{Solve})
853−}}
854−\\
855−\vec{\MO{Instance}}\:\tn\hg\mbox{(for type class constraint argument $\vn$)}
1207+(\tn,\tv)\;\gets\;\MO{Expand}\;\vx\;\ta\\
1208+\vec{\MO{Claim}}\;(\tn\Hab\tT)\\
1209+\MO{Fill}\;\vx\;\tn\\
1210+\vec{\MO{Focus}}\;\tn;\;\ttinterp{\tv}\hg\mbox{(for non-placeholder $\vv$)}\\
1211+\MO{Solve} \\
1212+\vec{\MO{Instance}}\;\tn\hg\mbox{(for type class constraint argument $\vn$)}
8561213}
8571214}
8581215}
@@ -862,27 +1219,19 @@ a type class instance which would solve the goal directly. First, it examines th
8621219context, then recursively searches the global context. $\MO{Instance}$ is covered
8631220in detail in Section \ref{sect:instance}.
8641221
865−To elaborate a simple function application, of an arbitrary expression to an arbitrary
866−argument, we need not worry about implicit arguments or class constraints. Instead,
867−the function and argument are elaborated, and the results applied. Since elaboration
868−is type directed, however, there must be an appropriate type for the function.
869−As before, elaboration tries two orders, as it may learn something from elaborating
870−the function or argument which helps with unification:
1222+To elaborate a simple function application, of an arbitrary expression to an
1223+arbitrary argument, we need not worry about implicit arguments or class
1224+constraints. Instead, the function and argument are elaborated, and the results
1225+applied. Since elaboration is type directed, however, there must be an
1226+appropriate type for the function.
8711227
8721228\DM{
873−\ttinterp{\ve\:\va}\:\mq\:\RW{do}\:
1229+\ttinterp{\ve\;\va}\;\mq\;\RW{do}\;
8741230\AR{
875−\MO{Claim}\:(\vA\Hab\Set);\;\MO{Claim}\:(\vB\Hab\Set)\\
876−\MO{Claim}\:(\vf\Hab\vA\to\vB);\;\MO{Claim}\:(\vs\Hab\vA)\\
877−\MO{Try}\:
878−\AR{
879−(\RW{do}\:\AR{
880−\MO{Focus}\:\vf;\;\ttinterp{\ve}\\
881−\MO{Focus}\:\vs;\;\ttinterp{\va})}\\
882−(\RW{do}\:\AR{
883−\MO{Focus}\:\vs;\;\ttinterp{\va}\\
884−\MO{Focus}\:\vf;\;\ttinterp{\ve})}\\
885−}
1231+\MO{Claim}\;(\vA\Hab\Type);\;\MO{Claim}\;(\vB\Hab\Type)\\
1232+\MO{Claim}\;(\vf\Hab\vA\to\vB);\;\MO{Claim}\;(\vs\Hab\vA)\\
1233+\MO{Focus}\;\vf;\;\ttinterp{\ve}\\
1234+\MO{Focus}\;\vs;\;\ttinterp{\va}\\
8861235}
8871236}
8881237
@@ -897,7 +1246,7 @@ relative to the system state (see Section \ref{sect:sysstate}) and has access to
8971246current proof state. $\MO{Elab}$ uses $\ttinterp{\cdot}$ to help translate
8981247\IdrisM{} type, function and class declarations into \TT{} declarations.
8991248
900−\newcommand{\edo}[1]{\RW{do}\:\AR{#1}}
1249+\newcommand{\edo}[1]{\RW{do}\;\AR{#1}}
9011250
9021251\subsubsection{Elaborating Type Declarations}
9031252
@@ -906,11 +1255,11 @@ translating the \IdrisM{} type to a \TT{} type, then adding the resulting type
9061255as a \TT{} declaration:
9071256
9081257\DM{
909−\MO{Elab}\:(\vx\Hab\vt)\:\mq
910−\:\edo{\MO{NewProof}\:\Set\\
1258+\MO{Elab}\;(\vx\Hab\vt)\;\mq
1259+\;\edo{\MO{NewProof}\;\Type\\
9111260 \ttinterp{\vt}\\
9121261 \vt'\gets\MO{Term}\\
913− \MO{TTDecl}\:(\vx\Hab\vt')
1262+ \MO{TTDecl}\;(\vx\Hab\vt')
9141263}}
9151264
9161265The final $\MO{TTDecl}$ takes the result of elaboration, type checks it,
@@ -927,20 +1276,20 @@ adds a \TT{} data declaration.
9271276
9281277\DM{
9291278\AR{
930−\MO{Elab}\:(\idata\;\ihab{\vx}{\vt}\;\iwhere\;\tc)\\
931−\hg\hg\mq\:\edo{\MO{NewProof}\:\Set\\
1279+\MO{Elab}\;(\idata\;\ihab{\vx}{\vt}\;\iwhere\;\tc)\\
1280+\hg\hg\mq\;\edo{\MO{NewProof}\;\Type\\
9321281 \ttinterp{\vt}\\
9331282 \vt'\gets\MO{Term}\\
934− \MO{TTDecl}\:(\vx\Hab\vt')\\
935− \tc'\gets\vec{\MO{ElabCon}}\:\tc\\
936− \MO{TTDecl}\:(\Data\:\vx\Hab\vt'\:\Where\:\tc')
1283+ \MO{TTDecl}\;(\vx\Hab\vt')\\
1284+ \tc'\gets\vec{\MO{ElabCon}}\;\tc\\
1285+ \MO{TTDecl}\;(\Data\;\vx\Hab\vt'\;\Where\;\tc')
9371286}
9381287\AR{
939−\MO{ElabCon}\:(\vx\Hab\vt)\\
940−\hg\hg\mq\: \edo{\MO{NewProof}\:\Set\\
1288+\MO{ElabCon}\;(\vx\Hab\vt)\\
1289+\hg\hg\mq\; \edo{\MO{NewProof}\;\Type\\
9411290 \ttinterp{\vt}\\
9421291 \vt'\gets\MO{Term}\\
943− \RW{return}\:(\vx\Hab\vt')
1292+ \RW{return}\;(\vx\Hab\vt')
9441293}
9451294}}}
9461295
@@ -953,7 +1302,7 @@ to the global context, such as definitions in $\iwhere$ clauses.
9531302First, let us consider the simplest case, with no $\iwhere$ clause:
9541303
9551304\DM{
956−\MO{ElabClause}\:(\vx\:\ttt\:=\:\ve)\:\mq\:?
1305+\MO{ElabClause}\;(\vx\;\ttt\;=\;\ve)\;\mq\;?
9571306}
9581307
9591308How does the left hand side get elaborated, given that elaboration is type directed, and
@@ -962,24 +1311,24 @@ This can be achieved without any change to the elaborator by defining
9621311a type $\TC{Infer}$:
9631312
9641313\DM{
965−\Data\hg\TC{Infer}\Hab\Set\hg\Where\hg\DC{MkInfer}\Hab\all{\va}{\Set}\SC\va\to\TC{Infer}
1314+\Data\hg\TC{Infer}\Hab\Type\hg\Where\hg\DC{MkInfer}\Hab\all{\va}{\Type}\SC\va\to\TC{Infer}
9661315}
9671316
968−Now elaboration of the left hand side proceeds by elaborating $\DC{MkInfer}\:\_\:(\vx\:\ttt)$ and
1317+Now elaboration of the left hand side proceeds by elaborating $\DC{MkInfer}\;\_\;(\vx\;\ttt)$ and
9691318extracting the value and unified type when complete.
9701319
9711320\DM{
9721321\AR{
973−\MO{ElabClause}\:(\vx\:\ttt\:=\:\ve)\:\mq\:\\
1322+\MO{ElabClause}\;(\vx\;\ttt\;=\;\ve)\;\mq\;\\
9741323\hg\hg\edo{
975−\MO{NewProof}\:\TC{Infer};\;
976−\ttinterp{\DC{MkInfer}\:\_\:(\vx\:\ttt)}\\
977−\DC{MkInfer}\:\vT\:\VV{lhs}\gets\MO{Term}\\
1324+\MO{NewProof}\;\TC{Infer};\;
1325+\ttpinterp{\DC{MkInfer}\;\_\;(\vx\;\ttt)}\\
1326+\DC{MkInfer}\;\vT\;\VV{lhs}\gets\MO{Term}\\
9781327\tp\gets\MO{Patterns}\\
979−\MO{NewTerm}\:\vT;\;
1328+\MO{NewTerm}\;\vT;\;
9801329\ttinterp{\ve}\\
9811330\VV{rhs}\gets\MO{Term}\\
982−\RW{return}\:(\RW{var}\:\tp\SC\VV{lhs}\:=\:\VV{rhs})
1331+\RW{return}\;(\RW{var}\;\tp\SC\VV{lhs}\;=\;\VV{rhs})
9831332}
9841333}
9851334}
@@ -993,10 +1342,10 @@ the clauses and adding the resulting collection to \TT{}.
9931342
9941343\DM{
9951344\AR{
996−\MO{Elab}\:\vec{\VV{pclause}}\:\mq\:
1345+\MO{Elab}\;\vec{\VV{pclause}}\;\mq\;
9971346\edo{
998−\tc\gets\vec{\MO{ElabClause}}\:\vec{\VV{pclause}}\\
999−\vec{\MO{TTDecl}}\:\tc
1347+\tc\gets\vec{\MO{ElabClause}}\;\vec{\VV{pclause}}\\
1348+\vec{\MO{TTDecl}}\;\tc
10001349}
10011350}
10021351}
@@ -1008,18 +1357,18 @@ which are then recursively elaborated before the right hand side.
10081357
10091358\DM{
10101359\AR{
1011−\MO{ElabClause}\:(\vx\:\ttt\:=\:\ve\:\iwhere\:\td)\:\mq\:\\
1360+\MO{ElabClause}\;(\vx\;\ttt\;=\;\ve\;\iwhere\;\td)\;\mq\;\\
10121361\hg\hg\edo{
1013−\MO{NewProof}\:\TC{Infer};\;
1014−\ttinterp{\DC{MkInfer}\:\_\:(\vx\:\ttt)}\\
1015−\DC{MkInfer}\:\vT\:\VV{lhs}\gets\MO{Term}\\
1362+\MO{NewProof}\;\TC{Infer};\;
1363+\ttpinterp{\DC{MkInfer}\;\_\;(\vx\;\ttt)}\\
1364+\DC{MkInfer}\;\vT\;\VV{lhs}\gets\MO{Term}\\
10161365\tp\gets\MO{Patterns}\\
1017−(\td', \ve') \gets\MO{Lift}\:\tp\:\td\:\ve\\
1018−\vec{\MO{Elab}}\:\td'\\
1019−\MO{NewTerm}\:\vT;\;
1366+(\td', \ve') \gets\MO{Lift}\;\tp\;\td\;\ve\\
1367+\vec{\MO{Elab}}\;\td'\\
1368+\MO{NewTerm}\;\vT;\;
10201369\ttinterp{\ve'}\\
10211370\VV{rhs}\gets\MO{Term}\\
1022−\RW{return}\:(\RW{var}\:\tp\SC\VV{lhs}\:=\:\VV{rhs})
1371+\RW{return}\;(\RW{var}\;\tp\SC\VV{lhs}\;=\;\VV{rhs})
10231372}
10241373}
10251374}
@@ -1060,32 +1409,74 @@ natToBin' (S (j + j)) odd = True :: natToBin j
10601409\useverb{natToBinwp}
10611410
10621411\noindent
1063−Elaboration of \texttt{with} builds the type declaration and auxiliary function
1064−automatically:
1412+Additionally, the elaborator abstracts over the term being analysed in the type
1413+of the generated auxiliary definition\footnote{This is sometimes referred to
1414+as ``magic \texttt{with}''.} and reorders the arguments as required.
1415+For example:
1416+
1417+\begin{SaveVerbatim}{magicwith}
1418+
1419+f : Nat -> Bool
1420+
1421+ftest : (n : Nat) -> so (f n) -> Nat
1422+ftest n x with (f n)
1423+ | True = ...
1424+ | False = ...
1425+
1426+\end{SaveVerbatim}
1427+\useverb{magicwith}
10651428
1429+\noindent
1430+Here, we may require the knowledge that \texttt{f n} is \texttt{True} or
1431+\texttt{False} in the appropriate case. The elaborator abstracts over
1432+\texttt{f n} in the auxiliary definition, specialising the type of
1433+\texttt{x} in each case:
1434+
1435+\begin{SaveVerbatim}{magicwithaux}
1436+
1437+ftest : (n : Nat) -> so (f n) -> Nat
1438+ftest n x = ftest' n (f n) x
1439+
1440+ftest' : (n : Nat) -> (p : Bool) -> so p -> Nat
1441+ftest' n True x = ...
1442+ftest' n False x = ...
1443+
1444+\end{SaveVerbatim}
1445+\useverb{magicwithaux}
1446+
1447+\noindent
1448+Elaboration of \texttt{with} builds the type declaration and auxiliary function
1449+automatically. It checks the left hand side, resulting in a set of patterns
1450+$\tp$, then splits these patterns into those necessary to type
1451+$\vW$, and the rest ($\tp_w$ and $\tp_n$ respectively) using
1452+$\MO{SplitContext}$. Then, it builds a new declaration, abstracting over
1453+the matched expression $\ve$ in the types of $\tp_n$.
1454+$\MO{Abstract}\;\ve\;\vw\;\vp$ simply replaces any occurrence of $\vw$ in
1455+$\vp$ with the name $\ve$.
10661456
10671457\DM{
10681458\AR{
1069−\MO{ElabClause}\:(\vx\:\ttt\:\iwith\:\ve\:\vec{\VV{pclause}})\:\mq\\
1459+\MO{ElabClause}\;(\vx\;\ttt\;\iwith\;\ve\;\vec{\VV{pclause}})\;\mq\\
10701460\hg\hg\edo{
1071−\MO{NewProof}\:\TC{Infer};\;
1072−\ttinterp{\DC{MkInfer}\:\_\:(\vx\:\ttt)}\\
1073−\DC{MkInfer}\:\vT\:\VV{lhs}\gets\MO{Term}\\
1461+\MO{NewProof}\;\TC{Infer};\;
1462+\ttinterp{\DC{MkInfer}\;\_\;(\vx\;\ttt)}\\
1463+\DC{MkInfer}\;\vT\;\VV{lhs}\gets\MO{Term}\\
10741464\tp\gets\MO{Patterns}\\
1075−\MO{NewTerm}\:\TC{Infer};\;
1076−\ttinterp{\DC{MkInfer}\:\_\:\ve}\\
1077−\DC{MkInfer}\:\vW\:\vw'\gets\MO{Term}\\
1078−\MO{TTDecl}\:(\vx'\Hab\tp\to\vW\to\vT)\\
1079−\tc'\gets\vec{\MO{MatchWith}}\:\tp\:(\vx\:\ttt)\:\vec{\VV{pclause}}\\
1080−\vec{\MO{Elab}}\:\tc'\\
1081−\RW{return}\:(\RW{var}\:\tp\SC\VV{lhs}\:=\:\vx'\:\tp\:\vw')
1465+\MO{NewTerm}\;\TC{Infer};\;
1466+\ttinterp{\DC{MkInfer}\;\_\;\ve}\\
1467+\DC{MkInfer}\;\vW\;\vw'\gets\MO{Term}\\
1468+(\tp_w,\tp_n)\;\gets\;\MO{SplitContext}\;\vW\;\tp\\
1469+\MO{TTDecl}\;(\vx'\Hab\tp_{w}\to(\ve\Hab\vW)\to\vec{\MO{Abstract}}\;\ve\;\vw'\;\tp_{n}\to\vT)\\
1470+\tc'\gets\vec{\MO{MatchWith}}\;\tp\;\ttt\;\vec{\VV{pclause}}\\
1471+\vec{\MO{Elab}}\;\tc'\\
1472+\RW{return}\;(\RW{var}\;\tp\SC\VV{lhs}\;=\;\vx'\;\tp_{w}\;\vw'\;\tp_{n})
10821473}
10831474\medskip\\
1084−\MO{MatchWith}\:\tp\:(\vx\:\ttt)\:(\vx\:\tw\:\mid\:\ve\:\VV{rhs})\:\mq\\
1475+\MO{MatchWith}\;\tp_w\;\tp_n\;\ttt\;(\vx\;\tw\;\mid\;\ve\;\VV{rhs})\;\mq\\
10851476\hg\hg\edo{
1086−\tp'\gets\vec{\MO{Match}}\:\tw\:\ttt\\
1087−\MO{CheckComplete}\:\tp\:\tp'\\
1088−\RW{return}\:(\vx'\:\tp'\:\ve\:\VV{rhs})
1477+\tp'\gets\vec{\MO{Match}}\;\tw\;\ttt\\
1478+(\tp'_w,\tp'_n)\;\gets\;\MO{SplitPats}\;\tp_w\;\tp_n\;\tp'\\
1479+\RW{return}\;(\vx'\;\tp'_w\;\ve\;\tp'_{n}\;\VV{rhs})
10891480}
10901481}
10911482}
@@ -1104,26 +1495,24 @@ $\ve$ which is the same type as the scrutinee of the \texttt{with}, $\vW$.
11041495The right hand side, $\VV{rhs}$, may either return a value directly, containing
11051496\texttt{where} clauses, or be a nested \texttt{with} block. In any case, it
11061497remains unchanged.
1107−$\MO{Match}\:\vw\:\vt$ returns a list of pattern bindings containing
1498+$\MO{Match}\;\vw\;\vt$ returns a list of pattern bindings containing
11081499the variables in $\vt$ and their matches in $\vw$.
1109−If the \texttt{with} block is well-formed, then
1110−the resulting set of patterns $\tp'$ contains exactly the same pattern variables
1111−as $\tp$, which is verified by $\MO{CheckComplete}$.
1112−
1500+The resulting matches are split, using $\MO{SplitPats}$, into matches for those
1501+variables necessary to type $\vW$ and the rest, as before.
11131502
11141503\subsubsection{Elaborating Class and Instance Declarations}
11151504
1116−Type classes are implemented as dictionaries of functions for each instance. Therefore,
1117−a type class declaration elaborates to a record type containing all of the functions
1118−in the class, and an instance is simply an instance of the record. The methods
1119−are translated to top level functions which extract the relevant function from the
1120−dictionary.
1121−For example, for the \texttt{Show} type class, the \texttt{class}
1122−declaration is translated to:
1505+Type classes are implemented as dictionaries of functions for each instance,
1506+following the implementation of first class type classes in Coq~\cite{Sozeau2008}.
1507+Therefore, a type class declaration elaborates to a record type containing all
1508+of the functions in the class, and an instance is simply an instance of the
1509+record. The methods are translated to top level functions which extract the
1510+relevant function from the dictionary. For example, for the \texttt{Show} type
1511+class, the \texttt{class} declaration is translated to:
11231512
11241513\begin{SaveVerbatim}{showdata}
11251514
1126−data Show : Set -> Set where
1515+data Show : Type -> Type where
11271516 instanceShow : (show : a -> String) -> Show a
11281517
11291518show : Show a -> a -> String
@@ -1137,7 +1526,7 @@ An instance for a type \texttt{a} is then a value of type \texttt{Show a}; for e
11371526
11381527\begin{SaveVerbatim}{shownatf}
11391528
1140−showNat : Show Nat;
1529+showNat : Show Nat
11411530showNat = instanceShow show' where
11421531 show' : Nat -> String
11431532 show' O = "O"
@@ -1182,7 +1571,7 @@ This translates to:
11821571
11831572\begin{SaveVerbatim}{orddata}
11841573
1185−data Ord : Set -> Set where
1574+data Ord : Type -> Type where
11861575 instanceOrd : Eq a => (compare : a -> a -> Ordering) ->
11871576 (max : a -> a -> a) -> Ord a
11881577
@@ -1217,51 +1606,47 @@ In general, \texttt{class} declarations are elaborated as follows:
12171606
12181607\DM{
12191608\AR{
1220−\MO{Elab}\:(\iclass\;\piconst{\tc}\TC{C}\:(\ta\Hab\ttt)\:\iwhere\:\td)
1609+\MO{Elab}\;(\iclass\;\piconst{\tc}\TC{C}\;(\ta\Hab\ttt)\;\iwhere\;\td)
12211610\\
12221611\hg\hg
1223−\mq\:\RW{do}\:\AR{
1612+\mq\;\RW{do}\;\AR{
12241613(\vec{\VV{meth}}\Hab\ttt)\gets\td\\
1225−\MO{Elab}\:
1226−\AR{(\RW{data}\:\TC{C}\Hab(\ta\Hab\ttt)\to\Set\:\iwhere\\
1227−\hg\DC{InstanceC}\Hab\piconst{\tc}\td\to\TC{C}\:\ta)}
1228−}
1229−}
1230−}
1231−
1232−\DM{
1233−\AR{
1234−\AR{
1235−\vec{\MO{ElabMeth}}\:\vec{\VV{meth}}\:\td\\
1236−\vec{\MO{ElabParent}}\:\tc
1614+\MO{Elab}\;
1615+\AR{(\RW{data}\;\TC{C}\Hab(\ta\Hab\ttt)\to\Type\;\iwhere\\
1616+\hg\DC{InstanceC}\Hab\piconst{\tc}\td\to\TC{C}\;\ta)}\\
1617+\vec{\MO{ElabMeth}}\;(\vec{\VV{meth}}\Hab\ttt)\\
1618+\vec{\MO{ElabParent}}\;\tc
12371619}
12381620\medskip\\
1239−\MO{ElabMeth}\:(\vf\Hab\vt)\\
1240−\hg\hg\mq\:\RW{do}\:\AR{
1241−\MO{Elab}\:(\vf\Hab\TC{C}\:\ta\to\vt)\\
1242−\MO{Elab}\:(\vf\:(\DC{InstanceC}\:\vec{\VV{meth}})\:=\:\vec{\VV{meth}[\vf]})
1621+\MO{ElabMeth}\;(\vf\Hab\vt)\\
1622+\hg\hg\mq\;\RW{do}\;\AR{
1623+\MO{Elab}\;(\vf\Hab\TC{C}\;\ta\to\vt)\\
1624+\MO{Elab}\;(\vf\;(\DC{InstanceC}\;\vec{\VV{meth}})\;=\;\vec{\VV{meth}[\vf]})
12431625}
12441626\medskip\\
1245−\MO{ElabParent}\:\vc\\
1246−\hg\hg\mq\:\RW{do}\:\AR{
1247−\MO{Elab}\:(\VV{cC}\Hab\TC{C}\:\ta\to\vc)\\
1248−\MO{Elab}\:(\VV{cC}\:(\DC{InstanceC}\:\carg{\vc'}\:\vec{\VV{meth}})\:=\:\vc')
1627+\MO{ElabParent}\;\vc\\
1628+\hg\hg\mq\;\RW{do}\;\AR{
1629+\MO{Elab}\;(\VV{cC}\Hab\TC{C}\;\ta\to\vc)\\
1630+\MO{Elab}\;(\VV{cC}\;(\DC{InstanceC}\;\carg{\vc'}\;\vec{\VV{meth}})\;=\;\vc')
12491631}
12501632}
12511633}
12521634
12531635\noindent
1254−Then \texttt{instance} declarations are elaborated as follows:
1636+Then \texttt{instance} declarations are elaborated as follows. One complication
1637+is that the function definitions in an \texttt{instance} declaration do not
1638+have explicit types, so we must retrieve the method types from the system state
1639+and substitute $\TC{C}\;\ttt$, using $\MO{ExpandTypes}$:
12551640
12561641\DM{
12571642\AR{
1258−\MO{Elab}\:(\iinstance\;\piconst{\tc}\TC{C}\:\ttt\:\iwhere\:\td)\\
1259−\hg\hg\mq\:\RW{do}\:\AR{
1260−(\vec{\VV{meth}}, \vec{\VV{ty}})\gets\td\\
1261−\vec{\VV{ty'}}\:=\:\vec{\VV{ty}}[\ttt/\ta]\\
1262−\MO{Elab}\:(\FN{instanceC}\Hab\piconst{\tc}\TC{C}\:\ttt)\\
1263−\MO{Elab}\:\AR{
1264−(\FN{instanceC}\:=\:\DC{InstanceC}\;\vec{\VV{meth'}}\;\iwhere
1643+\MO{Elab}\;(\iinstance\;\piconst{\tc}\TC{C}\;\ttt\;\iwhere\;\td)\\
1644+\hg\hg\mq\;\RW{do}\;\AR{
1645+(\vec{\VV{meth}}, \vec{\VV{ty}})\gets\MO{ExpandTypes}\;\td\\
1646+\vec{\VV{ty'}}\;=\;\vec{\VV{ty}}[\ttt/\ta]\\
1647+\MO{Elab}\;(\FN{instanceC}\Hab\piconst{\tc}\TC{C}\;\ttt)\\
1648+\MO{Elab}\;\AR{
1649+(\FN{instanceC}\;=\;\DC{InstanceC}\;\vec{\VV{meth'}}\;\iwhere
12651650\\
12661651\hg\vec{\VV{meth'}}\Hab\vec{\VV{ty'}}\\
12671652\hg\td
@@ -1295,15 +1680,15 @@ basic primitive for proof search, and is defined as follows:
12951680
12961681\DM{
12971682\AR{
1298−\MO{Trivial}\:\mq\:
1299−\RW{do}\:\AR{
1683+\MO{Trivial}\;\mq\;
1684+\RW{do}\;\AR{
13001685 (\tv\Hab\ttt)\gets\MO{Context}\\
1301− \MO{TryAll}\:\tv
1686+ \MO{TryAll}\;\tv
13021687 }
13031688\medskip\\
1304−\MO{TryAll}\:(\vv_1,\vv_2\ldots)\:\mq\:\MO{Try}\:(\MO{Fill}\:\vv_1)\:(\MO{TryAll}\:\vv_2\ldots)
1689+\MO{TryAll}\;(\vv_1,\vv_2\ldots)\;\mq\;\MO{Try}\;(\MO{Fill}\;\vv_1)\;(\MO{TryAll}\;\vv_2\ldots)
13051690\\
1306−\MO{TryAll}\:\langle\rangle\:\mq\:\MO{Fail}
1691+\MO{TryAll}\;\langle\rangle\;\mq\;\MO{Fail}
13071692}
13081693}
13091694
@@ -1324,11 +1709,11 @@ applying every type class instance, and attempting to resolve the instance's par
13241709recursively. Given an instance $\vI$ with parameters $\ta$:
13251710
13261711\DM{
1327−\MO{TryInstance}\:(\vI\:\ta)\:\mq\:\RW{do}\;
1712+\MO{TryInstance}\;(\vI\;\ta)\;\mq\;\RW{do}\;
13281713\AR{
1329−\vec{\MO{Claim}}\:(\tx\Hab\ta)\\
1330−\ttinterp{\vI\:\tx}\\
1331−\vec{\MO{Focus}}\:\tx;\;\vec{\MO{Instance}}
1714+\vec{\MO{Claim}}\;(\tx\Hab\ta)\\
1715+\ttinterp{\vI\;\tx}\\
1716+\vec{\MO{Focus}}\;\tx;\;\vec{\MO{Instance}}
13321717}
13331718}
13341719
@@ -1336,13 +1721,13 @@ We define $\MO{Instance}$ as follows, using $\MO{AllInstances}$ to retrieve
13361721all possible type class instances in the form required by $\MO{TryInstance}$:
13371722
13381723\DM{
1339−\MO{Instance}\:\mq\:
1340−\MO{Try}\:
1724+\MO{Instance}\;\mq\;
1725+\MO{Try}\;
13411726\AR{
13421727\MO{Trivial}\\
1343−(\RW{do}\:\AR{
1728+(\RW{do}\;\AR{
13441729\ti\gets\MO{AllInstances}\\
1345−\vec{\MO{TryInstance}}\:\ti
1730+\vec{\MO{TryInstance}}\;\ti
13461731)
13471732}
13481733}
@@ -1386,9 +1771,9 @@ and $\icase$ expressions:
13861771\begin{array}{rll@{\hg}rll}
13871772\ve ::= & \ldots \\
13881773\mid & \mvar{\vx} & (\mbox{metavariable}) &
1389−\mid & \icase\:\ve\:\iof\:\vec{\VV{alt}} & (\mbox{case expression}) \\
1774+\mid & \icase\;\ve\;\iof\;\vec{\VV{alt}} & (\mbox{case expression}) \\
13901775\medskip\\
1391−\VV{alt} ::= & \ve\:\fatarrow\:\ve & (\mbox{case alternative})\\
1776+\VV{alt} ::= & \ve\;\fatarrow\;\ve & (\mbox{case alternative})\\
13921777\end{array}
13931778}
13941779}
@@ -1418,7 +1803,7 @@ We can inspect the type of \texttt{append\_rec} at the \Idris{} prompt:
14181803\begin{SaveVerbatim}{appendrec}
14191804
14201805*vec> :t append_rec
1421−append_rec : (a : Set) -> (m : Nat) -> (n : Nat) -> a ->
1806+append_rec : (a : Type) -> (m : Nat) -> (n : Nat) -> a ->
14221807 Vect a n -> Vect a m -> Vect a (n + m)
14231808
14241809\end{SaveVerbatim}
@@ -1441,12 +1826,12 @@ Elaborating a metavariable involves adding a new top level definition which is a
14411826to all of the variables in local scope.
14421827
14431828\DM{
1444−\ttinterp{\mvar{\vx}}\:\mq\:
1829+\ttinterp{\mvar{\vx}}\;\mq\;
14451830\edo{
14461831(\tv\Hab\ttt)\gets\MO{Context}\\
14471832\vT\gets\MO{Type}\\
1448−\MO{TTDecl}\:(\vx\Hab(\tv\Hab\ttt)\to\vT)\\
1449−\ttinterp{\vx\:\tv}
1833+\MO{TTDecl}\;(\vx\Hab(\tv\Hab\ttt)\to\vT)\\
1834+\ttinterp{\vx\;\tv}
14501835}
14511836}
14521837
@@ -1484,14 +1869,14 @@ and elaborate it:
14841869
14851870\DM{
14861871\AR{
1487−\ttinterp{\icase\:\ve\:\iof\:\vec{\VV{alt}}}\:\mq\:
1872+\ttinterp{\icase\;\ve\;\iof\;\vec{\VV{alt}}}\;\mq\;
14881873\edo{
1489−\ttinterp{\ilet{\VV{scrutinee}}{\ve}\:\mvar{\VV{xcase}}}\\
1874+\ttinterp{\ilet{\VV{scrutinee}}{\ve}\;\mvar{\VV{xcase}}}\\
14901875(\tv\Hab\ttt)\gets\MO{Context}\\
1491−\vec{\MO{MkCase}}\:\tv\:\VV{alt}\\
1876+\vec{\MO{MkCase}}\;\tv\;\VV{alt}\\
14921877}
14931878\medskip\\
1494−\MO{MkCase}\:\tv\:(\vl\:\fatarrow\:\vr)\:\mq\:\MO{Elab}\:(\VV{xcase}\:\tv\:\vl\:=\:\vr)
1879+\MO{MkCase}\;\tv\;(\vl\;\fatarrow\;\vr)\;\mq\;\MO{Elab}\;(\VV{xcase}\;\tv\;\vl\;=\;\vr)
14951880}
14961881}
14971882
papers/impl-paper/hll.tex+131−109
@@ -12,7 +12,8 @@ covering the most important features. A full tutorial is available elsewhere
1212
1313\subsection{Preliminaries}
1414
15−\Idris{} defines several primitive types: \tTC{Int}, \tTC{Integer} and
15+\Idris{} defines several primitive types: fixed width integers
16+\tTC{Int}, arbitrary width integers \tTC{Integer}, and
1617\tTC{Float} for numeric operations, \tTC{Char} and \tTC{String} for
1718text manipulation, and \tTC{Ptr} which represents foreign pointers.
1819There are also several data types declared in the library, including
@@ -25,7 +26,7 @@ list of imports and a collection of definitions and declarations, for example:
2526
2627\begin{SaveVerbatim}{constprims}
2728
28−module main
29+module Main
2930
3031x : Int
3132x = 42
@@ -40,14 +41,14 @@ main = putStrLn ("The answer is " ++ show x)
4041Like Haskell, the main function
4142is called \texttt{main}, and input and output is managed with an \texttt{IO}
4243monad. Unlike Haskell, however, a single colon indicates \texttt{:} a type
43−declaration, emphasising the importance of types,
44−and \remph{all} functions must have a top level type
45−declaration. This is due to type inference being, in general,
44+signature, emphasising the importance of types,
45+and \remph{all} top level functions must have a type
46+signature. This is due to type inference being, in general,
4647undecidable for languages with
4748dependent types.
4849
4950A module declaration also opens a \remph{namespace}. The fully qualified names
50−declared in this module are \texttt{main.x} and \texttt{main.main}.
51+declared in this module are \texttt{Main.x} and \texttt{Main.main}.
5152
5253
5354\subsection{Types and Functions}
@@ -66,8 +67,7 @@ data List a = Nil | (::) a (List a) -- Polymorphic lists
6667\useverb{natlist}
6768
6869\noindent
69−The above declarations are taken from the standard library. Unary natural
70−numbers can be either zero, or
70+Unary natural numbers can be either zero, or
7171the successor of another natural number (\texttt{S k}).
7272Lists can either be empty (\texttt{Nil})
7373or a value added to the front of another list (\texttt{x :: xs}).
@@ -166,24 +166,15 @@ reverse xs = revAcc [] xs where
166166Indentation is significant --- functions in the \texttt{where} block must be indented
167167further than the outer function.
168168
169−\textbf{Scope:}
170−Any names which are visible in the outer scope are also visible in the \texttt{where}
171−clause (unless they have been redefined, such as \texttt{xs} here).
172−\emph{However}, names which appear in the type are \emph{not} automatically
173−in scope. In particular,
174−in the above example, the \texttt{a} in the top level type and the \texttt{a} in the
175−auxiliary definition \texttt{revAcc} are \emph{not} the same. If this is the required
176−behaviour, the \texttt{a} can be brought into scope as follows:
177−
178−\begin{SaveVerbatim}{revwhereb}
179−
180−reverse : List a -> List a
181−reverse {a} xs = revAcc [] xs where
182− revAcc : List a -> List a -> List a
183− ...
184−
185−\end{SaveVerbatim}
186−\useverb{revwhereb}
169+\textbf{Remark (scope):}
170+Any names which are visible in the outer scope are also visible in the
171+\texttt{where} clause (unless they are redefined in the \texttt{where} clause,
172+such as \texttt{xs} here). A name which appears only in the type will be in
173+scope in the \texttt{where} clause if it is a \remph{parameter} to one of the
174+types, i.e. it is fixed across the entire structure. In particular, this means
175+that the \texttt{a} in the definition of \texttt{reverse} above is the
176+\remph{same} \texttt{a} as in the definition of \texttt{revAcc}, as \texttt{a}
177+is a parameter of \texttt{List}.
187178
188179\subsubsection{Dependent Types}
189180
@@ -193,7 +184,7 @@ literature. In \Idris{}, vectors are declared as follows:
193184
194185\begin{SaveVerbatim}{vect}
195186
196−data Vect : Set -> Nat -> Set where
187+data Vect : Type -> Nat -> Type where
197188 Nil : Vect a O
198189 (::) : a -> Vect a k -> Vect a (S k)
199190
@@ -201,19 +192,23 @@ data Vect : Set -> Nat -> Set where
201192\useverb{vect}
202193
203194\noindent
204−Note that this uses the same constructor names as for \tTC{List}. Ad-hoc
205−name overloading such as this is accepted by \Idris{}, provided that the names
206−are declared in different namespaces (in practice, normally in different modules).
207−Ambiguous constructor names are resolved by type.
208−
209−This declares a family of types, which requires a different form of declaration
210−from the simple type declarations above. It resembles a Haskell GADT
211−declaration: it explicitly states the type
195+Note that this uses the same constructor names as for \tTC{List}. Ad-hoc name
196+overloading such as this is accepted by \Idris{}, provided that the names are
197+declared in different namespaces (in practice, normally in different modules)
198+so that the names are different internally. Namespace resolution can be made
199+explicitly (e.g. \texttt{List.Nil} or \texttt{Vect.Nil}) or more commonly
200+by type.
201+
202+The above declaration creates a family of types, and requires a different form
203+of declaration from the simple type declarations above. It resembles a Haskell
204+GADT declaration: it explicitly states the type
212205of the type constructor \tTC{Vect} --- it takes a type and a \tTC{Nat} as an
213−argument, where \tTC{Set} stands for the type of types. We say that \tTC{Vect}
214−is \emph{parameterised} by a type, and \emph{indexed} over \tTC{Nat}. Each
215−constructor targets a different part of the family of types. \tDC{Nil} can only
216−be used to construct vectors with zero length, and \tDC{::} to construct
206+argument, where \tTC{Type} stands for the type of types. We say that \tTC{Vect}
207+is \emph{parameterised} by a type, and \emph{indexed} over \tTC{Nat}.
208+The distinction between parameters and indices is that a parameter is fixed
209+across an entire structure, whereas an index may vary.
210+Each constructor targets a different part of the family of types. \tDC{Nil} can
211+only be used to construct vectors with zero length, and \tDC{::} to construct
217212vectors with non-zero length. The type of \tDC{::} states explicitly that an element
218213of type \texttt{a} and a tail of type \texttt{Vect a k} (i.e., a vector of length \texttt{k})
219214combine to make a vector of length \texttt{S k}.
@@ -227,20 +222,20 @@ library, appends two \tTC{Vect}s:
227222\begin{SaveVerbatim}{vapp}
228223
229224(++) : Vect A n -> Vect A m -> Vect A (n + m)
230−(++) Nil ys = ys
231−(++) (x :: xs) ys = x :: xs ++ ys
225+Nil ++ ys = ys
226+(x :: xs) ++ ys = x :: xs ++ ys
232227
233228\end{SaveVerbatim}
234229\useverb{vapp}
235230
236−\subsubsection{The Finite Sets}
231+\subsubsection*{Example: The Finite Sets}
237232
238233Finite sets, as the name suggests, are sets with a finite number of elements.
239234They are declared as follows in the library:
240235
241236\begin{SaveVerbatim}{findecl}
242237
243−data Fin : Nat -> Set where
238+data Fin : Nat -> Type where
244239 fO : Fin (S k)
245240 fS : Fin k -> Fin (S k)
246241
@@ -281,11 +276,10 @@ need for a run-time bounds check. The type checker guarantees that the location
281276is no larger than the length of the vector.
282277
283278Note also that there is no case for \texttt{Nil} here. It would be impossible
284−to apply such a case ---
285−since there is no element of \texttt{Fin O}, and the location is a
286−\texttt{Fin n}, then \texttt{n} can not be \tDC{O}. As a result, attempting to
287−look up an element in an empty vector would give a compile time type error,
288−since it would force \texttt{n} to be \tDC{O}.
279+to apply such a case --- since there is no element of \texttt{Fin O}, and the
280+location is a \texttt{Fin n}, then \texttt{n} can not be \tDC{O}. As a result,
281+attempting to look up an element in an empty vector would give a compile time
282+type error.
289283
290284\subsubsection{Implicit Arguments}
291285
@@ -317,19 +311,18 @@ their types, to be inferred by the machine. These types could also be given expl
317311
318312\begin{SaveVerbatim}{vindeximpty}
319313
320−index : {a:Set} -> {n:Nat} -> Fin n -> Vect a n -> a
314+index : {a:Type} -> {n:Nat} -> Fin n -> Vect a n -> a
321315
322316\end{SaveVerbatim}
323317\useverb{vindeximpty}
324318
325319\noindent
326−Implicit arguments, given in braces \texttt{\{\}} in the type declaration, are not given in
327−applications of \texttt{index}; their values can be inferred from the types of
328−the \texttt{Fin n} and \texttt{Vect a n} arguments. Any name which appears as a parameter
329−or index in a type declaration, but which is otherwise free, will be automatically
330−bound as an implicit argument. Indeed, binding arguments in this way is the essence
331−of dependent types.
332−Implicit arguments can still be given explicitly in applications, using the syntax
320+Implicit arguments, given in braces \texttt{\{\}} in the type signature, are
321+not given in applications of \texttt{index}; their values can be inferred from
322+the types of the \texttt{Fin n} and \texttt{Vect a n} arguments. Any name which
323+appears as a parameter or index in a type signature, but which is otherwise
324+free, will be automatically bound as an implicit argument. Implicit arguments
325+can still be given explicitly in applications, using the syntax
333326\texttt{\{a=value\}} and \texttt{\{n=value\}}, for example:
334327
335328\begin{SaveVerbatim}{vindexexp}
@@ -354,6 +347,41 @@ index : (i:Fin n) -> (xs:Vect a n) -> a
354347This can be useful for improving the readability of type signatures, particularly
355348where the name suggests the argument's purpose.
356349
350+\subsubsection{Totality Checking}
351+
352+Internally, \Idris{} programs are checked for \emph{totality} --- that they
353+produce an answer in finite time for all possible inputs --- but they are not
354+\emph{required} to be total by default. Totality checking serves two
355+purposes: firstly, if a program terminates for all inputs
356+then its type gives a strong
357+guarantee about the properties specified by its type; secondly, we can
358+optimise total programs more aggressively~\cite{Brady2003}.
359+
360+Totality checking can be enforced by using the \texttt{total} keyword. For
361+example, recall the \texttt{vAdd} function:
362+
363+\begin{SaveVerbatim}{vadd}
364+
365+total vAdd : Num a => Vect a n -> Vect a n -> Vect a n
366+vAdd [] [] = []
367+vAdd (x :: xs) (y :: ys) = x + y :: vAdd xs ys
368+
369+\end{SaveVerbatim}
370+\useverb{vadd}
371+
372+\noindent
373+The elaborator can verify that this is total by checking that it covers all
374+possible patterns --- in this case, both arguments must be of the same form
375+as the type requires that the input vectors are the same length --- and that
376+recursive calls are on structurally smaller values. The totality checker is
377+implemented independently of the type checker and elaborator presented in the
378+remainder of this paper. While we could consider building totality proofs
379+by translating functions to eliminators~\cite{McBride2004a} we have taken
380+the more pragmatic approach of allowing more flexibility for the programmer
381+at the expense of simplicity of totality checking. \Idris{} also supports
382+coinductive definitions with a corresponding productivity checker, although
383+futher details are beyond the scope of this paper.
384+
357385\subsection{Type Classes}
358386
359387\Idris{} supports overloading in two ways. Firstly, as we have already seen with
@@ -427,7 +455,7 @@ to a \texttt{String}:
427455
428456instance Show a => Show (Vect a n) where
429457 show xs = "[" ++ show' xs ++ "]" where
430− show' : Vect a n' -> String
458+ show' : Vect a n -> String
431459 show' Nil = ""
432460 show' (x :: Nil) = show x
433461 show' (x :: xs) = show x ++ ", " ++ show' xs
@@ -435,15 +463,16 @@ instance Show a => Show (Vect a n) where
435463\end{SaveVerbatim}
436464\useverb{showvec}
437465
438−\noindent
439−\textbf{Remark: } The type of the auxiliary function \texttt{show'} is
440−important. The type variables \texttt{a} and \texttt{n} which are part of the
441−instance declaration for \texttt{Show (Vect a n)} are fixed across the entire
442−instance declaration. As a result, \texttt{a} need not be constrained
443−again. Furthermore, it means that if \texttt{n} is used again in the type, it refers
444−to the (fixed) length of the outermost list \texttt{xs}. Therefore,
445−there is a different name for the length \texttt{n'} in \texttt{show'}.
466+%\noindent
467+%\textbf{Remark: } The type of the auxiliary function \texttt{show'} is
468+%important. The type variables \texttt{a} and \texttt{n} which are part of the
469+%instance declaration for \texttt{Show (Vect a n)} are fixed across the entire
470+%instance declaration. As a result, \texttt{a} need not be constrained
471+%again. Furthermore, it means that if \texttt{n} is used again in the type, it refers
472+%to the (fixed) length of the outermost list \texttt{xs}. Therefore,
473+%there is a different name for the length \texttt{n'} in \texttt{show'}.
446474
475+\noindent
447476Like Haskell type classes, default definitions can be given in the class declaration.
448477Otherwise, all methods must be given in an instance. For example, there is an
449478\texttt{Eq} class:
@@ -484,41 +513,41 @@ class Eq a => Ord a where
484513
485514\subsection{Matching on intermediate values}
486515
487−\subsubsection{\texttt{let} bindings}
488−
489−Intermediate values can be calculated using \texttt{let} bindings:
490−
491−\begin{SaveVerbatim}{letb}
492−
493−mirror : List a -> List a
494−mirror xs = let xs' = rev xs in
495− app xs xs'
496−
497−\end{SaveVerbatim}
498−\useverb{letb}
499−
500−\noindent
501−Pattern matching is also supported in \texttt{let} bindings. For example, extracting
502−fields from a record can be achieved as follows, as well as by pattern matching at the top level:
503−
504−\begin{SaveVerbatim}{letp}
505−
506−data Person = MkPerson String Int
516+%\subsubsection{\texttt{let} bindings}
517+%
518+%Intermediate values can be calculated using \texttt{let} bindings:
519+%
520+%\begin{SaveVerbatim}{letb}
521+%
522+%mirror : List a -> List a
523+%mirror xs = let xs' = rev xs in
524+% app xs xs'
525+%
526+%\end{SaveVerbatim}
527+%\useverb{letb}
528+%
529+%\noindent
530+%Pattern matching is also supported in \texttt{let} bindings. For example, extracting
531+%fields from a record can be achieved as follows, as well as by pattern matching at the top level:
532+%
533+%\begin{SaveVerbatim}{letp}
534+%
535+%data Person = MkPerson String Int
536+%
537+%showPerson : Person -> String
538+%showPerson p = let MkPerson name age = p in
539+% name ++ " is " ++ show age ++ " years old"
540+%
541+%\end{SaveVerbatim}
542+%\useverb{letp}
507543
508−showPerson : Person -> String
509−showPerson p = let MkPerson name age = p in
510− name ++ " is " ++ show age ++ " years old"
511−
512−\end{SaveVerbatim}
513−\useverb{letp}
514544\subsubsection{\texttt{case} expressions}
515545
516−Another way of inspecting intermediate values of \emph{simple} types
517−is to use a \texttt{case} expression.
518−For example, \texttt{list\_lookup}
519−looks up an index in a list, returning \texttt{Nothing} if the index is out
520−of bounds. This can be used this to write \texttt{lookup\_default}, which
521−looks up an index and returns a default value if the index is out of bounds:
546+Intermediate values of \emph{non-dependent} types can be inspected using a
547+\texttt{case} expression. For example, \texttt{list\_lookup} looks up an index
548+in a list, returning \texttt{Nothing} if the index is out of bounds. This can
549+be used this to write \texttt{lookup\_default}, which looks up an index and
550+returns a default value if the index is out of bounds:
522551
523552\begin{SaveVerbatim}{listlookup}
524553
@@ -530,17 +559,10 @@ lookup_default i xs def = case list_lookup i xs of
530559\end{SaveVerbatim}
531560\useverb{listlookup}
532561
533−The \texttt{case} construct is intended for simple analysis
534−of intermediate expressions to avoid the need to write auxiliary functions, and is
535−also used internally to implement pattern matching \texttt{let} and lambda bindings.
536−It will \emph{only} work if:
537−
538−\begin{itemize}
539−\item Each branch \emph{matches} a value of the same type, and \emph{returns} a
540−value of the same type.
541−\item The type of the result is ``known''. i.e. the type of the expression can be
542−determined \emph{without} type checking the \texttt{case}-expression itself.
543−\end{itemize}
562+The \texttt{case} construct is intended for simple analysis of intermediate
563+expressions to avoid the need to write auxiliary functions. It will
564+\emph{only} work if each branch \emph{matches} a value of the same type, and
565+\emph{returns} a value of the same type.
544566
545567\subsubsection{The \texttt{with} rule}
546568
@@ -578,7 +600,7 @@ plus one:
578600
579601\begin{SaveVerbatim}{parity}
580602
581−data Parity : Nat -> Set where
603+data Parity : Nat -> Type where
582604 even : Parity (n + n)
583605 odd : Parity (S (n + n))
584606
papers/impl-paper/impldtp.tex+7−6
@@ -10,13 +10,13 @@
1010\usepackage{epsfig}
1111%\usepackage{path}
1212\usepackage{url}
13−%\usepackage{amsmath,amssymb}
13+%\usepackage{amsmath}
1414\usepackage{fancyvrb}
1515\usepackage{todonotes}
1616
1717\newenvironment{template}{\sffamily}
1818
19−\usepackage{graphics,epsfig}
19+%\usepackage{graphics,epsfig}
2020\usepackage{stmaryrd}
2121
2222\input{./macros.ltx}
@@ -131,10 +131,11 @@ implementation of new high level language constructs.
131131
132132\section*{Acknowledgements}
133133
134−This work was funded by the Scottish Informatics and Computer Science
135−Alliance (SICSA) and by EU Framework 7 Project No. 248828 (ADVANCE).
136−My thanks to Kevin Hammond and Vilhelm Sj\"{o}berg for their comments
137−on an earlier draft of this paper.
134+This work was funded by the Scottish Informatics and Computer Science Alliance
135+(SICSA) and by EU Framework 7 Project No. 248828 (ADVANCE). My thanks to
136+Philip H\"{o}lzenspies, Kevin Hammond and Vilhelm Sj\"{o}berg for their
137+comments on an earlier draft of this paper, and to the anonymous referees for
138+their many insightful and constructive comments.
138139
139140\bibliographystyle{jfp}
140141\bibliography{library.bib}
papers/impl-paper/intro.tex+35−41
@@ -39,12 +39,12 @@ How can we achieve both of these goals?
3939
4040This paper describes a method for elaborating a high level dependently typed
4141functional programming language to a low level core language based on dependent
42−type theory. The method involves building an Embedded Domain Specific Language
43−(EDSL) for constructing programs in the core language, using \emph{tactics}
44−directed by high level program syntax.
45−As we shall see, this method allows higher level language constructs to be
46−constructed in a straightforward manner, without compromising the simplicity
47−of the underlying type theory.
42+type theory. The method involves building an elaboration monad which captures
43+the state of incomplete programs and a collection of \emph{tactics} for
44+refining programs, directed by high level program syntax. As we shall see,
45+this method allows higher level language constructs to be constructed in a
46+straightforward manner, without compromising the simplicity of the underlying
47+type theory.
4848
4949\subsection{Contributions}
5050
@@ -55,18 +55,18 @@ unification algorithm \cite{Miller1992} and an evaluator. However, it is less
5555well understood how to combine these components effectively into a practical
5656programming language.
5757
58−The primary contribution of this paper is
59−an EDSL based method for translating programs in a
60−high level dependently typed programming language to a small core type theory,
61−\TT{}, based on UTT \cite{luo1994}. The paper describes the structure of the
62−EDSL including proof and system state, and introduces a collection of \remph{tactics}
63−for manipulating incomplete programs.
64−Secondly, the paper gives a detailed description of the core type theory used
65−by \Idris{}, including a full description of the typing rules. Finally, through
66−describing the EDSL and the specific tactics, the paper shows how to extend
67−\Idris{} with higher level features.
68−While we apply these ideas to \Idris{} specifically, the method for term construction
69−is equally applicable to other typed programming languages.
58+The primary contribution of this paper is a tactic based method for translating
59+programs in a high level dependently typed programming language to a small core
60+type theory, \TT{}, based on UTT \cite{luo1994}. The paper describes the
61+structure of an elaboration monad capturing proof and system state, and
62+introduces a collection of \remph{tactics} for manipulating incomplete
63+programs. Secondly, the paper gives a detailed description of the core type
64+theory used by \Idris{}, including a full description of the typing rules.
65+Finally, through describing the specific tactics, the paper shows how to extend
66+\Idris{} with higher level features. While we apply these ideas to \Idris{}
67+specifically, the method for term construction is equally applicable to other
68+typed programming languages, and indeed the tactics themselves are applicable
69+to any high level language which can be explained in terms of \TT{}.
7070
7171The paper is structured as follows: Section \ref{sect:hll} gives an overview of
7272programming in \Idris{}, introducing the high level constructs which will be
@@ -120,10 +120,10 @@ vAdd (x :: xs) (y :: ys) = x + y :: vAdd xs ys
120120This illustrates some basic features of \Idris{}:
121121
122122\begin{itemize}
123−\item A single colon is used for type declarations, and a double colon for the
123+\item A single colon is used for type signatures, and a double colon for the
124124cons operator.
125−\item Functions are defined by pattern matching, with a top level type declaration.
126−Names which are free in the type declaration (\texttt{a} and \texttt{n}) here
125+\item Functions are defined by pattern matching, with a top level type signature.
126+Names which are free in the type signature (\texttt{a} and \texttt{n}) here
127127are implicitly bound.
128128\item The type system ensures that both input vectors are the same length (\texttt{n})
129129and have the same element type (\texttt{a}), and that the element type and length
@@ -136,35 +136,29 @@ of the vector \texttt{a} must be numeric and therefore supports the \texttt{+} o
136136\Idris{} programs elaborate into a small core language, \TT{}, which is a $\lambda$-calculus
137137with dependent types, augmented with algebraic data types and pattern matching.
138138\TT{} programs are fully explicitly typed, including the names \texttt{a} and \texttt{n}
139−in the type declaration, and the names bound in each pattern match clause.
139+in the type signature, and the names bound in each pattern match clause.
140140Type classes are also made explicit.
141141The \TT{} translation of \texttt{vAdd} is:
142142
143143\DM{
144144\AR{
145−\begin{array}{ll}
146−\FN{vAdd} & \Hab(\va\Hab\Set)\to(\vn\Hab\Nat)\to\TC{Num}\:\va\to
147− \Vect\:\va\:\vn\to\Vect\:\va\:\vn\to\Vect\:\va\:\vn\\
148−\end{array}
149−\\
150−\begin{array}{lccccccc}
151−\multicolumn{5}{l}{
152−\RW{var}\:\va\Hab\Set,\:\vc\Hab\TC{Num}\;\va\SC}\\
153−\hg\FN{vAdd} & \va & \Z & \vc & (\DC{Nil}\;\va) & (\DC{Nil}\;\va) & \Ret{\DC{Nil}\;\va} \\
154−\multicolumn{5}{l}{
155−\RW{var}\:\AR{
156−\va\Hab\Set,\:\vk\Hab\Nat,\;\vc\Hab\TC{Num}\;\va,\\
145+\FN{vAdd} \Hab(\va\Hab\Type)\to(\vn\Hab\Nat)\to\TC{Num}\;\va\to
146+ \Vect\;\va\;\vn\to\Vect\;\va\;\vn\to\Vect\;\va\;\vn\\
147+\RW{var}\;\va\Hab\Type,\;\vc\Hab\TC{Num}\;\va\SC\\
148+\hg\FN{vAdd} \; \va \; \Z \; \vc \; (\DC{Nil}\;\va) \; (\DC{Nil}\;\va) \;
149+\cq\;\DC{Nil}\;\va \\
150+\RW{var}\;\AR{
151+\va\Hab\Type,\;\vk\Hab\Nat,\;\vc\Hab\TC{Num}\;\va,\\
157152\vx\Hab\va,\;\vxs\Hab\Vect\;\va\;\vk,\;
158153\vy\Hab\va,\;\vys\Hab\Vect\;\va\;\vk
159154\SC
155+\\
156+\FN{vAdd} \; \va \; (\suc\;\vk) \; \vc
157+ \; ((\DC{::})\;\va\;\vk\;\vx\;\vxs)
158+ \; ((\DC{::})\;\va\;\vk\;\vy\;\vys)
159+ \\
160+ \hg\hg\cq\:((\DC{::})\;\va\;\vk\;((+)\;\vc\;\vx\;\vy)\; (\FN{vAdd}\;\va\;\vk\;\vc\;\vxs\;\vys))
160161}
161−}\\
162−\hg\FN{vAdd} & \va & (\suc\;\vk) & \vc
163− & ((\DC{::})\;\va\;\vk\;\vx\;\vxs)
164− & ((\DC{::})\;\va\;\vk\;\vy\;\vys)
165− & \\
166− & & \MRet{5}{((\DC{::})\;\va\;\vk\;((+)\;\vc\;\vx\;\vy)\; (\FN{vAdd}\;\va\;\vk\;\vc\;\vxs\;\vys))}
167−\end{array}
168162}
169163}
170164
papers/impl-paper/library.bib+1993−1039
@@ -1,126 +1,155 @@
1−Automatically generated by Mendeley 1.3.1
1+Automatically generated by Mendeley 1.6
22Any changes to this file will be lost if it is regenerated by Mendeley.
33
4−@book{Chlipala2012,
5−author = {Chlipala, Adam},
6−file = {:Users/edwin/Documents/Mendeley Desktop/Chlipala/Unknown/Chlipala - 2012 - Certified Programming with Dependent Types.pdf:pdf},
7−title = {{Certified Programming with Dependent Types}},
8−year = {2012}
4+@techreport{Haskell98,
5+abstract = {Haskell is the world's leading lazy functional programming language and is widely used in teaching, research, and applications. The language continues to develop rapidly, but in 1998 the programming community decided to capture a stable snapshot of the language by introducing Haskell 98. This book constitutes the agreed definition of Haskell 98, the language itself as well as its supporting libraries, and should be a standard reference work for anyone involved in research, teaching, or applications. All Haskell compilers support Haskell 98, so professioanls and educators have a stable base for their work.},
6+author = {{Peyton Jones}, Simon},
7+booktitle = {Language},
8+editor = {Jones, Simon Peyton},
9+isbn = {0521826144},
10+number = {1},
11+publisher = {Cambridge University Press},
12+title = {{Haskell 98 Language and Libraries: The Revised Report}},
13+url = {http://www.amazon.ca/exec/obidos/redirect?tag=citeulike09-20&amp;path=ASIN/0521826144},
14+volume = {13},
15+year = {2002}
916}
10−@inproceedings{czarnecki2004dsl,
11−author = {Czarnecki, K. and O’Donnell, J. and Striegnitz, J. and Taha, W.},
12−booktitle = {Domain-Specific Program Generation},
13−file = {:Users/edwin/Documents/Mendeley Desktop/Czarnecki et al/Domain-Specific Program Generation/Czarnecki et al. - 2004 - DSL implementation in MetaOCaml, Template Haskell, and C.pdf:pdf},
14−pages = {51--72},
15−publisher = {Springer},
16−title = {{DSL implementation in MetaOCaml, Template Haskell, and C++}},
17−url = {http://www.springerlink.com/index/NL620EL7N94M161H.pdf},
18−year = {2004}
17+@inproceedings{McBride2006,
18+author = {McBride, C and Goguen, H and McKinna, J},
19+booktitle = {Types for Proofs and Programs {(TYPES 2006)}},
20+title = {{A few constructions on constructors}},
21+url = {http://www.springerlink.com/index/P4863U0M41396254.pdf},
22+year = {2006}
1923}
20−@phdthesis{Brady2005,
21−author = {Brady, Edwin},
22−file = {:Users/edwin/Documents/Mendeley Desktop/Brady/Unknown/Brady - 2005 - Practical Implementation of a Dependently Typed Functional Programming Language.pdf:pdf},
24+@article{McBride2005,
25+author = {McBride, Conor},
26+editor = {Vene, Varmo and Uustalu, Tarmo},
27+isbn = {3540285407},
28+journal = {Advanced Functional Programming},
2329keywords = {Dependent Types},
2430mendeley-tags = {Dependent Types},
25−school = {University of Durham},
26−title = {{Practical Implementation of a Dependently Typed Functional Programming Language}},
27−url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.150.8284&rep=rep1&type=pdf},
31+pages = {130--170},
32+publisher = {Springer},
33+series = {Lecture Notes in Computer Science},
34+title = {{Epigram: Practical programming with dependent types}},
35+url = {http://www.springerlink.com/index/96j7v5vn8tyebeky.pdf},
36+volume = {3622},
2837year = {2005}
2938}
30−@inproceedings{Kimmell2012,
31−author = {Kimmell, G and Stump, A and {Eades III}, HD and Fu, Peng and Sheard, Tim and Weirich, S and Casinghino, C and Sj\"{o}berg, V and Collins, N and Ahn, KY},
32−booktitle = {Programming Languages meets Program Verification},
33−file = {:Users/edwin/Documents/Mendeley Desktop/Kimmell et al/Programming Languages meets Program Verification/Kimmell et al. - 2012 - Equational reasoning about programs with general recursion and call-by-value semantics.pdf:pdf},
34−title = {{Equational reasoning about programs with general recursion and call-by-value semantics}},
35−url = {http://dl.acm.org/citation.cfm?id=2103780},
36−year = {2012}
37−}
38−@article{Epstein2011,
39−author = {Epstein, Jeff and Black, Andrew P and Peyton-jones, Simon},
40−institution = {Microsoft Research},
41−journal = {researchmicrosoftcom},
42−number = {Section 8},
43−pages = {1--12},
44−title = {{Haskell for the cloud}},
45−url = {http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/remote.pdf},
46−year = {2011}
47−}
48−@article{Altenkirch2010a,
49−abstract = {We begin by revisiting the idea of using a universe of types to write generic programs in a dependently typed setting by constructing a universe for Strictly Positive Types (SPTs). Here we extend this construction to cover dependent types, i.e. Strictly Positive Families (SPFs), thereby fixing a gap left open in previous work. Using the approach presented here we are able to represent all of Epigrams datatypes within Epigram including the universe of datatypes itself.},
50−author = {Altenkirch, Thorsten and Mcbride, Conor and Morris, Peter},
51−file = {:Users/edwin/Documents/Mendeley Desktop/Altenkirch, Mcbride, Morris/Citeseer/Altenkirch, Mcbride, Morris - 2010 - Generic Programming with Dependent Types.pdf:pdf},
52−journal = {Citeseer},
53−publisher = {Citeseer},
54−title = {{Generic Programming with Dependent Types}},
55−url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.129.2926&amp;rep=rep1&amp;type=pdf},
56−year = {2010}
57−}
58−@article{fisher2006next,
59−author = {Fisher, K. and Mandelbaum, Y. and Walker, D.},
60−file = {:Users/edwin/Documents/Mendeley Desktop/Fisher, Mandelbaum, Walker/Journal of the ACM/Fisher, Mandelbaum, Walker - 2010 - The next 700 data description languages.pdf:pdf},
61−journal = {Journal of the ACM},
62−number = {2},
63−pages = {1--51},
64−publisher = {ACM},
65−title = {{The next 700 data description languages}},
66−url = {http://dl.acm.org/citation.cfm?id=1111039},
67−volume = {15},
68−year = {2010}
39+@article{Okasaki1993,
40+author = {Okasaki, Chris},
41+file = {:Users/edwin/Documents/Mendeley Desktop/Okasaki/Red-Black Trees in A Functional Setting/Okasaki - Red-Black Trees in A Functional Setting - 1993.pdf:pdf},
42+journal = {Journal of functional programming},
43+title = {{Red-Black Trees in A Functional Setting}},
44+year = {1993}
6945}
70−@misc{The2012b,
71−author = {Brooks, Fred},
72−doi = {10.1093/epirev/mxr031},
73−file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/Unknown/Brooks - Unknown - The Design of Design Chapter 1.pdf:pdf},
74−isbn = {9780321702081},
75−issn = {1478-6729},
76−pmid = {22215642},
77−title = {{The Design of Design Chapter 1}}
46+@inproceedings{Hancock2000,
47+author = {Hancock, Peter and Setzer, Anton},
48+booktitle = {{Proceedings of the 14th Annual Conference of the EACSL on Computer Science Logic}},
49+file = {:Users/edwin/Documents/Mendeley Desktop/Hancock, Setzer/Interactive Programs in Dependent Type Theory/Hancock, Setzer - Interactive Programs in Dependent Type Theory - 2000.pdf:pdf},
50+isbn = {3-540-67895-6},
51+month = aug,
52+pages = {317--331},
53+title = {{Interactive Programs in Dependent Type Theory}},
54+url = {http://dl.acm.org/citation.cfm?id=647850.737221},
55+year = {2000}
7856}
79−@article{Chapman2005epigram,
80−author = {Chapman, James and Altenkirch, Thorsten and McBride, Conor},
81−file = {:Users/edwin/Documents/Mendeley Desktop/Chapman, Altenkirch, McBride/Trends in Functional Programming/Chapman, Altenkirch, McBride - 2005 - Epigram Reloaded A Standalone Typechecker for {ETT}.pdf:pdf},
82−journal = {Trends in Functional Programming},
83−publisher = {Intellect Books},
84−title = {{Epigram Reloaded: A Standalone Typechecker for {ETT}}},
85−url = {http://books.google.co.uk/books?hl=en&amp;lr=&amp;id=p0yV1sHLubcC&amp;oi=fnd&amp;pg=PA79&amp;dq=epigram+reloaded&amp;ots=x50ou0VMsm&amp;sig=7TjAGohIatNLTWsHcuNcK5hEGGY},
86−year = {2005}
57+@article{Turner2004,
58+author = {Turner, D A},
59+file = {:Users/edwin/Documents/Mendeley Desktop/Turner/Total Functional Programming/Turner - Total Functional Programming - 2004.pdf:pdf},
60+journal = {Journal of Universal Computer Science},
61+keywords = {functional programming},
62+number = {7},
63+pages = {751----768},
64+title = {{Total Functional Programming}},
65+volume = {10},
66+year = {2004}
8767}
88−@misc{TheMendeleySupportTeam2011,
89−abstract = {A quick introduction to Mendeley. Learn how Mendeley creates your personal digital library, how to organize and annotate documents, how to collaborate and share with colleagues, and how to generate citations and bibliographies.},
90−address = {London},
91−author = {{The Mendeley Support Team}},
92−booktitle = {Mendeley Desktop},
93−file = {:Users/edwin/Documents/Mendeley Desktop/The Mendeley Support Team/Mendeley Desktop/The Mendeley Support Team - 2011 - Getting Started with Mendeley.pdf:pdf},
94−keywords = {Mendeley,how-to,user manual},
95−pages = {1--16},
96−publisher = {Mendeley Ltd.},
97−title = {{Getting Started with Mendeley}},
98−url = {http://www.mendeley.com},
99−year = {2011}
68+@phdthesis{norell2007thesis,
69+author = {Norell, Ulf},
70+file = {:Users/edwin/Documents/Mendeley Desktop/Norell/Towards a practical programming language based on dependent type theory/Norell - Towards a practical programming language based on dependent type theory - 2007.pdf:pdf},
71+keywords = {Dependent Types},
72+mendeley-tags = {Dependent Types},
73+publisher = {Citeseer},
74+school = {Chalmers University of Technology},
75+title = {{Towards a practical programming language based on dependent type theory}},
76+url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.65.7934&amp;rep=rep1&amp;type=pdf},
77+year = {2007}
10078}
101−@phdthesis{Okasaki1996,
102−author = {Okasaki, Chris},
103−file = {:Users/edwin/Documents/Mendeley Desktop/Okasaki/Unknown/Okasaki - 1996 - Purely Functional Data Structures.pdf:pdf},
104−school = {Carnegie Mellon University},
105−title = {{Purely Functional Data Structures}},
106−year = {1996}
79+@article{Wu,
80+annote = {1,3
81+
82+
83+This paper describes a solution, in Haskell, of the 2012 ICFP Programming Contest task, explaining in particular how Haskell's laziness and higher order functions helped to build a solution in limited time. I enjoyed reading this paper as an experience report - it provides evidence for the importance of high level features such as purity and laziness (for example when describing the GameTrie), and shows that Haskell can handle more realistic, practical, problems such as concurrency and exceptions (for example when dealing gracefully with timeout and communication between solving threads).
84+
85+
86+My main concern with the paper is that it reads as if the reader is already familiar with the contest task. It would be useful to be more precise about the task itself in the introduction, rather than by making it implicit from the code samples. Section 1.1 describes the problem, but only in general terms - I think it would be worth extending this, and correspondingly removing some of the code. In particular, 'stepRobot' and 'updRocks' would probably be fine just with their type signatures if the problem specification was more precise.
87+
88+ },
89+author = {Wu, Nicolas and Magalh\~{a}es, Jos\'{e} Pedro and Bransen, Jeroen and Swierstra, Wouter},
90+file = {:Users/edwin/Documents/Mendeley Desktop/Wu et al/Pure and Lazy Lambda Mining/Wu et al. - Pure and Lazy Lambda Mining - Unknown.pdf:pdf},
91+title = {{Pure and Lazy Lambda Mining}}
10792}
108−@article{mcbride2008functional,
109−author = {McBride, C. and Paterson, R.},
110−file = {:Users/edwin/Documents/Mendeley Desktop/McBride, Paterson/Journal of functional programming/McBride, Paterson - 2008 - Functional pearl Applicative programming with effects.pdf:pdf},
111−journal = {Journal of functional programming},
112−number = {1},
113−pages = {1--13},
114−publisher = {Cambridge Univ Press},
115−title = {{Functional pearl: Applicative programming with effects}},
116−url = {http://journals.cambridge.org/production/action/cjoGetFulltext?fulltextid=1457860},
117−volume = {18},
93+@inproceedings{NanevskiAAMorrisett2008,
94+abstract = {We describe an axiomatic extension to the Coq proof assistant, that supports writing, reasoning about, and extracting higher-order, dependently-typed programs with side-effects. Coq already includes a powerful functional language that supports dependent types, but that language is limited to pure, total functions. The key contribution of our extension, which we call Ynot, is the added support for computations that may have effects such as non-termination, accessing a mutable store, and throwing/catching exceptions. The axioms of Ynot form a small trusted computing base which has been formally justified in our previous work on Hoare Type Theory (HTT). We show how these axioms can be combined with the powerful type and abstraction mechanisms of Coq to build higher-level reasoning mechanisms which in turn can be used to build realistic, verified software components. To substantiate this claim, we describe here a representative series of modules that implement imperative finite maps, including support for a higher-order (effectful) iterator. The implementations range from simple (e.g., association lists) to complex (e.g., hash tables) but share a common interface which, abstracts the implementation details and ensures that the modules properly implement the finite map abstraction. Copyright 2008 ACM.},
95+author = {{Nanevski A A Morrisett}, G B Shinnar A B Govereau P B Birkedal L C},
96+booktitle = {International Conference on Functional Programming},
97+doi = {10.1145/1411204.1411237},
98+file = {:Users/edwin/Documents/Mendeley Desktop/Nanevski A A Morrisett/Ynot Dependent types for imperative programs/Nanevski A A Morrisett - Ynot Dependent types for imperative programs - 2008.pdf:pdf},
99+isbn = {9781595939197},
100+issn = {15232867},
101+keywords = {Dependent Types},
102+mendeley-tags = {Dependent Types},
103+number = {9},
104+pages = {229--240},
105+title = {{Ynot: Dependent types for imperative programs}},
106+url = {http://www.scopus.com/inward/record.url?eid=2-s2.0-67650032847&partnerID=40&md5=7a5be3083878399cebafda33b1affa6b},
107+volume = {43},
118108year = {2008}
119109}
110+@article{Walt,
111+annote = {-1, 5
112+
113+
114+This paper describes the use of Agda's reflection mechanism to help with proof automation, and gives some simple examples, including proving evenness of natural numbers and proving that a boolean formula is a tautology.
115+
116+
117+It seems that proof automation is important for a practical language with dependent types, and Agda's reflection mechanism as described is likely to help. However, this paper only really scratches the surface of what is possible - existing (unpublished, as far as I'm aware) examples such as the Ring solver go much further towards demonstrating its value.
118+
119+
120+The 'Evenness' example uses a lot of space for something pretty simple. An in practice, the number won't necessarily be known. What if you know "Even x" and need to prove "Even (x + 100)". Does it still work? Similarly for the tautology example - what if there is an unknown formula which is nevertheless known to be a tautology? It would be nice, therefore, to show how such proof obligations come up in practice and how the reflection techniques described help. Without this, it's not clear that the paper answers the given central question of whether Agda's reflective capabilities are sufficient and practically usable.
121+
122+
123+In summary: there's some nice tutorial material here describing reflection and its application, but I don't think there is enough depth for it to be really interesting.
124+
125+
126+Minor comments
127+
128+
129+The fonts and layout look wrong. Is this the proper LaTeX class? Also remember that the colour won't come out in print...
130+
131+
132+p2 "new" keywords seems wrong for a technique was has been aroundfor a couple of years. I know it hasn't been written up elsewhere, but I'd omit the word "new"
133+
134+
135+p3 "This is why we have decidable equality" - can you explain what you mean by this, for the non-Agda expert?
136+
137+
138+Vars are naturals - so they are de Bruijn indexed?
139+
140+
141+p5 "Other terms are rejected" - what does it mean for a term to be rejected? i.e. what is the effect? The text hints that this is a type error, since there is a suggestion that a proof is needed to show it is valid, but it would be good to be explicit.
142+
143+
144+p8 I'm not sure I'd go as far as to say it's "trivial" to show that (1) is a tautology, but I agree it should be easy, if tedious.},
145+author = {Walt, Paul Van Der and Swierstra, Wouter},
146+file = {:Users/edwin/Documents/Mendeley Desktop/Walt, Swierstra/Engineering Proof by Reflection in Agda/Walt, Swierstra - Engineering Proof by Reflection in Agda - Unknown.pdf:pdf},
147+title = {{Engineering Proof by Reflection in Agda}}
148+}
120149@inproceedings{madhavapeddy2007melange,
121150author = {Madhavapeddy, A. and Ho, A. and Deegan, T. and Scott, D. and Sohan, R.},
122151booktitle = {ACM SIGOPS Operating Systems Review},
123−file = {:Users/edwin/Documents/Mendeley Desktop/Madhavapeddy et al/ACM SIGOPS Operating Systems Review/Madhavapeddy et al. - 2007 - Melange creating a functional internet.pdf:pdf},
152+file = {:Users/edwin/Documents/Mendeley Desktop/Madhavapeddy et al/Melange creating a functional internet/Madhavapeddy et al. - Melange creating a functional internet - 2007.pdf:pdf},
124153number = {3},
125154pages = {101--114},
126155publisher = {ACM},
@@ -129,243 +158,228 @@ url = {http://dl.acm.org/citation.cfm?id=1273009},
129158volume = {41},
130159year = {2007}
131160}
132−@inproceedings{lempsink2009type,
133−author = {Lempsink, E. and Leather, S. and L\"{o}h, A.},
134−booktitle = {Proceedings of the 2009 ACM SIGPLAN workshop on Generic programming},
135−file = {:Users/edwin/Documents/Mendeley Desktop/Lempsink, Leather, L\"{o}h/Proceedings of the 2009 ACM SIGPLAN workshop on Generic programming/Lempsink, Leather, L\"{o}h - 2009 - Type-safe diff for families of datatypes.pdf:pdf},
136−pages = {61--72},
137−publisher = {ACM},
138−title = {{Type-safe diff for families of datatypes}},
139−url = {http://dl.acm.org/citation.cfm?id=1596624},
140−year = {2009}
161+@inproceedings{czarnecki2004dsl,
162+author = {Czarnecki, K. and O’Donnell, J. and Striegnitz, J. and Taha, W.},
163+booktitle = {Domain-Specific Program Generation},
164+file = {:Users/edwin/Documents/Mendeley Desktop/Czarnecki et al/DSL implementation in MetaOCaml, Template Haskell, and C/Czarnecki et al. - DSL implementation in MetaOCaml, Template Haskell, and C - 2004.pdf:pdf},
165+pages = {51--72},
166+publisher = {Springer},
167+title = {{DSL implementation in MetaOCaml, Template Haskell, and C++}},
168+url = {http://www.springerlink.com/index/NL620EL7N94M161H.pdf},
169+year = {2004}
141170}
142−@book{Approach2012,
143−author = {Hunt, Andrew and Thomas, David},
144−booktitle = {Carcinogenesis},
145−doi = {10.1093/carcin/bgs054},
146−file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/Carcinogenesis/Hunt, Thomas - Unknown - The Pragmatic Programmer Chapter 2.pdf:pdf},
147−isbn = {020161622X},
148−issn = {1460-2180},
149−number = {3},
150−pmid = {22383472},
151−title = {{The Pragmatic Programmer Chapter 2}},
152−url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
153−volume = {33}
171+@article{Wadler2001,
172+abstract = {The use of monads to structure functional programs is described. Monads provide a convenient framework for simulating effects found in other languages, such as global state, exception handling, output, or non-determinism. Three case studies are looked at in detail: how monads ease the modification of a simple evaluator; how monads act as the basis of a datatype of arrays subject to in-place update; and how monads can be used to build parsers.},
173+author = {Wadler, Philip},
174+doi = {10.1007/3-540-59451-5_2},
175+editor = {Jeuring, Johan and Meijer, Erik},
176+file = {:Users/edwin/Documents/Mendeley Desktop/Wadler/Monads for functional programming/Wadler - Monads for functional programming - 2001.pdf:pdf},
177+isbn = {3540594515},
178+issn = {03029743},
179+journal = {Advanced Functional Programming},
180+number = {August 1992},
181+pages = {24--52},
182+publisher = {Springer},
183+series = {Lecture Notes in Computer Science},
184+title = {{Monads for functional programming}},
185+url = {http://www.springerlink.com/index/715264614rh13340.pdf},
186+volume = {925},
187+year = {2001}
154188}
155−@inproceedings{stump2010resource,
156−author = {Stump, A. and Austin, E.},
157−booktitle = {Proceedings of the 4th ACM SIGPLAN workshop on Programming languages meets program verification},
158−file = {:Users/edwin/Documents/Mendeley Desktop/Stump, Austin/Proceedings of the 4th ACM SIGPLAN workshop on Programming languages meets program verification/Stump, Austin - 2010 - Resource typing in Guru.pdf:pdf},
159−pages = {27--38},
160−publisher = {ACM},
161−title = {{Resource typing in Guru}},
162−url = {http://dl.acm.org/citation.cfm?id=1707796},
163−year = {2010}
189+@phdthesis{Boquist1999,
190+author = {Boquist, Urban},
191+file = {:Users/edwin/Documents/Mendeley Desktop/Boquist/Code optimisation techniques for lazy functional languages/Boquist - Code optimisation techniques for lazy functional languages - 1999.pdf:pdf},
192+title = {{Code optimisation techniques for lazy functional languages}},
193+url = {http://mirror.seize.it/papers/Code Optimization Techniques for Lazy Functional Languages.pdf},
194+year = {1999}
195+}
196+@inproceedings{Taha2003,
197+author = {Taha, Walid and Nielsson, Michael Florentin},
198+booktitle = {Principles of Programming Languages},
199+file = {:Users/edwin/Documents/Mendeley Desktop/Taha, Nielsson/Environment Classifiers/Taha, Nielsson - Environment Classifiers - 2003.pdf:pdf},
200+isbn = {1581136285},
201+keywords = {linear,modal logic,multi-stage programming,temporal logic,type safety,type systems},
202+title = {{Environment Classifiers}},
203+year = {2003}
204+}
205+@article{Brady2012a,
206+author = {{Peyton Jones}, S.L.},
207+doi = {10.1093/geront/gns026},
208+file = {:Users/edwin/Documents/Mendeley Desktop/Peyton Jones/Beautiful Code Chapter 24/Peyton Jones - Beautiful Code Chapter 24 - 2012.pdf:pdf},
209+isbn = {9780596510046},
210+issn = {1758-5341},
211+journal = {The Gerontologist},
212+month = dec,
213+number = {6},
214+pages = {NP},
215+pmid = {23150082},
216+title = {{Beautiful Code Chapter 24}},
217+url = {http://www.ncbi.nlm.nih.gov/pubmed/23150082},
218+volume = {52},
219+year = {2012}
164220}
165221@article{mcbride2010ornamental,
166222author = {McBride, Conor},
167−file = {:Users/edwin/Documents/Mendeley Desktop/McBride/Journal of Functional Programming/McBride - 2010 - Ornamental algebras, algebraic ornaments.pdf:pdf},
223+file = {:Users/edwin/Documents/Mendeley Desktop/McBride/Ornamental algebras, algebraic ornaments/McBride - Ornamental algebras, algebraic ornaments - 2010.pdf:pdf},
168224journal = {Journal of Functional Programming},
169225title = {{Ornamental algebras, algebraic ornaments}},
170226url = {http://personal.cis.strath.ac.uk/$\sim$conor/pub/OAAO/Ornament.pdf},
171227year = {2010}
172228}
173−@article{Swierstra2011,
174−author = {Swierstra, W},
175−file = {:Users/edwin/Documents/Mendeley Desktop/Swierstra/Journal of Functional Programming/Swierstra - 2011 - Sorted Verifying the Problem of the {Dutch National} Flag in {Agda}.pdf:pdf},
176−journal = {Journal of Functional Programming},
177−number = {6},
178−pages = {575----583},
179−title = {{Sorted: Verifying the Problem of the {Dutch National} Flag in {Agda}}},
180−url = {http://journals.cambridge.org/abstract_S0956796811000207},
181−volume = {21},
182−year = {2011}
229+@inproceedings{Gall2012,
230+author = {Gall, Yann Le and Lee, Adam J and Kapdia, Apu},
231+booktitle = {SCMAT},
232+file = {:Users/edwin/Documents/Mendeley Desktop/Gall, Lee, Kapdia/PlexC A Policy Language for Exposure Control/Gall, Lee, Kapdia - PlexC A Policy Language for Exposure Control - 2012.pdf:pdf},
233+isbn = {9781450312950},
234+keywords = {exposure,policy languages,privacy},
235+pages = {219--228},
236+title = {{PlexC : A Policy Language for Exposure Control}},
237+year = {2012}
183238}
184−@article{McBride2002,
185−author = {McBride, C},
186−file = {:Users/edwin/Documents/Mendeley Desktop/McBride/Types for proofs and programs ({TYPES 2000})/McBride - 2000 - Elimination with a Motive.pdf:pdf},
187−journal = {Types for proofs and programs ({TYPES 2000})},
188−title = {{Elimination with a Motive}},
189−url = {http://www.springerlink.com/index/vbpg19305t46f6dm.pdf},
190−year = {2000}
239+@article{Campbell-moore,
240+author = {Campbell-moore, Catrin},
241+file = {:Users/edwin/Documents/Mendeley Desktop/Campbell-moore/A Computable Infinitary Logic/Campbell-moore - A Computable Infinitary Logic - Unknown.pdf:pdf},
242+pages = {1--10},
243+title = {{A Computable Infinitary Logic}}
191244}
192−@article{Xi1998,
193−abstract = {We present a type-based approach to eliminating array bound checking and list tag checking by conservatively extending Standard ML with a restricted form of dependent types. This enables the programmer to capture more invariants through types while type-checking remains decidable in theory and can still be performed efficiently in practice. We illustrate our approach through concrete examples and present the result of our preliminary experiments which support support the feasibility and effectiveness of our approach.},
194−author = {Xi, Hongwei and Pfenning, Frank},
195−doi = {10.1145/277652.277732},
196−file = {:Users/edwin/Documents/Mendeley Desktop/Xi, Pfenning/ACM Sigplan Notices/Xi, Pfenning - 1998 - Eliminating array bound checking through dependent types.pdf:pdf},
197−isbn = {0897919874},
198−issn = {03621340},
199−journal = {ACM Sigplan Notices},
200−keywords = {Dependent Types},
201−mendeley-tags = {Dependent Types},
202−number = {5},
203−pages = {249--257},
204−publisher = {ACM},
205−series = {PLDI '98},
206−title = {{Eliminating array bound checking through dependent types}},
207−url = {http://portal.acm.org/citation.cfm?doid=277652.277732},
208−volume = {33},
209−year = {1998}
210−}
211−@misc{idristutorial,
212−author = {Brady, Edwin},
213−file = {:Users/edwin/Documents/Mendeley Desktop/Brady/Unknown/Brady - 2012 - Programming in Idris a tutorial.pdf:pdf},
214−title = {{Programming in Idris : a tutorial}},
215−url = {http://idris-lang.org/tutorial},
216−year = {2012}
217−}
218−@book{Cryptography2012,
219−author = {Anderson, Ross},
220−doi = {10.1093/intimm/dxs023},
221−file = {:Users/edwin/Documents/Mendeley Desktop/Anderson/Unknown/Anderson - Unknown - Security Engineering Chapter 5.pdf:pdf},
222−isbn = {9780470068526},
223−issn = {1460-2377},
224−number = {4},
225−pmid = {22451589},
226−title = {{Security Engineering Chapter 5}},
227−url = {http://www.ncbi.nlm.nih.gov/pubmed/22451589},
228−volume = {24}
229−}
230−@inproceedings{NanevskiAAMorrisett2008,
231−abstract = {We describe an axiomatic extension to the Coq proof assistant, that supports writing, reasoning about, and extracting higher-order, dependently-typed programs with side-effects. Coq already includes a powerful functional language that supports dependent types, but that language is limited to pure, total functions. The key contribution of our extension, which we call Ynot, is the added support for computations that may have effects such as non-termination, accessing a mutable store, and throwing/catching exceptions. The axioms of Ynot form a small trusted computing base which has been formally justified in our previous work on Hoare Type Theory (HTT). We show how these axioms can be combined with the powerful type and abstraction mechanisms of Coq to build higher-level reasoning mechanisms which in turn can be used to build realistic, verified software components. To substantiate this claim, we describe here a representative series of modules that implement imperative finite maps, including support for a higher-order (effectful) iterator. The implementations range from simple (e.g., association lists) to complex (e.g., hash tables) but share a common interface which, abstracts the implementation details and ensures that the modules properly implement the finite map abstraction. Copyright 2008 ACM.},
232−author = {{Nanevski A A Morrisett}, G B Shinnar A B Govereau P B Birkedal L C},
233−booktitle = {International Conference on Functional Programming},
234−doi = {10.1145/1411204.1411237},
235−file = {:Users/edwin/Documents/Mendeley Desktop/Nanevski A A Morrisett/International Conference on Functional Programming/Nanevski A A Morrisett - 2008 - Ynot Dependent types for imperative programs.pdf:pdf},
236−isbn = {9781595939197},
237−issn = {15232867},
238−keywords = {Dependent Types},
239−mendeley-tags = {Dependent Types},
240−number = {9},
241−pages = {229--240},
242−title = {{Ynot: Dependent types for imperative programs}},
243−url = {http://www.scopus.com/inward/record.url?eid=2-s2.0-67650032847&partnerID=40&md5=7a5be3083878399cebafda33b1affa6b},
244−volume = {43},
245−year = {2008}
246−}
247−@misc{Brady2012c,
248−author = {Brooks, Fred},
245+@misc{Resolution2012a,
246+author = {Fall, Kevin R and Stevens, W. Richard},
249247doi = {10.1093/epirev/mxr031},
250−file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/Unknown/Brooks - Unknown - The Design of Design Chapter 5.pdf:pdf},
251−isbn = {9780321702081},
248+file = {:Users/edwin/Documents/Mendeley Desktop/Fall, Stevens/TCPIP Illustrated Volume 1 Chapter 11/Fall, Stevens - TCPIP Illustrated Volume 1 Chapter 11 - Unknown.pdf:pdf},
252249issn = {1478-6729},
253−number = {1},
254−pages = {NP},
255250pmid = {22215642},
256−title = {{The Design of Design Chapter 5}},
257−volume = {34}
251+title = {{TCP/IP Illustrated Volume 1 Chapter 11}}
258252}
259−@inproceedings{ko2011modularising,
260−author = {Ko, H.S. and Gibbons, J.},
261−booktitle = {Proceedings of the seventh ACM SIGPLAN workshop on Generic programming},
262−file = {:Users/edwin/Documents/Mendeley Desktop/Ko, Gibbons/Proceedings of the seventh ACM SIGPLAN workshop on Generic programming/Ko, Gibbons - 2011 - Modularising inductive families.pdf:pdf},
263−pages = {13--24},
264−publisher = {ACM},
265−title = {{Modularising inductive families}},
266−url = {http://www.cs.ox.ac.uk/publications/publication5008-abstract.html http://dl.acm.org/citation.cfm?id=2036921},
267−year = {2011}
253+@inproceedings{Pasalic2002,
254+author = {Pa\v{s}alic, Emir and Taha, Walid and Sheard, Tim},
255+booktitle = {International Conference on Functional Programming},
256+doi = {10.1145/583852.581499},
257+file = {:Users/edwin/Documents/Mendeley Desktop/Pa\v{s}alic, Taha, Sheard/Tagless staged interpreters for typed languages/Pa\v{s}alic, Taha, Sheard - Tagless staged interpreters for typed languages - 2002.pdf:pdf},
258+isbn = {1-58113-487-8},
259+issn = {03621340},
260+keywords = {calculus of constructions,definitional interpreters,domain-specific languages,multi-stage programming},
261+month = sep,
262+number = {9},
263+pages = {218--229},
264+title = {{Tagless staged interpreters for typed languages}},
265+url = {http://dl.acm.org/citation.cfm?id=583852.581499},
266+volume = {37},
267+year = {2002}
268268}
269−@book{Choosing2012,
270−author = {Fowler, Martin},
271−booktitle = {Carcinogenesis},
272−doi = {10.1093/carcin/bgs054},
273−file = {:Users/edwin/Documents/Mendeley Desktop/Fowler/Carcinogenesis/Fowler - Unknown - Domain Specific Languages Chapter 6.pdf:pdf},
274−isbn = {9780132107549},
275−issn = {1460-2180},
276−number = {3},
277−pmid = {22383472},
278−title = {{Domain Specific Languages Chapter 6}},
279−url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
280−volume = {33}
269+@book{Projects,
270+author = {Hunt, Andrew and Thomas, David},
271+file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/The Pragmatic Programmer Chapter 8/Hunt, Thomas - The Pragmatic Programmer Chapter 8 - Unknown.pdf:pdf},
272+isbn = {020161622X},
273+title = {{The Pragmatic Programmer Chapter 8}}
281274}
282−@article{marlow2006making,
283−author = {Marlow, S. and {Peyton Jones}, S.},
284−file = {:Users/edwin/Documents/Mendeley Desktop/Marlow, Peyton Jones/Journal of Functional Programming/Marlow, Peyton Jones - 2006 - Making a fast curry pushenter vs. evalapply for higher-order languages.pdf:pdf},
285−journal = {Journal of Functional Programming},
286−number = {4-5},
287−pages = {415--449},
288−publisher = {Cambridge University Press},
289−title = {{Making a fast curry: push/enter vs. eval/apply for higher-order languages}},
290−url = {http://dl.acm.org/citation.cfm?id=1166018},
291−volume = {16},
292−year = {2006}
275+@inproceedings{Wadler1989,
276+abstract = {From the type of a polymorphic function we can derive a theorem that it satisfies. Every function of the same type satisfies the same theorem. This provides a free source of useful theorems, courtesy of Reynolds' abstraction theorem for the polymorphic lambda calculus.},
277+author = {Wadler, Philip},
278+booktitle = {Proceedings of the fourth international conference on Functional programming languages and computer architecture},
279+doi = {10.1145/99370.99404},
280+file = {:Users/edwin/Documents/Mendeley Desktop/Wadler/Theorems for free!/Wadler - Theorems for free! - 1989.pdf:pdf},
281+isbn = {0897913280},
282+number = {June},
283+pages = {347--359},
284+publisher = {ACM},
285+series = {FPCA '89},
286+title = {{Theorems for free!}},
287+url = {http://portal.acm.org/citation.cfm?id=99404},
288+year = {1989}
293289}
294−@article{Mandelbaum2007,
295−abstract = {Massive amounts of useful data are stored and processed in ad hoc formats for which common tools like parsers, printers, query engines and format converters are not readily available. In this paper, we explain the design and implementation of PADS/ML , a new language and system that facilitates the generation of data processing tools for ad hoc formats. The PADS/ML design includes features such as dependent, polymorphic and recursive datatypes, which allow programmers to describe the syntax and semantics of ad hoc data in a concise, easy-to-read notation. The PADS/ML implementation compiles these descriptions into ml structures and functors that include types for parsed data, functions for parsing and printing, and auxiliary support for user-specified, format-dependent and format-independent tool generation.},
296−author = {Mandelbaum, Yitzhak and Fisher, Kathleen and Walker, David and Fernandez, Mary and Gleyzer, Artem},
297−doi = {10.1145/1190215.1190231},
298−isbn = {1595935754},
299−issn = {03621340},
300−journal = {SIGPLAN Not},
301−number = {1},
302−pages = {77--83},
290+@inproceedings{swierstra2007beauty,
291+author = {Swierstra, W. and Altenkirch, T.},
292+booktitle = {Proceedings of the ACM SIGPLAN workshop on Haskell workshop},
293+file = {:Users/edwin/Documents/Mendeley Desktop/Swierstra, Altenkirch/Beauty in the beast/Swierstra, Altenkirch - Beauty in the beast - 2007.pdf:pdf},
294+pages = {25--36},
303295publisher = {ACM},
304−series = {POPL '07},
305−title = {{PADS/ML: a functional data description language}},
306−url = {http://doi.acm.org/10.1145/1190216.1190231},
307−volume = {42},
296+title = {{Beauty in the beast}},
297+url = {http://dl.acm.org/citation.cfm?id=1291206},
308298year = {2007}
309299}
310−@article{Abel2010,
311−abstract = {Sized types are a modular and theoretically well-understood tool for checking termination of recursive and productivity of corecursive definitions. The essential idea is to track structural descent and guardedness in the type system to make termination checking robust and suitable for strong abstractions like higher-order functions and polymorphism. To study the application of sized types to proof assistants and programming languages based on dependent type theory, we have implemented a core language, MiniAgda, with explicit handling of sizes. New considerations were necessary to soundly integrate sized types with dependencies and pattern matching, which was made possible by concepts such as inaccessible patterns and parametric function spaces. This paper provides an introduction to MiniAgda by example and informal explanations of the underlying principles.},
312−author = {Abel, Andreas},
313−file = {:Users/edwin/Documents/Mendeley Desktop/Abel/EPTCS/Abel - 2010 - MiniAgda Integrating Sized and Dependent Types.pdf:pdf},
314−journal = {EPTCS},
315−pages = {1--15},
316−title = {{MiniAgda: Integrating Sized and Dependent Types}},
317−url = {http://arxiv.org/abs/1012.4896},
318−volume = {43},
319−year = {2010}
300+@inproceedings{Xi1999,
301+abstract = {Note: OCR errors may be found in this Reference List extracted from the full text article. ACM has opted to expose the complete List rather than only correct and linked references.},
302+author = {Xi, Hongwei and Pfenning, Frank},
303+booktitle = {Proceedings of the 26th ACM SIGPLANSIGACT symposium on Principles of programming languages POPL 99},
304+doi = {10.1145/292540.292560},
305+file = {:Users/edwin/Documents/Mendeley Desktop/Xi, Pfenning/Dependent types in practical programming/Xi, Pfenning - Dependent types in practical programming - 1999.pdf:pdf},
306+isbn = {1581130953},
307+issn = {07439016},
308+keywords = {Dependent Types},
309+mendeley-tags = {Dependent Types},
310+organization = {Carnegie Mellon University},
311+pages = {214--227},
312+publisher = {ACM Press},
313+series = {POPL '99},
314+title = {{Dependent types in practical programming}},
315+url = {http://portal.acm.org/citation.cfm?doid=292540.292560},
316+volume = {26},
317+year = {1999}
320318}
321−@article{Hoare1978,
322−abstract = {This paper suggests that input and output are basic primitives of programming and that parallel composition of communicating sequential processes is a fundamental program structuring method. When combined with a development of Dijkstra's guarded command, these concepts are surprisingly versatile. Their use is illustrated by sample solutions of a variety of a familiar programming exercises.},
323−author = {Hoare, C A R},
324−doi = {10.1016/0167-6423(87)90028-1},
325−editor = {McKeag, R M and Macnaghten, A M},
326−file = {:Users/edwin/Documents/Mendeley Desktop/Hoare/Communications of the ACM/Hoare - 1978 - Communicating sequential processes.pdf:pdf},
327−isbn = {0131532715},
328−issn = {01676423},
329−journal = {Communications of the ACM},
330−number = {8},
331−pages = {666--677},
332−pmid = {2142694823583477576},
319+@inproceedings{Kimmell2012,
320+author = {Kimmell, G and Stump, A and {Eades III}, HD and Fu, Peng and Sheard, Tim and Weirich, S and Casinghino, C and Sj\"{o}berg, V and Collins, N and Ahn, KY},
321+booktitle = {Programming Languages meets Program Verification},
322+file = {:Users/edwin/Documents/Mendeley Desktop/Kimmell et al/Equational reasoning about programs with general recursion and call-by-value semantics/Kimmell et al. - Equational reasoning about programs with general recursion and call-by-value semantics - 2012.pdf:pdf},
323+title = {{Equational reasoning about programs with general recursion and call-by-value semantics}},
324+url = {http://dl.acm.org/citation.cfm?id=2103780},
325+year = {2012}
326+}
327+@article{mccann2000packet,
328+author = {McCann, P.J. and Chandra, S.},
329+journal = {ACM SIGCOMM Computer Communication Review},
330+number = {4},
331+pages = {321--333},
333332publisher = {ACM},
334−series = {International Series in Computer Science},
335−title = {{Communicating sequential processes}},
336−url = {http://linkinghub.elsevier.com/retrieve/pii/0167642387900281},
337−volume = {21},
338−year = {1978}
333+title = {{Packet types: abstract specification of network protocol messages}},
334+url = {http://dl.acm.org/citation.cfm?id=347563},
335+volume = {30},
336+year = {2000}
339337}
340−@book{Bird2010,
341−author = {Bird, Richard},
342−file = {:Users/edwin/Documents/Mendeley Desktop/Bird/Unknown/Bird - 2010 - Pearls of Functional Algorithm Design.pdf:pdf},
343−isbn = {9780521513388},
344−title = {{Pearls of Functional Algorithm Design}},
345−year = {2010}
338+@article{McBride2007,
339+author = {McBride, Conor and Paterson, Ross},
340+file = {:Users/edwin/Documents/Mendeley Desktop/McBride, Paterson/Applicative programming with effects/McBride, Paterson - Applicative programming with effects - 2007.pdf:pdf},
341+journal = {Journal of functional programming},
342+title = {{Applicative programming with effects}},
343+url = {http://journals.cambridge.org/abstract_S0956796807006326},
344+year = {2007}
346345}
347−@inproceedings{oury2008power,
348−author = {Oury, N. and Swierstra, W.},
349−booktitle = {International Conference on Functional Programming},
350−file = {:Users/edwin/Documents/Mendeley Desktop/Oury, Swierstra/International Conference on Functional Programming/Oury, Swierstra - 2008 - The power of Pi.pdf:pdf},
351−keywords = {Dependent Types},
352−mendeley-tags = {Dependent Types},
353−number = {9},
354−pages = {39--50},
355−publisher = {ACM},
356−title = {{The power of Pi}},
357−url = {http://dl.acm.org/citation.cfm?id=1411213},
358−volume = {43},
359−year = {2008}
346+@misc{Ferreira2012,
347+annote = {This paper explains how to compile Beluga, a programming language with higher order abstract syntax which is specifically designed to support data structures with binders. In particular, it aims to make it easy to reason about metatheory of programming languages by supporting name generation, alpha conversion and capture avoiding substitution.
348+
349+
350+In general, I liked this paper, primarily because it tackles an underrepresented problem - namely, taking a high level language with support for theorem proving and dependent types, and generating efficient executable code. This is clearly important if such high level languages are to be useful in practice, and even to demonstrate the usefulness and power of the language on anything other than small scale examples.
351+
352+
353+I think this paper can be accepted, though I have some small comments and suggestions for improvements:
354+
355+
356+The introductory example in section 2 provides a generally clear introduction to contextual objects, motivating the problem with a well-understood example. However, it would be nice to say more here about what the target of the compilation is (otherwise I'm not sure what you mean by using "simple names" here). You say: "The output is a fully annotated program using a representation close to the one presented by Cave and Pientka" - as well as the reference it would be very useful here to summarise what that representation is. There are a couple of instances of this, where some background is assumed, which would be good to explain in a couple of sentences in the early sections - e.g. it would also be useful to say what you mean by "Fresh-Style" earlier on.
357+
358+
359+Section 4 - maybe give the informal description of fresh binders earlier?
360+
361+
362+p6-7 On dependency erasure - "The compiler keeps the simple types as a way of sanity check" - is this always true? It isn't true in general for dependent types (consider, for example, a function which computes a simple type) and certainly not with more aggressive dependency erasure such as forcing of constructor arguments which is implemented in Agda and Idris, for example.
363+
364+
365+p9 It seems that the type system is strong enough to support some optimisations on pattern match compilation - such as Epigram's detagging, where the result of a case split on one value informs what another value should be.
366+
367+
368+In related work, you don't mention any other compilers for dependently typed languages which have to tackle similar problems, though you do mention program extraction for Coq. There is also MAlonzo, which translates Agda to Haskell, and Epic (Trends in Functional Programming), used by Epigram, Agda and Idris, which deals with naming though in a much more limited way than this paper.},
369+author = {Ferreira, Francisco and Monnier, Stefan and Pientka, Brigitte},
370+file = {:Users/edwin/Documents/Mendeley Desktop/Ferreira, Monnier, Pientka/Compiling Contextual Objects Bringing Higher-Order Abstract Syntax to Programmers/Ferreira, Monnier, Pientka - Compiling Contextual Objects Bringing Higher-Order Abstract Syntax to Programmers - 2012.pdf:pdf},
371+keywords = {compilation,contextual objects,pattern matching},
372+title = {{Compiling Contextual Objects Bringing Higher-Order Abstract Syntax to Programmers}},
373+year = {2012}
360374}
361−@inproceedings{madhavapeddy2010turning,
362−author = {Madhavapeddy, A. and Mortier, R. and Sohan, R. and Gazagnaire, T. and Hand, S. and Deegan, T. and McAuley, D. and Crowcroft, J.},
363−booktitle = {Proceedings of the 2nd USENIX conference on Hot topics in cloud computing},
364−file = {:Users/edwin/Documents/Mendeley Desktop/Madhavapeddy et al/Proceedings of the 2nd USENIX conference on Hot topics in cloud computing/Madhavapeddy et al. - 2010 - Turning down the LAMP software specialisation for the cloud.pdf:pdf},
365−publisher = {USENIX Association},
366−title = {{Turning down the LAMP: software specialisation for the cloud}},
367−url = {http://dl.acm.org/citation.cfm?id=1863114},
368−year = {2010}
375+@misc{The2012b,
376+author = {Brooks, Fred},
377+doi = {10.1093/epirev/mxr031},
378+file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/The Design of Design Chapter 1/Brooks - The Design of Design Chapter 1 - Unknown.pdf:pdf},
379+isbn = {9780321702081},
380+issn = {1478-6729},
381+pmid = {22215642},
382+title = {{The Design of Design Chapter 1}}
369383}
370384@book{peyton1987implementation,
371385author = {{Peyton Jones}, S.L.},
@@ -374,390 +388,572 @@ title = {{The implementation of functional programming languages (prentice-hall
374388url = {http://dl.acm.org/citation.cfm?id=1096899},
375389year = {1987}
376390}
377−@inproceedings{Pasalic2002,
378−author = {Pa\v{s}alic, Emir and Taha, Walid and Sheard, Tim},
391+@article{Miller1992,
392+author = {Miller, Dale},
393+file = {:Users/edwin/Documents/Mendeley Desktop/Miller/Unification under a mixed prefix/Miller - Unification under a mixed prefix - 1992.pdf:pdf},
394+journal = {Journal of Symbolic Computation},
395+title = {{Unification under a mixed prefix}},
396+url = {http://www.sciencedirect.com/science/article/pii/074771719290011R},
397+year = {1992}
398+}
399+@inproceedings{Danielsson2010,
400+author = {Danielsson, Nils Anders},
379401booktitle = {International Conference on Functional Programming},
380−doi = {10.1145/583852.581499},
381−file = {:Users/edwin/Documents/Mendeley Desktop/Pa\v{s}alic, Taha, Sheard/International Conference on Functional Programming/Pa\v{s}alic, Taha, Sheard - 2002 - Tagless staged interpreters for typed languages.pdf:pdf},
382−isbn = {1-58113-487-8},
402+doi = {10.1145/1932681.1863585},
403+file = {:Users/edwin/Documents/Mendeley Desktop/Danielsson/Total parser combinators/Danielsson - Total parser combinators - 2010.pdf:pdf},
404+isbn = {978-1-60558-794-3},
383405issn = {03621340},
384−keywords = {calculus of constructions,definitional interpreters,domain-specific languages,multi-stage programming},
406+keywords = {dependent types,mixed induction and coinduction,parser combinators,productivity,termination},
385407month = sep,
386408number = {9},
387−pages = {218--229},
388−title = {{Tagless staged interpreters for typed languages}},
389−url = {http://dl.acm.org/citation.cfm?id=583852.581499},
390−volume = {37},
391−year = {2002}
409+pages = {285},
410+title = {{Total parser combinators}},
411+url = {http://dl.acm.org/citation.cfm?id=1932681.1863585},
412+volume = {45},
413+year = {2010}
392414}
393−@inproceedings{Brady2010,
394−author = {Brady, Edwin and Hammond, Kevin},
395−booktitle = {Proceedings of the 15th ACM SIGPLAN international conference on Functional programming},
396−file = {:Users/edwin/Documents/Mendeley Desktop/Brady, Hammond/Proceedings of the 15th ACM SIGPLAN international conference on Functional programming/Brady, Hammond - 2010 - Scrapping your inefficient engine using partial evaluation to improve domain-specific language implementation.pdf:pdf},
397−isbn = {9781605587943},
398−keywords = {Dependent Types,code generation gives,contrast,dependent types,efficient,harder,however,implementation,likely efficient,ness interpreter,partial evaluation,resulting implementation,un,verify its correctness},
399−mendeley-tags = {Dependent Types},
400−pages = {297--308},
401−publisher = {ACM},
402−title = {{Scrapping your inefficient engine: using partial evaluation to improve domain-specific language implementation}},
403−url = {http://portal.acm.org/citation.cfm?id=1863587},
404−year = {2010}
415+@inproceedings{augustsson1999exercise,
416+author = {Augustsson, L. and Carlsson, M.},
417+booktitle = {In Workshop on Dependent Types in Programming, Gothenburg},
418+keywords = {Depe},
419+mendeley-tags = {Depe},
420+publisher = {Citeseer},
421+title = {{An exercise in dependent types: A well-typed interpreter}},
422+url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.39.2895},
423+year = {1999}
424+}
425+@inproceedings{Sheard2005,
426+address = {New York, New York, USA},
427+author = {Sheard, Tim},
428+booktitle = {Proceedings of the 2005 ACM SIGPLAN workshop on Haskell - Haskell '05},
429+doi = {10.1145/1088348.1088356},
430+file = {:Users/edwin/Documents/Mendeley Desktop/Sheard/Putting curry-howard to work/Sheard - Putting curry-howard to work - 2005.pdf:pdf},
431+isbn = {159593071X},
432+keywords = {GADT,curry-howard isomorphism,extensional kind system,haskell,logic},
433+month = sep,
434+pages = {74--85},
435+publisher = {ACM Press},
436+title = {{Putting curry-howard to work}},
437+url = {http://dl.acm.org/citation.cfm?id=1088348.1088356},
438+year = {2005}
439+}
440+@phdthesis{McBride1999,
441+author = {McBride, Conor},
442+file = {:Users/edwin/Documents/Mendeley Desktop/McBride/Dependently typed functional programs and their proofs/McBride - Dependently typed functional programs and their proofs - 1999.pdf:pdf},
443+keywords = {Dependent Types},
444+mendeley-tags = {Dependent Types},
445+school = {University of Edinburgh},
446+title = {{Dependently typed functional programs and their proofs}},
447+url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.26.4785&rep=rep1&type=pdf},
448+year = {1999}
449+}
450+@article{The2012a,
451+author = {Bentley, Jon},
452+doi = {10.1093/geront/gns026},
453+file = {:Users/edwin/Documents/Mendeley Desktop/Bentley/Beautiful Code Chapter 3/Bentley - Beautiful Code Chapter 3 - 2012.pdf:pdf},
454+isbn = {9780596510046},
455+issn = {1758-5341},
456+month = dec,
457+number = {6},
458+pages = {NP},
459+pmid = {23150082},
460+title = {{Beautiful Code Chapter 3}},
461+url = {http://www.ncbi.nlm.nih.gov/pubmed/23150082},
462+volume = {52},
463+year = {2012}
405464}
406465@inproceedings{Fournet2011,
407466author = {Fournet, Cedric and Bhargavan, Karthikeyan and Gordon, Andrew D},
408467booktitle = {Foundations of security analysis and design {VI}},
409−file = {:Users/edwin/Documents/Mendeley Desktop/Fournet, Bhargavan, Gordon/Foundations of security analysis and design {VI}/Fournet, Bhargavan, Gordon - 2010 - Cryptographic verification by typing for a sample protocol implementation.pdf:pdf},
468+file = {:Users/edwin/Documents/Mendeley Desktop/Fournet, Bhargavan, Gordon/Cryptographic verification by typing for a sample protocol implementation/Fournet, Bhargavan, Gordon - Cryptographic verification by typing for a sample protocol implementation - 2010.pdf:pdf},
410469title = {{Cryptographic verification by typing for a sample protocol implementation}},
411470url = {http://www.springerlink.com/index/V168041M46658R73.pdf},
412471year = {2010}
413472}
414−@article{landin1966next,
415−author = {Landin, P.J.},
416−file = {:Users/edwin/Documents/Mendeley Desktop/Landin/Communications of the ACM/Landin - 1966 - The next 700 programming languages.pdf:pdf},
417−journal = {Communications of the ACM},
418−number = {3},
419−pages = {157--166},
420−publisher = {ACM},
421−title = {{The next 700 programming languages}},
422−url = {http://dl.acm.org/citation.cfm?id=365257 )},
423−volume = {9},
424−year = {1966}
425−}
426−@inproceedings{bhargavan2010modular,
427−author = {Bhargavan, K. and Fournet, C. and Gordon, A.D.},
428−booktitle = {ACM Sigplan Notices},
429−number = {1},
430−pages = {445--456},
473+@inproceedings{chlipala2010ur,
474+author = {Chlipala, Adam},
475+booktitle = {ACM SIGPLAN Notices},
476+file = {:Users/edwin/Documents/Mendeley Desktop/Chlipala/Ur statically-typed metaprogramming with type-level record computation/Chlipala - Ur statically-typed metaprogramming with type-level record computation - 2010.pdf:pdf},
477+number = {6},
478+pages = {122--133},
431479publisher = {ACM},
432−title = {{Modular verification of security protocol code by typing}},
433−url = {http://dl.acm.org/citation.cfm?id=1707801.1706350},
480+title = {{Ur: statically-typed metaprogramming with type-level record computation}},
481+url = {http://dl.acm.org/citation.cfm?id=1806612},
434482volume = {45},
435483year = {2010}
436484}
437−@article{Haskell2012a,
438−author = {Biancuzzi, F and Warden, S},
439−doi = {10.1093/epirev/mxr031},
440−file = {:Users/edwin/Documents/Mendeley Desktop/Biancuzzi, Warden/Unknown/Biancuzzi, Warden - Unknown - Masterminds of Programming Chapter 8.pdf:pdf},
441−isbn = {9780596801670},
442−issn = {1478-6729},
443−pmid = {22215642},
444−title = {{Masterminds of Programming Chapter 8}}
445−}
446−@book{Brady2012,
447−author = {Hunt, Andrew and Thomas, David},
448−booktitle = {Carcinogenesis},
449−doi = {10.1093/carcin/bgs054},
450−file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/Carcinogenesis/Hunt, Thomas - Unknown - The Pragmatic Programmer Chapter 5.pdf:pdf},
451−isbn = {020161622X},
452−issn = {1460-2180},
453−number = {3},
454−pmid = {22383472},
455−title = {{The Pragmatic Programmer Chapter 5}},
456−url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
457−volume = {33}
458−}
459−@article{McBride2007,
460−author = {McBride, Conor and Paterson, Ross},
461−file = {:Users/edwin/Documents/Mendeley Desktop/McBride, Paterson/Journal of functional programming/McBride, Paterson - 2007 - Applicative programming with effects.pdf:pdf},
462−journal = {Journal of functional programming},
463−title = {{Applicative programming with effects}},
464−url = {http://journals.cambridge.org/abstract_S0956796807006326},
465−year = {2007}
466−}
467−@inproceedings{Altenkirch2010,
468−abstract = {The recent success of languages like Agda and Coq demonstrates the potential of using dependent types for programming. These systems rely on many high-level features like datatype definitions, pattern matching and implicit arguments to facilitate the use of the languages. However, these features complicate the metatheoretical study and are a potential source of bugs. To address these issues we introduce $\Pi$$\Sigma$, a dependently typed core language. It is small enough for metatheoretical study and the type checker is small enough to be formally verified. In this language there is only one mechanism for recursionused for types, functions and infinite objectsand an explicit mechanism to control unfolding, based on lifted types. Furthermore structural equality is used consistently for values and types; this is achieved by a new notion of $\alpha$-equality for recursive definitions. We show, by translating several high-level constructions, that $\Pi$$\Sigma$ is suitable as a core language for dependently typed programming.},
469−author = {Altenkirch, Thorsten and Danielsson, Nils Anders and L\"{o}h, Andres and Oury, Nicolas},
470−booktitle = {{FLOPS 2010}},
471−doi = {10.1007/978-3-642-12251-4_5},
472−editor = {Blume, Matthias and Kobayashi, Naoki and Vidal, Germ\'{a}n},
473−file = {:Users/edwin/Documents/Mendeley Desktop/Altenkirch et al/{FLOPS 2010}/Altenkirch et al. - 2010 - Dependent Types without the Sugar.pdf:pdf},
474−isbn = {9783642122507},
475−pages = {40----55},
476−publisher = {Springer Berlin Heidelberg},
477−series = {Lecture Notes in Computer Science},
478−title = {{Dependent Types without the Sugar}},
479−url = {http://www.springerlink.com/index/91W712G2806R575H.pdf},
480−year = {2010}
481−}
482−@article{McBride2005,
483−author = {McBride, Conor},
484−editor = {Vene, Varmo and Uustalu, Tarmo},
485−isbn = {3540285407},
486−journal = {Advanced Functional Programming},
487−keywords = {Dependent Types},
488−mendeley-tags = {Dependent Types},
489−pages = {130--170},
490−publisher = {Springer},
491−series = {Lecture Notes in Computer Science},
492−title = {{Epigram: Practical programming with dependent types}},
493−url = {http://www.springerlink.com/index/96j7v5vn8tyebeky.pdf},
494−volume = {3622},
495−year = {2005}
485+@article{Fluet,
486+annote = {0,3
487+
488+
489+This paper gives a control flow analysis for polymorphic functional programs (specifically System F with recursion). Surprisingly (to me at least) this appears not to have been done before, with previous analyses targetting dynamically typed or simply typed languages, or handling polymorphism by explicitly eliminating it. It seems to be a worthwhile exercise: richer static type systems should give more information to support static analysis.
490+
491+
492+While I like what is achieved by this paper, I did find it rather hard going. The introduction feels laboured and then the paper covers a lot of detail (possibly too much) in quite a short space (though it still runs to 18 pages, two more than the limit!). I would suggest that the paper would be much improved, particularly to a non-expert reader, if it give one or more motivating examples in the introduction and showed how the analysis applied to these examples, when translated to ANF.
493+I think this would shorten the introduction and give a much better intuition for the rules.},
494+author = {Fluet, Matthew},
495+file = {:Users/edwin/Documents/Mendeley Desktop/Fluet/A Type- and Control-Flow Analysis for System F/Fluet - A Type- and Control-Flow Analysis for System F - Unknown.pdf:pdf},
496+pages = {1--18},
497+title = {{A Type- and Control-Flow Analysis for System F}}
496498}
497−@article{Huet1997,
498−author = {Huet, G},
499−file = {:Users/edwin/Documents/Mendeley Desktop/Huet/{Journal of Functional Programming}/Huet - 1997 - The zipper.pdf:pdf},
499+@article{Vytiniotis2011,
500+author = {Vytiniotis, Dimitrios and {Peyton Jones}, Simon and Schrijvers, Tom and Sulzmann, Martin},
501+file = {:Users/edwin/Documents/Mendeley Desktop/Vytiniotis et al/textsc{OutsideIn}(X) Modular type inference with local assumptions/Vytiniotis et al. - textsc{OutsideIn}(X) Modular type inference with local assumptions - 2011.pdf:pdf;:Users/edwin/Documents/Mendeley Desktop/Vytiniotis et al/textsc{OutsideIn}(X) Modular type inference with local assumptions/Vytiniotis et al. - textsc{OutsideIn}(X) Modular type inference with local assumptions - 2011(2).pdf:pdf},
500502journal = {{Journal of Functional Programming}},
501−number = {5},
502−pages = {549----554},
503−title = {{The zipper}},
504−url = {http://journals.cambridge.org/abstract_S0956796897002864},
505−volume = {7},
506−year = {1997}
503+number = {4--5},
504+pages = {333----412},
505+title = {{\textsc{OutsideIn}(X) Modular type inference with local assumptions}},
506+url = {http://journals.cambridge.org/abstract_S0956796811000098},
507+volume = {21},
508+year = {2011}
507509}
508510@inproceedings{Gregoire2005,
509511author = {Gregoire, Benjamin and Mahboubi, Assia},
510512booktitle = {{Theorem Proving in Higher Order Logics (TPHOLS 2005)}},
511−file = {:Users/edwin/Documents/Mendeley Desktop/Gregoire, Mahboubi/{Theorem Proving in Higher Order Logics (TPHOLS 2005)}/Gregoire, Mahboubi - 2005 - Proving Equalities in a Commutative Ring Done Right in Coq.pdf:pdf},
513+file = {:Users/edwin/Documents/Mendeley Desktop/Gregoire, Mahboubi/Proving Equalities in a Commutative Ring Done Right in Coq/Gregoire, Mahboubi - Proving Equalities in a Commutative Ring Done Right in Coq - 2005.pdf:pdf},
512514pages = {98----113},
513515title = {{Proving Equalities in a Commutative Ring Done Right in Coq}},
514516url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.61.3041},
515517year = {2005}
516518}
517−@misc{Bloat,
518−author = {Brooks, Fred},
519−file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/Unknown/Brooks - Unknown - The Design of Design Chapter 4.pdf:pdf},
520−isbn = {9780321702081},
521−title = {{The Design of Design Chapter 4}}
522−}
523−@misc{Protocols2012a,
519+@book{Cryptography2012,
524520author = {Anderson, Ross},
525−doi = {10.1093/epirev/mxr031},
526−file = {:Users/edwin/Documents/Mendeley Desktop/Anderson/Unknown/Anderson - Unknown - Security Engineering Chapter 3.pdf:pdf},
521+doi = {10.1093/intimm/dxs023},
522+file = {:Users/edwin/Documents/Mendeley Desktop/Anderson/Security Engineering Chapter 5/Anderson - Security Engineering Chapter 5 - Unknown.pdf:pdf},
527523isbn = {9780470068526},
528−issn = {1478-6729},
529−pmid = {22215642},
530−title = {{Security Engineering Chapter 3}}
524+issn = {1460-2377},
525+number = {4},
526+pmid = {22451589},
527+title = {{Security Engineering Chapter 5}},
528+url = {http://www.ncbi.nlm.nih.gov/pubmed/22451589},
529+volume = {24}
531530}
532−@inproceedings{Augustsson1998,
533−abstract = {Cayenne is a Haskell-like language. The main difference between Haskell and Cayenne is that Cayenne has dependent types, i.e., the result type of a function may depend on the argument value , and types of record components (which can be types or values) may depend on other components. Cayenne also combines the syntactic categories for value expressions and type expressions; thus reducing the number of language concepts. Having dependent types and combined type and value expressions makes the language very powerful. It is powerful enough that a special module concept is unnecessary; ordinary records suffice. It is also powerful enough to encode predicate logic at the type level, allowing types to be used as specifications of programs. However, this power comes at a cost: type checking of Cayenne is undecidable. While this may appear to be a steep price to pay, it seems to work well in practice.},
534−author = {Augustsson, Lennart},
531+@article{Brady,
532+author = {Butenhof, David R.},
533+file = {:Users/edwin/Documents/Mendeley Desktop/Butenhof/Programming with POSIX Threads Chapter 8/Butenhof - Programming with POSIX Threads Chapter 8 - Unknown.pdf:pdf},
534+isbn = {0201633922},
535+title = {{Programming with POSIX Threads Chapter 8}}
536+}
537+@inproceedings{oury2008power,
538+author = {Oury, N. and Swierstra, W.},
535539booktitle = {International Conference on Functional Programming},
536−doi = {10.1097/MEG.0b013e328342f213},
537−file = {:Users/edwin/Documents/Mendeley Desktop/Augustsson/International Conference on Functional Programming/Augustsson - 1998 - Cayenne - a language with dependent types.pdf:pdf},
538−issn = {14735687},
539−keywords = {Depe,Dependent Types},
540−mendeley-tags = {Depe,Dependent Types},
540+file = {:Users/edwin/Documents/Mendeley Desktop/Oury, Swierstra/The power of Pi/Oury, Swierstra - The power of Pi - 2008.pdf:pdf},
541+keywords = {Dependent Types},
542+mendeley-tags = {Dependent Types},
543+number = {9},
544+pages = {39--50},
545+publisher = {ACM},
546+title = {{The power of Pi}},
547+url = {http://dl.acm.org/citation.cfm?id=1411213},
548+volume = {43},
549+year = {2008}
550+}
551+@article{McBride2004a,
552+abstract = {ABSTRACT Pattern matching has proved an extremely powerful and durable notion in functional programming. This paper contributes a new programming notation for type theory which elaborates the notion in various ways. First, as is by now quite well-known in the type theory community, definition by pattern matching becomes a more discriminating tool in the presence of dependent types, since it refines the explanation of types as well as values. This becomes all the more true in the presence of the rich class of datatypes known as inductive families (Dybjer, 1991). Secondly, as proposed by Peyton Jones (1997) for Haskell, and independently rediscovered by us, subsidiary case analyses on the results of intermediate computations, which commonly take place on the right-hand side of definitions by pattern matching, should rather be handled on the left. In simply-typed languages, this subsumes the trivial case of Boolean guards; in our setting it becomes yet more powerful. Thirdly, elementary pattern matching decompositions have a well-defined interface given by a dependent type; they correspond to the statement of an induction principle for the datatype. More general, user-definable decompositions may be defined which also have types of the same general form. Elementary pattern matching may therefore be recast in abstract form, with a semantics given by translation. Such abstract decompositions of data generalize Wadler&apos;s (1987) notion of &lsquo;view&rsquo;. The programmer wishing to introduce a new view of a type mathitT, and exploit it directly in pattern matching, may do so via a standard programming idiom. The type theorist, looking through the Curry&ndash;Howard lens, may see this as proving a theorem, one which establishes the validity of a new induction principle for mathitT. We develop enough syntax and semantics to account for this high-level style of programming in dependent type theory. We close with the development of a typechecker for the simply-typed lambda calculus, which furnishes a view of raw terms as either being well-typed, or containing an error. The implementation of this view is ipso facto a proof that typechecking is decidable.},
553+author = {McBride, Conor and McKinna, James},
554+doi = {10.1017/S0956796803004829},
555+file = {:Users/edwin/Documents/Mendeley Desktop/McBride, McKinna/The view from the left/McBride, McKinna - The view from the left - 2004.pdf:pdf},
556+issn = {09567968},
557+journal = {Journal of Functional Programming},
558+keywords = {Dependent Types},
559+mendeley-tags = {Dependent Types},
541560number = {1},
542−pages = {239--250},
543−pmid = {21139473},
544−publisher = {ACM Press},
545−title = {{Cayenne - a language with dependent types}},
546−url = {http://www.cs.chalmers.se/$\sim$augustss/cayenne/paper.ps},
547−volume = {23},
548−year = {1998}
561+pages = {69--111},
562+publisher = {Cambridge University Press},
563+title = {{The view from the left}},
564+url = {http://www.journals.cambridge.org/abstract_S0956796803004829},
565+volume = {14},
566+year = {2004}
549567}
550−@book{Hunt,
551−author = {Hunt, Andrew and Thomas, David},
552−booktitle = {Design},
553−file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/Design/Hunt, Thomas - Unknown - The Pragmatic Programmer Chapter 4.pdf:pdf},
554−isbn = {020161622X},
555−title = {{The Pragmatic Programmer Chapter 4}}
568+@book{Cryptography2012a,
569+author = {Pfleeger, Charles P and Pfleeger, S. L.},
570+booktitle = {Nicotine & tobacco research : official journal of the Society for Research on Nicotine and Tobacco},
571+doi = {10.1093/ntr/nts035},
572+file = {:Users/edwin/Documents/Mendeley Desktop/Pfleeger, Pfleeger/Security in Computing Chapter 2/Pfleeger, Pfleeger - Security in Computing Chapter 2 - 2012.pdf:pdf},
573+isbn = {0132390779},
574+issn = {1469-994X},
575+month = oct,
576+number = {10},
577+pages = {NP},
578+pmid = {23012339},
579+title = {{Security in Computing Chapter 2}},
580+url = {http://www.ncbi.nlm.nih.gov/pubmed/23012339},
581+volume = {14},
582+year = {2012}
556583}
557−@article{burrows1990,
558−author = {Burrows, Michael and Abadi, Martin and Needham, Roger},
559−file = {:Users/edwin/Documents/Mendeley Desktop/Burrows, Abadi, Needham/ACM Transactions on Computer Systems/Burrows, Abadi, Needham - 1990 - A logic of authentication.pdf:pdf},
560−journal = {ACM Transactions on Computer Systems},
561−pages = {18----36},
562−title = {{A logic of authentication}},
563−url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.115.3569},
564−volume = {8},
565−year = {1990}
584+@phdthesis{Pretnar2010,
585+author = {Pretnar, Matija},
586+file = {:Users/edwin/Documents/Mendeley Desktop/Pretnar/The Logic and Handling of Algebraic Effects/Pretnar - The Logic and Handling of Algebraic Effects - 2010.pdf:pdf},
587+school = {University of Edinburgh},
588+title = {{The Logic and Handling of Algebraic Effects}},
589+year = {2010}
566590}
567−@inproceedings{atkey2009unembedding,
568−author = {Atkey, R. and Lindley, S. and Yallop, J.},
569−booktitle = {Proceedings of the 2nd ACM SIGPLAN symposium on Haskell},
570−pages = {37--48},
591+@inproceedings{Brady2010,
592+author = {Brady, Edwin and Hammond, Kevin},
593+booktitle = {Proceedings of the 15th ACM SIGPLAN international conference on Functional programming},
594+file = {:Users/edwin/Documents/Mendeley Desktop/Brady, Hammond/Scrapping your inefficient engine using partial evaluation to improve domain-specific language implementation/Brady, Hammond - Scrapping your inefficient engine using partial evaluation to improve domain-specific language implementation - 2010.pdf:pdf},
595+isbn = {9781605587943},
596+keywords = {Dependent Types,code generation gives,contrast,dependent types,efficient,harder,however,implementation,likely efficient,ness interpreter,partial evaluation,resulting implementation,un,verify its correctness},
597+mendeley-tags = {Dependent Types},
598+pages = {297--308},
571599publisher = {ACM},
572−title = {{Unembedding domain-specific languages}},
573−url = {http://dl.acm.org/citation.cfm?id=1596644},
574−year = {2009}
600+title = {{Scrapping your inefficient engine: using partial evaluation to improve domain-specific language implementation}},
601+url = {http://portal.acm.org/citation.cfm?id=1863587},
602+year = {2010}
575603}
576−@inproceedings{Brady2011a,
577−address = {New York, New York, USA},
578−author = {Brady, Edwin},
579−booktitle = {Proceedings of the 5th {ACM} workshop on Programming languages meets program verification - {PLPV} '11},
580−doi = {10.1145/1929529.1929536},
581−file = {:Users/edwin/Documents/Mendeley Desktop/Brady/Proceedings of the 5th {ACM} workshop on Programming languages meets program verification - {PLPV} '11/Brady - 2011 - Idris --- Systems Programming Meets Full Dependent Types.pdf:pdf},
582−isbn = {9781450304870},
583−keywords = {Dependent Types,data description,dependent types},
584−mendeley-tags = {Dependent Types},
585−month = jan,
586−publisher = {ACM Press},
587−title = {{Idris --- Systems Programming Meets Full Dependent Types}},
588−url = {http://dl.acm.org/citation.cfm?id=1929529.1929536},
589−year = {2011}
604+@misc{Danielsson2002,
605+author = {Danielsson, Nils Anders and Altenkirch, Thorsten},
606+file = {:Users/edwin/Documents/Mendeley Desktop/Danielsson, Altenkirch/Subtyping, Declaratively/Danielsson, Altenkirch - Subtyping, Declaratively - 2002.pdf:pdf},
607+title = {{Subtyping, Declaratively}},
608+year = {2002}
590609}
591−@inproceedings{gibbons2011modularising,
592−author = {Gibbons, J. and Ko, H.S. and Others},
593−file = {:Users/edwin/Documents/Mendeley Desktop/Ko, Gibbons/Proceedings of the seventh ACM SIGPLAN workshop on Generic programming/Ko, Gibbons - 2011 - Modularising inductive families.pdf:pdf},
594−title = {{Modularising inductive families}},
595−url = {http://www.cs.ox.ac.uk/publications/publication5008-abstract.html},
596−year = {2011}
610+@book{Strings2012,
611+author = {Sedgewick, Robert and Wayne, Kevin},
612+booktitle = {Nicotine & tobacco research : official journal of the Society for Research on Nicotine and Tobacco},
613+doi = {10.1093/ntr/nts035},
614+file = {:Users/edwin/Documents/Mendeley Desktop/Sedgewick, Wayne/Algorithms Chapter 5/Sedgewick, Wayne - Algorithms Chapter 5 - 2012.pdf:pdf},
615+isbn = {9780132762571},
616+issn = {1469-994X},
617+month = oct,
618+number = {10},
619+pages = {NP},
620+pmid = {23012339},
621+title = {{Algorithms Chapter 5}},
622+url = {http://www.ncbi.nlm.nih.gov/pubmed/23012339},
623+volume = {14},
624+year = {2012}
597625}
598−@book{An2012,
599−author = {Fowler, Martin},
600−booktitle = {Carcinogenesis},
601−doi = {10.1093/carcin/bgs054},
602−file = {:Users/edwin/Documents/Mendeley Desktop/Fowler/Carcinogenesis/Fowler - Unknown - Domain Specific Languages Chapter 1.pdf:pdf},
603−isbn = {9780132107549},
604−issn = {1460-2180},
605−number = {3},
606−pmid = {22383472},
607−title = {{Domain Specific Languages Chapter 1}},
608−url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
609−volume = {33}
626+@inproceedings{Augustsson1985,
627+address = {Berlin, Heidelberg},
628+author = {Augustsson, Lennart},
629+booktitle = {Functional Programming Languages and Computer Architecture},
630+doi = {10.1007/3-540-15975-4},
631+editor = {Jouannaud, Jean-Pierre},
632+isbn = {978-3-540-15975-9},
633+keywords = {Computer Science},
634+pages = {368----381},
635+publisher = {Springer Berlin Heidelberg},
636+series = {Lecture Notes in Computer Science},
637+title = {{Compiling Pattern Matching}},
638+url = {http://www.springerlink.com/content/y647423656557505/},
639+volume = {201},
640+year = {1985}
641+}
642+@misc{Abel1998,
643+author = {Abel, Andreas},
644+booktitle = {Language},
645+file = {:Users/edwin/Documents/Mendeley Desktop/Abel/foetus - Termination Checker for Simple Functional Programs/Abel - foetus - Termination Checker for Simple Functional Programs - 1998.pdf:pdf},
646+title = {{foetus - Termination Checker for Simple Functional Programs}},
647+year = {1998}
648+}
649+@article{Silkensen,
650+author = {Silkensen, Erik and Siek, Jeremy},
651+file = {:Users/edwin/Documents/Mendeley Desktop/Silkensen, Siek/Well-typed Islands Parse Faster/Silkensen, Siek - Well-typed Islands Parse Faster - Unknown.pdf:pdf},
652+title = {{Well-typed Islands Parse Faster}}
653+}
654+@misc{Svenningsson,
655+author = {Svenningsson, Josef and Axelsson, Emil},
656+booktitle = {Writing},
657+file = {:Users/edwin/Documents/Mendeley Desktop/Svenningsson, Axelsson/Combining Deep and Shallow Embedding for EDSL/Svenningsson, Axelsson - Combining Deep and Shallow Embedding for EDSL - Unknown.pdf:pdf},
658+title = {{Combining Deep and Shallow Embedding for EDSL}}
659+}
660+@misc{Bauer,
661+archivePrefix = {arXiv},
662+arxivId = {arXiv:1203.1539v1},
663+author = {Bauer, Andrej and Pretnar, Matija},
664+eprint = {arXiv:1203.1539v1},
665+file = {:Users/edwin/Documents/Mendeley Desktop/Bauer, Pretnar/Programming with Algebraic Effects and Handlers/Bauer, Pretnar - Programming with Algebraic Effects and Handlers - Unknown.pdf:pdf},
666+keywords = {()},
667+title = {{Programming with Algebraic Effects and Handlers}}
668+}
669+@misc{Krustev,
670+author = {Krustev, Dimitur},
671+booktitle = {Language},
672+file = {:Users/edwin/Documents/Mendeley Desktop/Krustev/Towards a Framework for Building Formally Verified Supercompilers in Coq/Krustev - Towards a Framework for Building Formally Verified Supercompilers in Coq - Unknown.pdf:pdf},
673+title = {{Towards a Framework for Building Formally Verified Supercompilers in Coq}}
674+}
675+@book{Graphs2012,
676+author = {Sedgewick, Robert and Wayne, Kevin},
677+booktitle = {The Gerontologist},
678+doi = {10.1093/geront/gns026},
679+file = {:Users/edwin/Documents/Mendeley Desktop/Sedgewick, Wayne/Algorithms Chapter 4/Sedgewick, Wayne - Algorithms Chapter 4 - 2012.pdf:pdf},
680+isbn = {9780132762571},
681+issn = {1758-5341},
682+month = dec,
683+number = {6},
684+pages = {NP},
685+pmid = {23150082},
686+title = {{Algorithms Chapter 4}},
687+url = {http://www.ncbi.nlm.nih.gov/pubmed/23150082},
688+volume = {52},
689+year = {2012}
690+}
691+@misc{Brady2012c,
692+author = {Brooks, Fred},
693+doi = {10.1093/epirev/mxr031},
694+file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/The Design of Design Chapter 5/Brooks - The Design of Design Chapter 5 - Unknown.pdf:pdf},
695+isbn = {9780321702081},
696+issn = {1478-6729},
697+number = {1},
698+pages = {NP},
699+pmid = {22215642},
700+title = {{The Design of Design Chapter 5}},
701+volume = {34}
610702}
611703@inproceedings{coquand1986analysis,
612704author = {Coquand, T.},
613705booktitle = {{Proceedings of the First IEEE Symposium on Logic in Computer Science}},
614−file = {:Users/edwin/Documents/Mendeley Desktop/Coquand/{Proceedings of the First IEEE Symposium on Logic in Computer Science}/Coquand - 1986 - An analysis of Girard's paradox.pdf:pdf},
706+file = {:Users/edwin/Documents/Mendeley Desktop/Coquand/An analysis of Girard's paradox/Coquand - An analysis of Girard's paradox - 1986.pdf:pdf},
615707pages = {227----246},
616708title = {{An analysis of Girard's paradox}},
617709url = {http://hal.inria.fr/docs/00/07/60/23/PDF/RR-0531.pdf},
618710year = {1986}
619711}
620−@misc{altenkirch2008nσ,
621−author = {Altenkirch, T. and Oury, N.},
622−file = {:Users/edwin/Documents/Mendeley Desktop/Altenkirch, Oury/Unknown/Altenkirch, Oury - 2008 - $Pi$$Sigma$ A Core Language for Dependently Typed Programming.pdf:pdf},
623−title = {{$\Pi$$\Sigma$: A Core Language for Dependently Typed Programming}},
624−url = {http://verse.aasemoon.com/images/6/6f/PiSigma.pdf},
625−year = {2008}
626−}
627−@inproceedings{barras2008implicit,
628−author = {Barras, B. and Bernardo, B.},
629−booktitle = {Foundations of Software Science and Computational Structures},
630−file = {:Users/edwin/Documents/Mendeley Desktop/Barras, Bernardo/Foundations of Software Science and Computational Structures/Barras, Bernardo - 2008 - The implicit calculus of constructions as a programming language with dependent types.pdf:pdf},
631−pages = {365--379},
632−publisher = {Springer},
633−title = {{The implicit calculus of constructions as a programming language with dependent types}},
634−url = {http://www.springerlink.com/index/m84h82904546l265.pdf},
635−year = {2008}
636−}
637−@book{While2012,
638−author = {Hunt, Andrew and Thomas, David},
639−booktitle = {Carcinogenesis},
640−doi = {10.1093/carcin/bgs054},
641−file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/Carcinogenesis/Hunt, Thomas - Unknown - The Pragmatic Programmer Chapter 6.pdf:pdf},
642−isbn = {020161622X},
643−issn = {1460-2180},
644−number = {3},
645−pmid = {22383472},
646−title = {{The Pragmatic Programmer Chapter 6}},
647−url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
648−volume = {33}
649−}
650−@inproceedings{bradyresource,
651−author = {Brady, Edwin and Hammond, Kevin},
652−booktitle = {Practical Applications of Declarative Languages ({PADL} 2012)},
653−file = {:Users/edwin/Documents/Mendeley Desktop/Brady, Hammond/Practical Applications of Declarative Languages ({PADL} 2012)/Brady, Hammond - 2012 - Resource-safe Systems Programming with Embedded Domain Specific Languages.pdf:pdf},
654−pages = {242----257},
655−title = {{Resource-safe Systems Programming with Embedded Domain Specific Languages}},
656−url = {http://www.cs.st-andrews.ac.uk/$\sim$eb/drafts/dsl-idris.pdf},
712+@book{Harper2012,
713+author = {Harper, Robert},
714+file = {:Users/edwin/Documents/Mendeley Desktop/Harper/Practical Foundations for Programming Languages/Harper - Practical Foundations for Programming Languages - 2012.pdf:pdf},
715+title = {{Practical Foundations for Programming Languages}},
657716year = {2012}
658717}
659−@book{luo1994,
660−author = {Luo, Z.},
661−publisher = {Oxford University Press, Inc.},
662−title = {{Computation and reasoning: a type theory for computer science}},
663−url = {http://dl.acm.org/citation.cfm?id=SERIES9893.184757},
664−year = {1994}
718+@misc{dagand2011transporting,
719+author = {Dagand, Pierre-Evariste and McBride, Conor},
720+file = {:Users/edwin/Documents/Mendeley Desktop/Dagand, McBride/Transporting Functions across Ornaments/Dagand, McBride - Transporting Functions across Ornaments - 2011.pdf:pdf},
721+title = {{Transporting Functions across Ornaments}},
722+url = {http://personal.cis.strath.ac.uk/$\sim$dagand/stuffs/paper-2011-patch/paper.pdf},
723+year = {2011}
665724}
666−@phdthesis{norell2007thesis,
667−author = {Norell, Ulf},
668−file = {:Users/edwin/Documents/Mendeley Desktop/Norell/Unknown/Norell - 2007 - Towards a practical programming language based on dependent type theory.pdf:pdf},
669−keywords = {Dependent Types},
670−mendeley-tags = {Dependent Types},
671−publisher = {Citeseer},
672−school = {Chalmers University of Technology},
673−title = {{Towards a practical programming language based on dependent type theory}},
674−url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.65.7934&amp;rep=rep1&amp;type=pdf},
675−year = {2007}
725+@article{Abel2010,
726+abstract = {Sized types are a modular and theoretically well-understood tool for checking termination of recursive and productivity of corecursive definitions. The essential idea is to track structural descent and guardedness in the type system to make termination checking robust and suitable for strong abstractions like higher-order functions and polymorphism. To study the application of sized types to proof assistants and programming languages based on dependent type theory, we have implemented a core language, MiniAgda, with explicit handling of sizes. New considerations were necessary to soundly integrate sized types with dependencies and pattern matching, which was made possible by concepts such as inaccessible patterns and parametric function spaces. This paper provides an introduction to MiniAgda by example and informal explanations of the underlying principles.},
727+author = {Abel, Andreas},
728+file = {:Users/edwin/Documents/Mendeley Desktop/Abel/MiniAgda Integrating Sized and Dependent Types/Abel - MiniAgda Integrating Sized and Dependent Types - 2010.pdf:pdf},
729+journal = {EPTCS},
730+pages = {1--15},
731+title = {{MiniAgda: Integrating Sized and Dependent Types}},
732+url = {http://arxiv.org/abs/1012.4896},
733+volume = {43},
734+year = {2010}
676735}
677−@inproceedings{Brady2006b,
678−author = {Brady, Edwin},
679−booktitle = {Implementation and Application of Functional Languages ({IFL}'06)},
680−file = {:Users/edwin/Documents/Mendeley Desktop/Brady/Implementation and Application of Functional Languages ({IFL}'06)/Brady - 2006 - Ivor, a proof engine.pdf:pdf},
681−isbn = {978-3-540-74129-9},
682−month = sep,
683−pages = {145----162},
684−title = {{Ivor, a proof engine}},
685−url = {http://dl.acm.org/citation.cfm?id=1757028.1757037},
686−year = {2006}
736+@article{burrows1990,
737+author = {Burrows, Michael and Abadi, Martin and Needham, Roger},
738+file = {:Users/edwin/Documents/Mendeley Desktop/Burrows, Abadi, Needham/A logic of authentication/Burrows, Abadi, Needham - A logic of authentication - 1990.pdf:pdf},
739+journal = {ACM Transactions on Computer Systems},
740+pages = {18----36},
741+title = {{A logic of authentication}},
742+url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.115.3569},
743+volume = {8},
744+year = {1990}
687745}
688−@inproceedings{chlipala2010ur,
689−author = {Chlipala, Adam},
690−booktitle = {ACM SIGPLAN Notices},
691−file = {:Users/edwin/Documents/Mendeley Desktop/Chlipala/ACM SIGPLAN Notices/Chlipala - 2010 - Ur statically-typed metaprogramming with type-level record computation.pdf:pdf},
692−number = {6},
693−pages = {122--133},
694−publisher = {ACM},
695−title = {{Ur: statically-typed metaprogramming with type-level record computation}},
696−url = {http://dl.acm.org/citation.cfm?id=1806612},
697−volume = {45},
746+@article{loh2010tutorial,
747+author = {L\"{o}h, A. and McBride, C. and Swierstra, W.},
748+file = {:Users/edwin/Documents/Mendeley Desktop/L\"{o}h, McBride, Swierstra/A tutorial implementation of a dependently typed lambda calculus/L\"{o}h, McBride, Swierstra - A tutorial implementation of a dependently typed lambda calculus - 2010.pdf:pdf},
749+journal = {Fundamenta Informaticae},
750+number = {2},
751+pages = {177--207},
752+publisher = {IOS Press},
753+title = {{A tutorial implementation of a dependently typed lambda calculus}},
754+url = {http://iospress.metapress.com/index/976W4716TM79M6U8.pdf},
755+volume = {102},
698756year = {2010}
699757}
758+@article{mcbride2008functional,
759+author = {McBride, C. and Paterson, R.},
760+file = {:Users/edwin/Documents/Mendeley Desktop/McBride, Paterson/Functional pearl Applicative programming with effects/McBride, Paterson - Functional pearl Applicative programming with effects - 2008.pdf:pdf},
761+journal = {Journal of functional programming},
762+number = {1},
763+pages = {1--13},
764+publisher = {Cambridge Univ Press},
765+title = {{Functional pearl: Applicative programming with effects}},
766+url = {http://journals.cambridge.org/production/action/cjoGetFulltext?fulltextid=1457860},
767+volume = {18},
768+year = {2008}
769+}
770+@techreport{Cardelli1988,
771+author = {Cardelli, L},
772+file = {:Users/edwin/Documents/Mendeley Desktop/Cardelli/Phase distinctions in type theory/Cardelli - Phase distinctions in type theory - 1988.pdf:pdf},
773+title = {{Phase distinctions in type theory}},
774+year = {1988}
775+}
700776@misc{Abadi1997,
701777author = {Abadi, Martin and Gordon, Andrew D},
702778booktitle = {4TH ACM CONFERENCE ON COMPUTER AND COMMUNICATIONS SECURITY},
703−file = {:Users/edwin/Documents/Mendeley Desktop/Abadi, Gordon/4TH ACM CONFERENCE ON COMPUTER AND COMMUNICATIONS SECURITY/Abadi, Gordon - 1997 - A calculus for cryptographic protocols The spi calculus.pdf:pdf},
779+file = {:Users/edwin/Documents/Mendeley Desktop/Abadi, Gordon/A calculus for cryptographic protocols The spi calculus/Abadi, Gordon - A calculus for cryptographic protocols The spi calculus - 1997.pdf:pdf},
704780pages = {36 -- 47},
705781title = {{A calculus for cryptographic protocols: The spi calculus}},
706782url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.49.2176},
707783year = {1997}
708784}
709−@inproceedings{McBride2006,
710−author = {McBride, C and Goguen, H and McKinna, J},
711−booktitle = {Types for Proofs and Programs {(TYPES 2006)}},
712−title = {{A few constructions on constructors}},
713−url = {http://www.springerlink.com/index/P4863U0M41396254.pdf},
714−year = {2006}
785+@article{Haskell2012a,
786+author = {Biancuzzi, F and Warden, S},
787+doi = {10.1093/epirev/mxr031},
788+file = {:Users/edwin/Documents/Mendeley Desktop/Biancuzzi, Warden/Masterminds of Programming Chapter 8/Biancuzzi, Warden - Masterminds of Programming Chapter 8 - Unknown.pdf:pdf},
789+isbn = {9780596801670},
790+issn = {1478-6729},
791+pmid = {22215642},
792+title = {{Masterminds of Programming Chapter 8}}
715793}
716−@article{Jones2003,
717−abstract = {Haskell is the world's leading lazy functional programming language and is widely used in teaching, research, and applications. The language continues to develop rapidly, but in 1998 the programming community decided to capture a stable snapshot of the language by introducing Haskell 98. This book constitutes the agreed definition of Haskell 98, the language itself as well as its supporting libraries, and should be a standard reference work for anyone involved in research, teaching, or applications. All Haskell compilers support Haskell 98, so professioanls and educators have a stable base for their work.},
718−author = {Jones, Simon Peyton},
719−editor = {Jones, Simon Peyton},
720−isbn = {0521826144},
721−journal = {Language},
722−number = {1},
723−publisher = {Cambridge University Press},
724−title = {{Haskell 98 Language and Libraries The Revised Report}},
725−url = {http://www.amazon.ca/exec/obidos/redirect?tag=citeulike09-20&amp;path=ASIN/0521826144},
726−volume = {13},
794+@inproceedings{madhavapeddy2010turning,
795+author = {Madhavapeddy, A. and Mortier, R. and Sohan, R. and Gazagnaire, T. and Hand, S. and Deegan, T. and McAuley, D. and Crowcroft, J.},
796+booktitle = {Proceedings of the 2nd USENIX conference on Hot topics in cloud computing},
797+file = {:Users/edwin/Documents/Mendeley Desktop/Madhavapeddy et al/Turning down the LAMP software specialisation for the cloud/Madhavapeddy et al. - Turning down the LAMP software specialisation for the cloud - 2010.pdf:pdf},
798+publisher = {USENIX Association},
799+title = {{Turning down the LAMP: software specialisation for the cloud}},
800+url = {http://dl.acm.org/citation.cfm?id=1863114},
801+year = {2010}
802+}
803+@misc{Braßel,
804+annote = {New compilation system for Curry, a Haskell like language with equational constraints, making it a functional logic language.
805+
806+
807+What is the contribution of this paper? i.e. what is new about the compiler? Seems to be efficient implementation of equational constraints.
808+
809+
810+Nice introduction to the language, easy for a Haskell programmer to follow, and nice explanation of how it works motivating the problem. But I find it hard to tell what in the paper is already known and what is a specific contribution.
811+
812+
813+Functional patterns look nice, if hard to implement. Related to views? Limitations?
814+Could these techniques improve (compile-time) unification in dependently typed languages?
815+
816+
817+Not many results. Encouraging, but only 7 of various forms isn't conclusive. },
818+author = {Bra\ss el, Bernd and Hanus, Michael and Peem\"{o}ller, Bj\"{o}rn and Reck, Fabian},
819+file = {:Users/edwin/Documents/Mendeley Desktop/Bra\ss el et al/Implementing Equational Constraints in a Functional Language/Bra\ss el et al. - Implementing Equational Constraints in a Functional Language - Unknown.pdf:pdf},
820+keywords = {func-,functional logic programming,implementation,unification},
821+title = {{Implementing Equational Constraints in a Functional Language}}
822+}
823+@inproceedings{Brady2003,
824+author = {Brady, Edwin and McBride, Conor and McKinna, James},
825+booktitle = {Types for Proofs and Programs {(TYPES 2003)}},
826+file = {:Users/edwin/Documents/Mendeley Desktop/Brady, McBride, McKinna/Inductive families need not store their indices/Brady, McBride, McKinna - Inductive families need not store their indices - 2003.pdf:pdf},
827+keywords = {Dependent Types},
828+mendeley-tags = {Dependent Types},
829+title = {{Inductive families need not store their indices}},
727830year = {2003}
728831}
729−@inproceedings{Visser2008,
730−author = {Visser, E},
731−booktitle = {Generative and Transformational Techniques in Software Engineering},
732−title = {{WebDSL: A case study in domain-specific language engineering}},
733−url = {http://www.springerlink.com/index/A3213003X6268032.pdf},
832+@book{An2012,
833+author = {Fowler, Martin},
834+booktitle = {Carcinogenesis},
835+doi = {10.1093/carcin/bgs054},
836+file = {:Users/edwin/Documents/Mendeley Desktop/Fowler/Domain Specific Languages Chapter 1/Fowler - Domain Specific Languages Chapter 1 - Unknown.pdf:pdf},
837+isbn = {9780132107549},
838+issn = {1460-2180},
839+number = {3},
840+pmid = {22383472},
841+title = {{Domain Specific Languages Chapter 1}},
842+url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
843+volume = {33}
844+}
845+@book{Choosing2012,
846+author = {Fowler, Martin},
847+booktitle = {Carcinogenesis},
848+doi = {10.1093/carcin/bgs054},
849+file = {:Users/edwin/Documents/Mendeley Desktop/Fowler/Domain Specific Languages Chapter 6/Fowler - Domain Specific Languages Chapter 6 - Unknown.pdf:pdf},
850+isbn = {9780132107549},
851+issn = {1460-2180},
852+number = {3},
853+pmid = {22383472},
854+title = {{Domain Specific Languages Chapter 6}},
855+url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
856+volume = {33}
857+}
858+@misc{altenkirch2008nσ,
859+author = {Altenkirch, T. and Oury, N.},
860+file = {:Users/edwin/Documents/Mendeley Desktop/Altenkirch, Oury/$Pi$$Sigma$ A Core Language for Dependently Typed Programming/Altenkirch, Oury - $Pi$$Sigma$ A Core Language for Dependently Typed Programming - 2008.pdf:pdf},
861+title = {{$\Pi$$\Sigma$: A Core Language for Dependently Typed Programming}},
862+url = {http://verse.aasemoon.com/images/6/6f/PiSigma.pdf},
734863year = {2008}
735864}
736−@inproceedings{ko2011modularising,
737−author = {Ko, H.S. and Gibbons, J.},
738−booktitle = {Proceedings of the seventh ACM SIGPLAN workshop on Generic programming},
739−pages = {13--24},
740−publisher = {ACM},
741−title = {{Modularising inductive families}},
742−url = {http://dl.acm.org/citation.cfm?id=2036921},
743−year = {2011}
865+@misc{Silkensen2012,
866+annote = {This paper tackles an interesting problem, namely that of building DSLs independently which are nevertheless composable (at least as far as parsing goes). The claim is that the approach taken - using type based disambiguation - can combine the good features of internal and external DSLs - namely, that they become easier to implement, and have a nice syntax.
867+
868+
869+I found the paper interesting to read, the contribution worthwhile and the results convincing, though I have a few suggestions for preparing the paper for TFP submission, since it wouldn't be possible to accept it in its current form.
870+
871+
872+Perhaps most importantly, the draft submission is in the SIGPLAN format, which means you've used a lot more space than you have available. I find that 1 SIGPLAN page becomes at least 2 in Springer format because of font size and margins, so you'll need to think carefully about what you consider the most important contribution of the paper, how much detail you can go into, and how many examples to give.
873+If it helps, I think you could reduce section 5 to just a short sketch of Typed Racket and there'd be enough of a contribution to justify a TFP paper (though of course I can't speak for other potential referees!)
874+
875+
876+I found the paper a bit difficult to read at first since I don't have a detailed understand of parsing algorithms, and I suspect I won't be alone in this among the TFP readership. It would be useful to say more in the introduction about island parsing, and what a chart parsing strategy is. An intuitive explanation of the various parsing algorithms you give formally (Example 2.3, say) would be very useful for this (possibly even more useful than the formal descriptions...).
877+
878+
879+Another advantage of internal DSLs that I didn't see mentioned explicitly in the paper is that many features of the host language - syntax, code generation, type checking - are available for free, but have to be implemented explicitly for an external DSL. Maybe this is part of what you mean by interoperability. There is more than parsing needed for this though.
880+
881+
882+A question on contribution 1: how realistic is it to assume that nonterminals are largely disjoint? I could imagine, say, function calls or arithmetic being part of multiple DSLs if not factored out. Or have I misunderstood what you mean?
883+
884+
885+Some modern languages with dependent types have systems for syntax extension, e.g. Agda has mixfix declarations, Idris has syntax rules, type-directed elaboration and overloaded variable bindings. I wonder, therefore, if your approach to parsing could be better integrated into this kind of language, where embedded verifiable DSLs seem to be an obvious application. The Typed Racket example suggests to me that this would be an interesting thing to explore.},
886+author = {Silkensen, Erik and Siek, Jeremy},
887+file = {:Users/edwin/Documents/Mendeley Desktop/Silkensen, Siek/Well-typed Islands Parse Faster/Silkensen, Siek - Well-typed Islands Parse Faster - 2012.pdf:pdf},
888+pages = {1--12},
889+title = {{Well-typed Islands Parse Faster}},
890+year = {2012}
744891}
745−@misc{Attacks2012a,
746−author = {Anderson, Ross},
892+@misc{The2012c,
893+author = {Robbins, A and Hannah, E and Lamb, L},
747894doi = {10.1093/epirev/mxr031},
748−file = {:Users/edwin/Documents/Mendeley Desktop/Anderson/Unknown/Anderson - Unknown - Security Engineering Chapter 18.pdf:pdf},
749−isbn = {9780470068526},
895+file = {:Users/edwin/Documents/Mendeley Desktop/Robbins, Hannah, Lamb/Learning the vi and Vim Editors/Robbins, Hannah, Lamb - Learning the vi and Vim Editors - Unknown.pdf:pdf},
896+isbn = {9780596529833},
750897issn = {1478-6729},
751−number = {1},
752−pages = {NP},
753898pmid = {22215642},
754−title = {{Security Engineering Chapter 18}},
755−volume = {34}
899+title = {{Learning the vi and Vim Editors}}
900+}
901+@misc{idristutorial,
902+author = {Brady, Edwin},
903+file = {:Users/edwin/Documents/Mendeley Desktop/Brady/Programming in Idris a tutorial/Brady - Programming in Idris a tutorial - 2012.pdf:pdf},
904+title = {{Programming in Idris : a tutorial}},
905+url = {http://idris-lang.org/tutorial},
906+year = {2012}
907+}
908+@book{Simon2012,
909+author = {Seibel, Peter},
910+booktitle = {The Gerontologist},
911+doi = {10.1093/geront/gns026},
912+file = {:Users/edwin/Documents/Mendeley Desktop/Seibel/Coders at Work Chapter 7/Seibel - Coders at Work Chapter 7 - 2012.pdf:pdf},
913+isbn = {9781430219484},
914+issn = {1758-5341},
915+month = dec,
916+number = {6},
917+pages = {NP},
918+pmid = {23150082},
919+title = {{Coders at Work Chapter 7}},
920+url = {http://www.ncbi.nlm.nih.gov/pubmed/23150082},
921+volume = {52},
922+year = {2012}
923+}
924+@misc{TheMendeleySupportTeam2011,
925+abstract = {A quick introduction to Mendeley. Learn how Mendeley creates your personal digital library, how to organize and annotate documents, how to collaborate and share with colleagues, and how to generate citations and bibliographies.},
926+address = {London},
927+author = {{The Mendeley Support Team}},
928+booktitle = {Mendeley Desktop},
929+file = {:Users/edwin/Documents/Mendeley Desktop/The Mendeley Support Team/Getting Started with Mendeley/The Mendeley Support Team - Getting Started with Mendeley - 2011.pdf:pdf},
930+keywords = {Mendeley,how-to,user manual},
931+pages = {1--16},
932+publisher = {Mendeley Ltd.},
933+title = {{Getting Started with Mendeley}},
934+url = {http://www.mendeley.com},
935+year = {2011}
936+}
937+@book{Brady2012d,
938+author = {Seibel, Peter},
939+booktitle = {The Gerontologist},
940+doi = {10.1093/geront/gns026},
941+file = {:Users/edwin/Documents/Mendeley Desktop/Seibel/Coders at Work Chapter 6/Seibel - Coders at Work Chapter 6 - 2012.pdf:pdf},
942+isbn = {9781430219484},
943+issn = {1758-5341},
944+month = dec,
945+number = {6},
946+pages = {NP},
947+pmid = {23150082},
948+title = {{Coders at Work Chapter 6}},
949+url = {http://www.ncbi.nlm.nih.gov/pubmed/23150082},
950+volume = {52},
951+year = {2012}
756952}
757953@inproceedings{l,
758954author = {L\"{a}mmel, R. and Jones, S.P.},
759955booktitle = {ACM SIGPLAN Notices},
760−file = {:Users/edwin/Documents/Mendeley Desktop/L\"{a}mmel, Jones/ACM SIGPLAN Notices/L\"{a}mmel, Jones - 2003 - Scrap your boilerplate a practical design pattern for generic programming.pdf:pdf},
956+file = {:Users/edwin/Documents/Mendeley Desktop/L\"{a}mmel, Jones/Scrap your boilerplate a practical design pattern for generic programming/L\"{a}mmel, Jones - Scrap your boilerplate a practical design pattern for generic programming - 2003.pdf:pdf},
761957number = {3},
762958pages = {26--37},
763959publisher = {ACM},
@@ -766,213 +962,303 @@ url = {http://dl.acm.org/citation.cfm?id=640136.604179},
766962volume = {38},
767963year = {2003}
768964}
769−@inproceedings{Delahaye2000,
770−author = {Delahaye, D},
771−booktitle = {Logic for Programming and Automated Reasoning},
772−file = {:Users/edwin/Documents/Mendeley Desktop/Delahaye/Logic for Programming and Automated Reasoning/Delahaye - 2000 - A tactic language for the system Coq.pdf:pdf;:Users/edwin/Documents/Mendeley Desktop/Delahaye/Logic for Programming and Automated Reasoning/Delahaye - 2000 - A tactic language for the system Coq(2).pdf:pdf},
773−pages = {85----95},
774−publisher = {Springer},
775−title = {{A tactic language for the system Coq}},
776−url = {http://www.springerlink.com/index/EFQAH8J88K42VN8T.pdf},
777−year = {2000}
965+@phdthesis{Okasaki1996,
966+author = {Okasaki, Chris},
967+file = {:Users/edwin/Documents/Mendeley Desktop/Okasaki/Purely Functional Data Structures/Okasaki - Purely Functional Data Structures - 1996.pdf:pdf},
968+school = {Carnegie Mellon University},
969+title = {{Purely Functional Data Structures}},
970+year = {1996}
778971}
779−@misc{pollack1997believe,
780−author = {Pollack, R.},
781−file = {:Users/edwin/Documents/Mendeley Desktop/Pollack/Unknown/Pollack - 1997 - How to believe a machine-checked proof.pdf:pdf},
782−title = {{How to believe a machine-checked proof}},
783−url = {http://books.google.co.uk/books?hl=en&amp;lr=&amp;id=pLnKggT_In4C&amp;oi=fnd&amp;pg=PA205&amp;dq=how+to+believe+a+machine+checked+proof&amp;ots=c2OI8krqqA&amp;sig=EF3QonGFVdOpYdKO1KmW6ljCkjY},
784−year = {1997}
972+@inproceedings{McBride2004b,
973+author = {McBride, Conor and McKinna, James},
974+booktitle = {Haskell Workshop},
975+file = {:Users/edwin/Documents/Mendeley Desktop/McBride, McKinna/I am not a number I am a free variable/McBride, McKinna - I am not a number I am a free variable - 2004.pdf:pdf},
976+title = {{I am not a number : I am a free variable}},
977+year = {2004}
785978}
786−@book{Bertot2004,
787−author = {Bertot, Yves and Cast\'{e}ran, Pierre},
979+@inproceedings{Brady2005a,
980+author = {Brady, E and Hammond, K},
981+booktitle = {Implementation and Application of Functional \ldots},
982+file = {:Users/edwin/Documents/Mendeley Desktop/Brady, Hammond/A dependently typed framework for static analysis of program execution costs/Brady, Hammond - A dependently typed framework for static analysis of program execution costs - 2005.pdf:pdf},
983+keywords = {Dependent Types},
984+mendeley-tags = {Dependent Types},
985+title = {{A dependently typed framework for static analysis of program execution costs}},
986+url = {http://www.springerlink.com/index/P446P2HH70107759.pdf},
987+year = {2005}
988+}
989+@misc{TMR13,
990+author = {Eidhof, Chris and Elkins, Derek and Hicks, Stephen},
991+file = {:Users/edwin/Documents/Mendeley Desktop/Eidhof, Elkins, Hicks/The Monad . Reader Issue 13/Eidhof, Elkins, Hicks - The Monad . Reader Issue 13 - 2009.pdf:pdf},
992+number = {13},
993+title = {{The Monad . Reader Issue 13}},
994+year = {2009}
995+}
996+@inproceedings{taha2004gentle,
997+author = {Taha, W.},
998+booktitle = {Domain-Specific Program Generation},
999+pages = {30--50},
7881000publisher = {Springer},
789−title = {{Interactive theorem proving and program development: {Coq'Art}: the {Calculus of Inductive Constructions}}},
790−url = {http://books.google.co.uk/books?hl=en&amp;lr=&amp;id=m5w5PRj5Nj4C&amp;oi=fnd&amp;pg=PA1&amp;dq=coq+theorem+prover&amp;ots=VHny1IYV0h&amp;sig=-K0FC67cdkhMDkAocFla8cZyRT4},
1001+title = {{A gentle introduction to multi-stage programming}},
1002+url = {http://www.springerlink.com/index/JEMT0D8VYN5JB2L8.pdf},
7911003year = {2004}
7921004}
793−@inproceedings{brady2011epic,
794−author = {Brady, Edwin},
795−booktitle = {Trends in Functional Programming ({TFP}’11)},
796−file = {:Users/edwin/Documents/Mendeley Desktop/Brady/Trends in Functional Programming ({TFP}’11)/Brady - 2011 - Epic --- A Library for Generating Compilers.pdf:pdf},
797−title = {{Epic --- A Library for Generating Compilers}},
798−url = {http://scholar.google.co.uk/scholar?cites=2588300990390214449&as_sdt=2005&sciodt=0,5&hl=en#1},
799−year = {2011}
1005+@article{Rose,
1006+annote = {This paper describes a language, Jeeves, for describing privacy policies and ensuring that they are automatically enforced. It gives the semantics of Jeeves in terms of a translation to a target language $\lambda_J$ and shows how to implement the privacy rules in a monadic style in Haskell which captures the constraint propagation.
1007+
1008+
1009+Capturing policy rules in this way is an interesting idea and the monadic definition of constraint propagation is natural, but unfortunately the paper itself only seems half-written. I found the website (https://sites.google.com/site/jeevesprogramming/) and the tutorial there much more enlightening! Perhaps relating the implementation to some more extensive examples would be helpful, illustrating how the Haskell code relates to Jeeves programs. This would be particularly valuable in sections 3 and 5, and there is plenty of space available for this.
1010+
1011+
1012+The paper could use a thorough proof read and spell check. For example:
1013+
1014+
1015+end of sec 1 - references for the report and web site would be useful here.
1016+End of sec 2: privacy politics? This is the only place this phrase is used.
1017+
1018+
1019+p2 etal => et al
1020+
1021+
1022+"The program read" => "The program reads"
1023+"Depending on what" => comma before this
1024+"bottem" => "bottom"
1025+
1026+
1027+p4 "Eventhough" => "Even though"
1028+"The program body, consist" => "The program body consists"
1029+
1030+
1031+"but without any substantial..." - there is a missing word here
1032+
1033+
1034+The presentation of Sec 5 is untidy - for example a section heading at the end of the page and bad spacing between subsections.
1035+
1036+
1037+Reference 1 is blank
1038+
1039+
1040+
1041+ },
1042+author = {Rose, Eva},
1043+file = {:Users/edwin/Documents/Mendeley Desktop/Rose/Declarative implementation aspects of privacy policy effects/Rose - Declarative implementation aspects of privacy policy effects - Unknown.pdf:pdf},
1044+keywords = {constraints,language design,mon-,privacy policy,semantics},
1045+title = {{Declarative implementation aspects of privacy policy effects}}
8001046}
801−@article{dybjer1994inductive,
802−author = {Dybjer, P.},
803−journal = {Formal aspects of computing},
804−number = {4},
805−pages = {440--465},
1047+@inproceedings{morris2006exploring,
1048+author = {Morris, P. and Altenkirch, T. and McBride, C.},
1049+booktitle = {Types for Proofs and Programs},
1050+file = {:Users/edwin/Documents/Mendeley Desktop/Morris, Altenkirch, McBride/Exploring the regular tree types/Morris, Altenkirch, McBride - Exploring the regular tree types - 2006.pdf:pdf},
1051+pages = {252--267},
8061052publisher = {Springer},
807−title = {{Inductive families}},
808−url = {http://www.springerlink.com/index/J17824H467X6J288.pdf},
809−volume = {6},
1053+title = {{Exploring the regular tree types}},
1054+url = {http://www.springerlink.com/index/f9p1317716614834.pdf},
1055+year = {2006}
1056+}
1057+@inproceedings{pj2006gadts,
1058+author = {{Peyton Jones}, S. and Vytiniotis, D. and Weirich, S. and Washburn, G.},
1059+booktitle = {{International Conference on Functional Programming} ({ICFP} '06)},
1060+file = {:Users/edwin/Documents/Mendeley Desktop/Peyton Jones et al/Simple unification-based type inference for GADTs/Peyton Jones et al. - Simple unification-based type inference for GADTs - 2006.pdf:pdf},
1061+number = {9},
1062+pages = {50--61},
1063+publisher = {ACM},
1064+title = {{Simple unification-based type inference for GADTs}},
1065+url = {http://dl.acm.org/citation.cfm?id=1159811},
1066+volume = {41},
1067+year = {2006}
1068+}
1069+@book{luo1994,
1070+author = {Luo, Z.},
1071+publisher = {Oxford University Press, Inc.},
1072+title = {{Computation and reasoning: a type theory for computer science}},
1073+url = {http://dl.acm.org/citation.cfm?id=SERIES9893.184757},
8101074year = {1994}
8111075}
812−@inproceedings{McBride2004b,
813−author = {McBride, Conor and McKinna, James},
814−booktitle = {Haskell Workshop},
815−file = {:Users/edwin/Documents/Mendeley Desktop/McBride, McKinna/Haskell Workshop/McBride, McKinna - 2004 - I am not a number I am a free variable.pdf:pdf},
816−title = {{I am not a number : I am a free variable}},
817−year = {2004}
1076+@misc{Hancock,
1077+author = {Hancock, Peter and Setzer, Anton},
1078+file = {:Users/edwin/Documents/Mendeley Desktop/Hancock, Setzer/Interactive Programs in Dependent Type Theory/Hancock, Setzer - Interactive Programs in Dependent Type Theory - 2000(2).pdf:pdf},
1079+keywords = {dependent types,functional programming,interac-,monadic i,o,reactive programming,refinement,repetition constructs,tion},
1080+title = {{Interactive Programs in Dependent Type Theory}},
1081+year = {2000}
8181082}
819−@article{Wadler2001,
820−abstract = {The use of monads to structure functional programs is described. Monads provide a convenient framework for simulating effects found in other languages, such as global state, exception handling, output, or non-determinism. Three case studies are looked at in detail: how monads ease the modification of a simple evaluator; how monads act as the basis of a datatype of arrays subject to in-place update; and how monads can be used to build parsers.},
821−author = {Wadler, Philip},
822−doi = {10.1007/3-540-59451-5_2},
823−editor = {Jeuring, Johan and Meijer, Erik},
824−file = {:Users/edwin/Documents/Mendeley Desktop/Wadler/Advanced Functional Programming/Wadler - 2001 - Monads for functional programming.pdf:pdf},
825−isbn = {3540594515},
826−issn = {03029743},
827−journal = {Advanced Functional Programming},
828−number = {August 1992},
829−pages = {24--52},
830−publisher = {Springer},
831−series = {Lecture Notes in Computer Science},
832−title = {{Monads for functional programming}},
833−url = {http://www.springerlink.com/index/715264614rh13340.pdf},
834−volume = {925},
835−year = {2001}
1083+@book{Chlipala2012,
1084+author = {Chlipala, Adam},
1085+file = {:Users/edwin/Documents/Mendeley Desktop/Chlipala/Certified Programming with Dependent Types/Chlipala - Certified Programming with Dependent Types - 2012.pdf:pdf},
1086+title = {{Certified Programming with Dependent Types}},
1087+year = {2012}
8361088}
837−@inproceedings{taha1997multi,
838−author = {Taha, W. and Sheard, T.},
839−booktitle = {ACM SIGPLAN Notices},
840−number = {12},
841−pages = {203--217},
1089+@article{Mandelbaum2007,
1090+abstract = {Massive amounts of useful data are stored and processed in ad hoc formats for which common tools like parsers, printers, query engines and format converters are not readily available. In this paper, we explain the design and implementation of PADS/ML , a new language and system that facilitates the generation of data processing tools for ad hoc formats. The PADS/ML design includes features such as dependent, polymorphic and recursive datatypes, which allow programmers to describe the syntax and semantics of ad hoc data in a concise, easy-to-read notation. The PADS/ML implementation compiles these descriptions into ml structures and functors that include types for parsed data, functions for parsing and printing, and auxiliary support for user-specified, format-dependent and format-independent tool generation.},
1091+author = {Mandelbaum, Yitzhak and Fisher, Kathleen and Walker, David and Fernandez, Mary and Gleyzer, Artem},
1092+doi = {10.1145/1190215.1190231},
1093+isbn = {1595935754},
1094+issn = {03621340},
1095+journal = {SIGPLAN Not},
1096+number = {1},
1097+pages = {77--83},
8421098publisher = {ACM},
843−title = {{Multi-stage programming with explicit annotations}},
844−url = {http://dl.acm.org/citation.cfm?id=259019},
845−volume = {32},
846−year = {1997}
1099+series = {POPL '07},
1100+title = {{PADS/ML: a functional data description language}},
1101+url = {http://doi.acm.org/10.1145/1190216.1190231},
1102+volume = {42},
1103+year = {2007}
8471104}
848−@article{loh2010tutorial,
849−author = {L\"{o}h, A. and McBride, C. and Swierstra, W.},
850−file = {:Users/edwin/Documents/Mendeley Desktop/L\"{o}h, McBride, Swierstra/Fundamenta Informaticae/L\"{o}h, McBride, Swierstra - 2010 - A tutorial implementation of a dependently typed lambda calculus.pdf:pdf},
851−journal = {Fundamenta Informaticae},
852−number = {2},
853−pages = {177--207},
854−publisher = {IOS Press},
855−title = {{A tutorial implementation of a dependently typed lambda calculus}},
856−url = {http://iospress.metapress.com/index/976W4716TM79M6U8.pdf},
857−volume = {102},
858−year = {2010}
1105+@article{Nabais2008,
1106+author = {Nabais, Davide},
1107+file = {:Users/edwin/Documents/Mendeley Desktop/Nabais/DesCo a Web Based Information System for Descriptional Complexity of Formal Languages/Nabais - DesCo a Web Based Information System for Descriptional Complexity of Formal Languages - 2008.pdf:pdf},
1108+journal = {Most},
1109+pages = {1--5},
1110+title = {{DesCo : a Web Based Information System for Descriptional Complexity of Formal Languages}},
1111+year = {2008}
8591112}
860−@book{Philosophy2012,
861−author = {Hunt, Andrew and Thomas, David},
862−booktitle = {Carcinogenesis},
863−doi = {10.1093/carcin/bgs054},
864−file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/Carcinogenesis/Hunt, Thomas - Unknown - The Pragmatic Programmer Chapter 1.pdf:pdf},
865−isbn = {020161622X},
866−issn = {1460-2180},
867−number = {3},
868−pmid = {22383472},
869−title = {{The Pragmatic Programmer Chapter 1}},
870−url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
871−volume = {33}
1113+@book{Edition2012,
1114+author = {Pfleeger, Charles P and Pfleeger, S. L.},
1115+booktitle = {Nicotine & tobacco research : official journal of the Society for Research on Nicotine and Tobacco},
1116+doi = {10.1093/ntr/nts035},
1117+file = {:Users/edwin/Documents/Mendeley Desktop/Pfleeger, Pfleeger/Security in Computing Chapter 1/Pfleeger, Pfleeger - Security in Computing Chapter 1 - 2012.pdf:pdf},
1118+isbn = {0132390779},
1119+issn = {1469-994X},
1120+month = oct,
1121+number = {10},
1122+pages = {NP},
1123+pmid = {23012339},
1124+title = {{Security in Computing Chapter 1}},
1125+url = {http://www.ncbi.nlm.nih.gov/pubmed/23012339},
1126+volume = {14},
1127+year = {2012}
8721128}
873−@inproceedings{pollack1990implicit,
874−author = {Pollack, R.},
875−booktitle = {{Informal Proceedings of First Workshop on Logical Frameworks, Antibes}},
876−file = {:Users/edwin/Documents/Mendeley Desktop/Pollack/{Informal Proceedings of First Workshop on Logical Frameworks, Antibes}/Pollack - 1990 - Implicit syntax.pdf:pdf},
877−publisher = {Citeseer},
878−title = {{Implicit syntax}},
879−url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.30.7361&amp;rep=rep1&amp;type=pdf},
880−year = {1990}
1129+@book{Eap,
1130+author = {Fall, Kevin R and Stevens, W. Richard},
1131+file = {:Users/edwin/Documents/Mendeley Desktop/Fall, Stevens/TCPIP Illustrated Chapter 18/Fall, Stevens - TCPIP Illustrated Chapter 18 - Unknown.pdf:pdf},
1132+isbn = {9780132808200},
1133+title = {{TCP/IP Illustrated Chapter 18}}
8811134}
882−@article{gordon2003authenticity,
883−author = {Gordon, A.D. and Jeffrey, A.},
884−file = {:Users/edwin/Documents/Mendeley Desktop/Gordon, Jeffrey/Journal of computer security/Gordon, Jeffrey - 2003 - Authenticity by typing for security protocols.pdf:pdf},
885−journal = {Journal of computer security},
886−number = {4},
887−pages = {451--520},
888−publisher = {IOS Press},
889−title = {{Authenticity by typing for security protocols}},
890−url = {http://iospress.metapress.com/index/BHQQUFRA1C7W8TLY.pdf},
891−volume = {11},
892−year = {2003}
1135+@book{Fowler,
1136+author = {Fowler, Martin},
1137+booktitle = {Language},
1138+file = {:Users/edwin/Documents/Mendeley Desktop/Fowler/Domain Specific Languages Chapter 2/Fowler - Domain Specific Languages Chapter 2 - Unknown.pdf:pdf},
1139+isbn = {9780132107549},
1140+title = {{Domain Specific Languages Chapter 2}}
8931141}
894−@inproceedings{Wadler1989,
895−abstract = {From the type of a polymorphic function we can derive a theorem that it satisfies. Every function of the same type satisfies the same theorem. This provides a free source of useful theorems, courtesy of Reynolds' abstraction theorem for the polymorphic lambda calculus.},
896−author = {Wadler, Philip},
897−booktitle = {Proceedings of the fourth international conference on Functional programming languages and computer architecture},
898−doi = {10.1145/99370.99404},
899−file = {:Users/edwin/Documents/Mendeley Desktop/Wadler/Proceedings of the fourth international conference on Functional programming languages and computer architecture/Wadler - 1989 - Theorems for free!.pdf:pdf},
900−isbn = {0897913280},
901−number = {June},
902−pages = {347--359},
903−publisher = {ACM},
904−series = {FPCA '89},
905−title = {{Theorems for free!}},
906−url = {http://portal.acm.org/citation.cfm?id=99404},
907−year = {1989}
1142+@book{Brady2012e,
1143+author = {Seibel, Peter},
1144+booktitle = {The Gerontologist},
1145+doi = {10.1093/geront/gns026},
1146+file = {:Users/edwin/Documents/Mendeley Desktop/Seibel/Coders at Work Chapter 9/Seibel - Coders at Work Chapter 9 - 2012.pdf:pdf},
1147+isbn = {9781430219484},
1148+issn = {1758-5341},
1149+month = dec,
1150+number = {6},
1151+pages = {NP},
1152+pmid = {23150082},
1153+title = {{Coders at Work Chapter 9}},
1154+url = {http://www.ncbi.nlm.nih.gov/pubmed/23150082},
1155+volume = {52},
1156+year = {2012}
9081157}
909−@inproceedings{Augustsson1985,
910−address = {Berlin, Heidelberg},
911−author = {Augustsson, Lennart},
912−booktitle = {Functional Programming Languages and Computer Architecture},
913−doi = {10.1007/3-540-15975-4},
914−editor = {Jouannaud, Jean-Pierre},
915−isbn = {978-3-540-15975-9},
916−keywords = {Computer Science},
917−pages = {368----381},
918−publisher = {Springer Berlin Heidelberg},
919−series = {Lecture Notes in Computer Science},
920−title = {{Compiling Pattern Matching}},
921−url = {http://www.springerlink.com/content/y647423656557505/},
922−volume = {201},
923−year = {1985}
1158+@article{Regular2012,
1159+author = {Kernighan, Brian},
1160+doi = {10.1093/geront/gns026},
1161+file = {:Users/edwin/Documents/Mendeley Desktop/Kernighan/Beautiful Code Chapter 1/Kernighan - Beautiful Code Chapter 1 - 2012.pdf:pdf},
1162+isbn = {9780596510046},
1163+issn = {1758-5341},
1164+month = dec,
1165+number = {6},
1166+pages = {NP},
1167+pmid = {23150082},
1168+title = {{Beautiful Code Chapter 1}},
1169+url = {http://www.ncbi.nlm.nih.gov/pubmed/23150082},
1170+volume = {52},
1171+year = {2012}
9241172}
925−@inproceedings{Brady2005a,
926−author = {Brady, E and Hammond, K},
927−booktitle = {Implementation and Application of Functional \ldots},
928−file = {:Users/edwin/Documents/Mendeley Desktop/Brady, Hammond/Implementation and Application of Functional \ldots/Brady, Hammond - 2005 - A dependently typed framework for static analysis of program execution costs.pdf:pdf},
1173+@inproceedings{norell2009dependently,
1174+author = {Norell, Ulf},
1175+booktitle = {Advanced Functional Programming},
1176+file = {:Users/edwin/Documents/Mendeley Desktop/Norell/Dependently typed programming in Agda/Norell - Dependently typed programming in Agda - 2009.pdf:pdf},
9291177keywords = {Dependent Types},
9301178mendeley-tags = {Dependent Types},
931−title = {{A dependently typed framework for static analysis of program execution costs}},
932−url = {http://www.springerlink.com/index/P446P2HH70107759.pdf},
933−year = {2005}
1179+pages = {230--266},
1180+publisher = {Springer},
1181+title = {{Dependently typed programming in Agda}},
1182+url = {http://www.springerlink.com/index/8X0H38858233VN26.pdf},
1183+year = {2009}
9341184}
935−@article{Vytiniotis2011,
936−author = {Vytiniotis, Dimitrios and {Peyton Jones}, Simon and Schrijvers, Tom and Sulzmann, Martin},
937−file = {:Users/edwin/Documents/Mendeley Desktop/Vytiniotis et al/{Journal of Functional Programming}/Vytiniotis et al. - 2011 - textsc{OutsideIn}(X) Modular type inference with local assumptions(2).pdf:pdf;:Users/edwin/Documents/Mendeley Desktop/Vytiniotis et al/{Journal of Functional Programming}/Vytiniotis et al. - 2011 - textsc{OutsideIn}(X) Modular type inference with local assumptions.pdf:pdf},
938−journal = {{Journal of Functional Programming}},
1185+@misc{Interface2012a,
1186+author = {Kreibich, Jay A.},
1187+doi = {10.1093/epirev/mxr031},
1188+file = {:Users/edwin/Documents/Mendeley Desktop/Kreibich/Using SQLite Chapter 7/Kreibich - Using SQLite Chapter 7 - Unknown.pdf:pdf},
1189+isbn = {9781449394592},
1190+issn = {1478-6729},
1191+pmid = {22215642},
1192+title = {{Using SQLite Chapter 7}}
1193+}
1194+@inproceedings{Augustsson1998,
1195+abstract = {Cayenne is a Haskell-like language. The main difference between Haskell and Cayenne is that Cayenne has dependent types, i.e., the result type of a function may depend on the argument value , and types of record components (which can be types or values) may depend on other components. Cayenne also combines the syntactic categories for value expressions and type expressions; thus reducing the number of language concepts. Having dependent types and combined type and value expressions makes the language very powerful. It is powerful enough that a special module concept is unnecessary; ordinary records suffice. It is also powerful enough to encode predicate logic at the type level, allowing types to be used as specifications of programs. However, this power comes at a cost: type checking of Cayenne is undecidable. While this may appear to be a steep price to pay, it seems to work well in practice.},
1196+author = {Augustsson, Lennart},
1197+booktitle = {International Conference on Functional Programming},
1198+doi = {10.1097/MEG.0b013e328342f213},
1199+file = {:Users/edwin/Documents/Mendeley Desktop/Augustsson/Cayenne - a language with dependent types/Augustsson - Cayenne - a language with dependent types - 1998.pdf:pdf},
1200+issn = {14735687},
1201+keywords = {Depe,Dependent Types},
1202+mendeley-tags = {Depe,Dependent Types},
1203+number = {1},
1204+pages = {239--250},
1205+pmid = {21139473},
1206+publisher = {ACM Press},
1207+title = {{Cayenne - a language with dependent types}},
1208+url = {http://www.cs.chalmers.se/$\sim$augustss/cayenne/paper.ps},
1209+volume = {23},
1210+year = {1998}
1211+}
1212+@article{OutsideIn,
1213+author = {Vytiniotis, D and {Peyton Jones}, Simon and Shrijvers, Tom and Sulzmann, Martin},
1214+file = {:Users/edwin/Documents/Mendeley Desktop/Vytiniotis et al/textsc{OutsideIn}(X) Modular type inference with local assumptions/Vytiniotis et al. - textsc{OutsideIn}(X) Modular type inference with local assumptions - 2011.pdf:pdf},
1215+journal = {Journal of Functional Programming},
9391216number = {4--5},
9401217pages = {333----412},
941−title = {{\textsc{OutsideIn}(X) Modular type inference with local assumptions}},
942−url = {http://journals.cambridge.org/abstract_S0956796811000098},
1218+title = {{OutsideIn (X) Modular type inference with local assumptions}},
1219+url = {http://journals.cambridge.org/production/action/cjoGetFulltext?fulltextid=8274818},
9431220volume = {21},
9441221year = {2011}
9451222}
946−@article{mccann2000packet,
947−author = {McCann, P.J. and Chandra, S.},
948−journal = {ACM SIGCOMM Computer Communication Review},
949−number = {4},
950−pages = {321--333},
1223+@inproceedings{fisher2005pads,
1224+author = {Fisher, K. and Gruber, R.},
1225+booktitle = {ACM SIGPLAN Notices},
1226+number = {6},
1227+pages = {295--304},
9511228publisher = {ACM},
952−title = {{Packet types: abstract specification of network protocol messages}},
953−url = {http://dl.acm.org/citation.cfm?id=347563},
954−volume = {30},
955−year = {2000}
1229+title = {{PADS: a domain-specific language for processing ad hoc data}},
1230+url = {http://dl.acm.org/citation.cfm?id=1065046},
1231+volume = {40},
1232+year = {2005}
9561233}
957−@article{Miller1992,
958−author = {Miller, Dale},
959−file = {:Users/edwin/Documents/Mendeley Desktop/Miller/Journal of Symbolic Computation/Miller - 1992 - Unification under a mixed prefix.pdf:pdf},
960−journal = {Journal of Symbolic Computation},
961−title = {{Unification under a mixed prefix}},
962−url = {http://www.sciencedirect.com/science/article/pii/074771719290011R},
963−year = {1992}
1234+@inproceedings{Levitation2010,
1235+author = {Chapman, James and Dagand, Pierre-Evariste and McBride, Conor and Morris, Peter},
1236+booktitle = {{15th ACM SIGPLAN International Conference on Functional programming (ICFP '10)}},
1237+doi = {10.1145/1932681.1863547},
1238+file = {:Users/edwin/Documents/Mendeley Desktop/Chapman et al/The gentle art of levitation/Chapman et al. - The gentle art of levitation - 2010.pdf:pdf},
1239+isbn = {978-1-60558-794-3},
1240+issn = {03621340},
1241+keywords = {Dependent Types,data structure,metaprogramming,monads,proof assistants,type systems},
1242+mendeley-tags = {Dependent Types},
1243+month = sep,
1244+number = {9},
1245+title = {{The gentle art of levitation}},
1246+url = {http://dl.acm.org/citation.cfm?id=1932681.1863547},
1247+volume = {45},
1248+year = {2010}
9641249}
965−@inproceedings{norell2009dependently,
966−author = {Norell, Ulf},
967−booktitle = {Advanced Functional Programming},
968−file = {:Users/edwin/Documents/Mendeley Desktop/Norell/Advanced Functional Programming/Norell - 2009 - Dependently typed programming in Agda.pdf:pdf},
969−keywords = {Dependent Types},
970−mendeley-tags = {Dependent Types},
971−pages = {230--266},
972−publisher = {Springer},
973−title = {{Dependently typed programming in Agda}},
974−url = {http://www.springerlink.com/index/8X0H38858233VN26.pdf},
975−year = {2009}
1250+@book{While2012,
1251+author = {Hunt, Andrew and Thomas, David},
1252+booktitle = {Carcinogenesis},
1253+doi = {10.1093/carcin/bgs054},
1254+file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/The Pragmatic Programmer Chapter 6/Hunt, Thomas - The Pragmatic Programmer Chapter 6 - Unknown.pdf:pdf},
1255+isbn = {020161622X},
1256+issn = {1460-2180},
1257+number = {3},
1258+pmid = {22383472},
1259+title = {{The Pragmatic Programmer Chapter 6}},
1260+url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
1261+volume = {33}
9761262}
9771263@article{Hughes1989,
9781264abstract = {As software becomes more and more complex, it is more and more important to structure it well. Well-structured software is easy to write, easy to debug, and provides a collection of modules that can be re-used to reduce future programming costs. Conventional languages place conceptual limits on the way problems can be modularised. Functional languages push those limits back. In this paper we show that two features of functional languages in particular, higher-order functions and lazy evaluation, can contribute greatly to modularity. As examples, we manipulate lists and trees, program several numerical algorithms, and implement the alpha-beta heuristic (an algorithm from Artificial Intelligence used in game-playing programs). Since modularity is the key to successful programming, functional languages are vitally important to the real world.},
@@ -980,7 +1266,7 @@ author = {Hughes, J},
9801266chapter = {2},
9811267doi = {10.1093/comjnl/32.2.98},
9821268editor = {Turner, David A},
983−file = {:Users/edwin/Documents/Mendeley Desktop/Hughes/The Computer Journal/Hughes - 1989 - Why Functional Programming Matters.pdf:pdf},
1269+file = {:Users/edwin/Documents/Mendeley Desktop/Hughes/Why Functional Programming Matters/Hughes - Why Functional Programming Matters - 1989.pdf:pdf},
9841270institution = {Programming Methodology Group, University of {G\"{o}teborg} and Chalmers Institute of Technology, Sweden},
9851271isbn = {0201172364},
9861272issn = {00104620},
@@ -993,57 +1279,401 @@ url = {http://comjnl.oupjournals.org/cgi/doi/10.1093/comjnl/32.2.98},
9931279volume = {32},
9941280year = {1989}
9951281}
996−@article{Steiner1988,
997−author = {Steiner, JG},
998−file = {:Users/edwin/Documents/Mendeley Desktop/Steiner/Proc. Winter USENIX Conference/Steiner - 1988 - Kerberos An authentication service for open network systems.pdf:pdf},
999−journal = {Proc. Winter USENIX Conference},
1000−title = {{Kerberos: An authentication service for open network systems}},
1001−url = {http://www.cse.nd.edu/$\sim$dthain/courses/cse598z/fall2004/papers/kerberos.pdf},
1002−year = {1988}
1282+@inproceedings{Asperti2011,
1283+author = {Asperti, Andrea and Ricciotti, Wilmer and Coen, Claudio Sacerdoti and Tassi, Enrico},
1284+booktitle = {Automated Deduction --- CADE-23},
1285+file = {:Users/edwin/Documents/Mendeley Desktop/Asperti et al/The Matita Interactive Theorem Prover/Asperti et al. - The Matita Interactive Theorem Prover - 2011.pdf:pdf},
1286+pages = {64----69},
1287+title = {{The Matita Interactive Theorem Prover}},
1288+year = {2011}
10031289}
1004−@phdthesis{McBride1999,
1005−author = {McBride, Conor},
1006−file = {:Users/edwin/Documents/Mendeley Desktop/McBride/Unknown/McBride - 1999 - Dependently typed functional programs and their proofs.pdf:pdf},
1290+@article{Brady2006a,
1291+author = {Brady, E and Hammond, K},
1292+file = {:Users/edwin/Documents/Mendeley Desktop/Brady, Hammond/A verified staged interpreter is a verified compiler/Brady, Hammond - A verified staged interpreter is a verified compiler - 2006.pdf:pdf},
1293+journal = {\ldots of the 5th international conference on \ldots},
10071294keywords = {Dependent Types},
10081295mendeley-tags = {Dependent Types},
1009−school = {University of Edinburgh},
1010−title = {{Dependently typed functional programs and their proofs}},
1011−url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.26.4785&rep=rep1&type=pdf},
1012−year = {1999}
1296+title = {{A verified staged interpreter is a verified compiler}},
1297+url = {http://portal.acm.org/citation.cfm?id=1173706.1173724},
1298+year = {2006}
10131299}
1014−@inproceedings{augustsson1999exercise,
1015−author = {Augustsson, L. and Carlsson, M.},
1016−booktitle = {In Workshop on Dependent Types in Programming, Gothenburg},
1017−keywords = {Depe},
1018−mendeley-tags = {Depe},
1019−publisher = {Citeseer},
1020−title = {{An exercise in dependent types: A well-typed interpreter}},
1021−url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.39.2895},
1022−year = {1999}
1300+@article{Xi1998,
1301+abstract = {We present a type-based approach to eliminating array bound checking and list tag checking by conservatively extending Standard ML with a restricted form of dependent types. This enables the programmer to capture more invariants through types while type-checking remains decidable in theory and can still be performed efficiently in practice. We illustrate our approach through concrete examples and present the result of our preliminary experiments which support support the feasibility and effectiveness of our approach.},
1302+author = {Xi, Hongwei and Pfenning, Frank},
1303+doi = {10.1145/277652.277732},
1304+file = {:Users/edwin/Documents/Mendeley Desktop/Xi, Pfenning/Eliminating array bound checking through dependent types/Xi, Pfenning - Eliminating array bound checking through dependent types - 1998.pdf:pdf},
1305+isbn = {0897919874},
1306+issn = {03621340},
1307+journal = {ACM Sigplan Notices},
1308+keywords = {Dependent Types},
1309+mendeley-tags = {Dependent Types},
1310+number = {5},
1311+pages = {249--257},
1312+publisher = {ACM},
1313+series = {PLDI '98},
1314+title = {{Eliminating array bound checking through dependent types}},
1315+url = {http://portal.acm.org/citation.cfm?doid=277652.277732},
1316+volume = {33},
1317+year = {1998}
10231318}
1024−@inproceedings{taha2004gentle,
1025−author = {Taha, W.},
1026−booktitle = {Domain-Specific Program Generation},
1027−pages = {30--50},
1028−publisher = {Springer},
1029−title = {{A gentle introduction to multi-stage programming}},
1030−url = {http://www.springerlink.com/index/JEMT0D8VYN5JB2L8.pdf},
1031−year = {2004}
1319+@inproceedings{Abel2013,
1320+author = {Abel, Andreas and Pientka, Brigitte and Thibodeau, David and Setzer, Anton},
1321+booktitle = {Principles of Programming Languages},
1322+file = {:Users/edwin/Documents/Mendeley Desktop/Abel et al/Copatterns Programming Infinite Structures by Observations/Abel et al. - Copatterns Programming Infinite Structures by Observations - 2013.pdf:pdf},
1323+isbn = {9781450318327},
1324+keywords = {2008,by the graduiertenkol-,coinduction,elimination,functional programming,introduction,leg programm und modellanalyse,message passing,of the deutsche,pattern matching,puma,thibodeau acknowledges financial support,vs},
1325+title = {{Copatterns: Programming Infinite Structures by Observations}},
1326+year = {2013}
1327+}
1328+@misc{pollack1997believe,
1329+author = {Pollack, R.},
1330+file = {:Users/edwin/Documents/Mendeley Desktop/Pollack/How to believe a machine-checked proof/Pollack - How to believe a machine-checked proof - 1997.pdf:pdf},
1331+title = {{How to believe a machine-checked proof}},
1332+url = {http://books.google.co.uk/books?hl=en&amp;lr=&amp;id=pLnKggT_In4C&amp;oi=fnd&amp;pg=PA205&amp;dq=how+to+believe+a+machine+checked+proof&amp;ots=c2OI8krqqA&amp;sig=EF3QonGFVdOpYdKO1KmW6ljCkjY},
1333+year = {1997}
1334+}
1335+@book{Searching2012,
1336+author = {Sedgewick, Robert and Wayne, Kevin},
1337+booktitle = {The Gerontologist},
1338+doi = {10.1093/geront/gns026},
1339+file = {:Users/edwin/Documents/Mendeley Desktop/Sedgewick, Wayne/Algorithms Chapter 3/Sedgewick, Wayne - Algorithms Chapter 3 - 2012.pdf:pdf},
1340+isbn = {9780132762571},
1341+issn = {1758-5341},
1342+month = dec,
1343+number = {6},
1344+pages = {NP},
1345+pmid = {23150082},
1346+title = {{Algorithms Chapter 3}},
1347+url = {http://www.ncbi.nlm.nih.gov/pubmed/23150082},
1348+volume = {52},
1349+year = {2012}
1350+}
1351+@book{Philosophy2012,
1352+author = {Hunt, Andrew and Thomas, David},
1353+booktitle = {Carcinogenesis},
1354+doi = {10.1093/carcin/bgs054},
1355+file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/The Pragmatic Programmer Chapter 1/Hunt, Thomas - The Pragmatic Programmer Chapter 1 - Unknown.pdf:pdf},
1356+isbn = {020161622X},
1357+issn = {1460-2180},
1358+number = {3},
1359+pmid = {22383472},
1360+title = {{The Pragmatic Programmer Chapter 1}},
1361+url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
1362+volume = {33}
1363+}
1364+@article{Servers,
1365+author = {Totty, Brian and Gourley, David},
1366+file = {:Users/edwin/Documents/Mendeley Desktop/Totty, Gourley/HTTP The Definitive Guide Chapter 5/Totty, Gourley - HTTP The Definitive Guide Chapter 5 - Unknown.pdf:pdf},
1367+isbn = {1565925092},
1368+title = {{HTTP: The Definitive Guide Chapter 5}}
1369+}
1370+@article{Bird2012a,
1371+annote = {This new version of the paper is, I think, very clear and an entertaining read. It presents a neat example of program calculation and reasoning with each step in the calculation explained precisely - indeed the interesting thing to me is the calculation, rather than the problem itself, and it is nice that this works for an algorithm which requires in-place update (even if it does involve pretending // is in-place!).
1372+
1373+
1374+I'm not totally convinced about the condition of the algorithm being "discovered in a disciplined manner" since many of the steps in the calculation required some insight, but others will disagree and I don't think it really matters for the main point of this paper in any case - the point is the calculational development, which is sufficiently detailed that a careful reader should be able to develop that insight, with practice. I would recommend this paper for acceptance in its current form. },
1375+author = {Bird, Richard S},
1376+file = {:Users/edwin/Documents/Mendeley Desktop/Bird/An in-situ algorithm for expanding a graph/Bird - An in-situ algorithm for expanding a graph - 2012.pdf:pdf},
1377+keywords = {a href,journal of functional programming},
1378+title = {{An in-situ algorithm for expanding a graph}},
1379+year = {2012}
10321380}
10331381@inproceedings{Sculthorpe2009,
10341382author = {Sculthorpe, Neil and Nilsson, Henrik},
10351383booktitle = {International Conference on Functional Programming ({ICFP} '09)},
1036−file = {:Users/edwin/Documents/Mendeley Desktop/Sculthorpe, Nilsson/International Conference on Functional Programming ({ICFP} '09)/Sculthorpe, Nilsson - 2009 - Safe functional reactive programming through dependent types.pdf:pdf;:Users/edwin/Documents/Mendeley Desktop/Sculthorpe, Nilsson/International Conference on Functional Programming ({ICFP} '09)/Sculthorpe, Nilsson - 2009 - Safe functional reactive programming through dependent types(2).pdf:pdf},
1384+file = {:Users/edwin/Documents/Mendeley Desktop/Sculthorpe, Nilsson/Safe functional reactive programming through dependent types/Sculthorpe, Nilsson - Safe functional reactive programming through dependent types - 2009.pdf:pdf;:Users/edwin/Documents/Mendeley Desktop/Sculthorpe, Nilsson/Safe functional reactive programming through dependent types/Sculthorpe, Nilsson - Safe functional reactive programming through dependent types - 2009(2).pdf:pdf},
10371385title = {{Safe functional reactive programming through dependent types}},
10381386url = {http://dl.acm.org/citation.cfm?id=1596558},
10391387year = {2009}
10401388}
1389+@article{landin1966next,
1390+author = {Landin, P.J.},
1391+file = {:Users/edwin/Documents/Mendeley Desktop/Landin/The next 700 programming languages/Landin - The next 700 programming languages - 1966.pdf:pdf},
1392+journal = {Communications of the ACM},
1393+number = {3},
1394+pages = {157--166},
1395+publisher = {ACM},
1396+title = {{The next 700 programming languages}},
1397+url = {http://dl.acm.org/citation.cfm?id=365257 )},
1398+volume = {9},
1399+year = {1966}
1400+}
1401+@inproceedings{Delahaye2000,
1402+author = {Delahaye, D},
1403+booktitle = {Logic for Programming and Automated Reasoning},
1404+file = {:Users/edwin/Documents/Mendeley Desktop/Delahaye/A tactic language for the system Coq/Delahaye - A tactic language for the system Coq - 2000.pdf:pdf;:Users/edwin/Documents/Mendeley Desktop/Delahaye/A tactic language for the system Coq/Delahaye - A tactic language for the system Coq - 2000(2).pdf:pdf},
1405+pages = {85----95},
1406+publisher = {Springer},
1407+title = {{A tactic language for the system Coq}},
1408+url = {http://www.springerlink.com/index/EFQAH8J88K42VN8T.pdf},
1409+year = {2000}
1410+}
1411+@book{Messages,
1412+author = {Totty, Brian and Gourley, David},
1413+file = {:Users/edwin/Documents/Mendeley Desktop/Totty, Gourley/HTTP The Definitive Guide Chapter 3/Totty, Gourley - HTTP The Definitive Guide Chapter 3 - Unknown.pdf:pdf},
1414+isbn = {1565925092},
1415+title = {{HTTP: The Definitive Guide Chapter 3}}
1416+}
1417+@article{Asperti,
1418+author = {Asperti, Andrea and Ricciotti, Wilmer and Coen, Claudio Sacerdoti and Tassi, Enrico},
1419+doi = {10.2168/LMCS-},
1420+file = {:Users/edwin/Documents/Mendeley Desktop/Asperti et al/A bi-directional refinement algorithm for the calculus of (co)inductive constructions/Asperti et al. - A bi-directional refinement algorithm for the calculus of (co)inductive constructions - 2012.pdf:pdf},
1421+journal = {Logical Methods in Computer Science},
1422+keywords = {and phrases,calculus of inductive construc-,interactive theorem prover,refiner,type inference},
1423+pages = {1----49},
1424+title = {{A bi-directional refinement algorithm for the calculus of (co)inductive constructions}},
1425+volume = {8},
1426+year = {2012}
1427+}
1428+@inproceedings{Altenkirch2010,
1429+abstract = {The recent success of languages like Agda and Coq demonstrates the potential of using dependent types for programming. These systems rely on many high-level features like datatype definitions, pattern matching and implicit arguments to facilitate the use of the languages. However, these features complicate the metatheoretical study and are a potential source of bugs. To address these issues we introduce $\Pi$$\Sigma$, a dependently typed core language. It is small enough for metatheoretical study and the type checker is small enough to be formally verified. In this language there is only one mechanism for recursionused for types, functions and infinite objectsand an explicit mechanism to control unfolding, based on lifted types. Furthermore structural equality is used consistently for values and types; this is achieved by a new notion of $\alpha$-equality for recursive definitions. We show, by translating several high-level constructions, that $\Pi$$\Sigma$ is suitable as a core language for dependently typed programming.},
1430+author = {Altenkirch, Thorsten and Danielsson, Nils Anders and L\"{o}h, Andres and Oury, Nicolas},
1431+booktitle = {{FLOPS 2010}},
1432+doi = {10.1007/978-3-642-12251-4_5},
1433+editor = {Blume, Matthias and Kobayashi, Naoki and Vidal, Germ\'{a}n},
1434+file = {:Users/edwin/Documents/Mendeley Desktop/Altenkirch et al/Dependent Types without the Sugar/Altenkirch et al. - Dependent Types without the Sugar - 2010.pdf:pdf},
1435+isbn = {9783642122507},
1436+pages = {40----55},
1437+publisher = {Springer Berlin Heidelberg},
1438+series = {Lecture Notes in Computer Science},
1439+title = {{Dependent Types without the Sugar}},
1440+url = {http://www.springerlink.com/index/91W712G2806R575H.pdf},
1441+year = {2010}
1442+}
1443+@misc{Gobi2010,
1444+author = {Gobi, Attila and Shkaravska, Olha and {Van Eekelen}, Marko},
1445+booktitle = {Syntax},
1446+file = {:Users/edwin/Documents/Mendeley Desktop/Gobi, Shkaravska, Van Eekelen/Higher-Order Size Checking Without Subtyping/Gobi, Shkaravska, Van Eekelen - Higher-Order Size Checking Without Subtyping - 2010.pdf:pdf},
1447+number = {100039},
1448+title = {{Higher-Order Size Checking Without Subtyping}},
1449+year = {2010}
1450+}
1451+@book{Context2012,
1452+author = {Sedgewick, Robert and Wayne, Kevin},
1453+booktitle = {The Gerontologist},
1454+doi = {10.1093/geront/gns026},
1455+file = {:Users/edwin/Documents/Mendeley Desktop/Sedgewick, Wayne/Algorithms Chapter 6/Sedgewick, Wayne - Algorithms Chapter 6 - 2012.pdf:pdf},
1456+isbn = {9780132762571},
1457+issn = {1758-5341},
1458+month = dec,
1459+number = {6},
1460+pages = {NP},
1461+pmid = {23150082},
1462+title = {{Algorithms Chapter 6}},
1463+url = {http://www.ncbi.nlm.nih.gov/pubmed/23150082},
1464+volume = {52},
1465+year = {2012}
1466+}
1467+@misc{Protocols2012a,
1468+author = {Anderson, Ross},
1469+doi = {10.1093/epirev/mxr031},
1470+file = {:Users/edwin/Documents/Mendeley Desktop/Anderson/Security Engineering Chapter 3/Anderson - Security Engineering Chapter 3 - Unknown.pdf:pdf},
1471+isbn = {9780470068526},
1472+issn = {1478-6729},
1473+pmid = {22215642},
1474+title = {{Security Engineering Chapter 3}}
1475+}
1476+@inproceedings{Visser2008,
1477+author = {Visser, E},
1478+booktitle = {Generative and Transformational Techniques in Software Engineering},
1479+title = {{WebDSL: A case study in domain-specific language engineering}},
1480+url = {http://www.springerlink.com/index/A3213003X6268032.pdf},
1481+year = {2008}
1482+}
1483+@inproceedings{gibbons2011modularising,
1484+author = {Gibbons, J. and Ko, H.S. and Others},
1485+file = {:Users/edwin/Documents/Mendeley Desktop/Ko, Gibbons/Modularising inductive families/Ko, Gibbons - Modularising inductive families - 2011.pdf:pdf},
1486+title = {{Modularising inductive families}},
1487+url = {http://www.cs.ox.ac.uk/publications/publication5008-abstract.html},
1488+year = {2011}
1489+}
1490+@book{Synchronization2012,
1491+author = {Butenhof, David R.},
1492+booktitle = {Nicotine & tobacco research : official journal of the Society for Research on Nicotine and Tobacco},
1493+doi = {10.1093/ntr/nts035},
1494+file = {:Users/edwin/Documents/Mendeley Desktop/Butenhof/Programming with POSIX Threads Chapter 3/Butenhof - Programming with POSIX Threads Chapter 3 - Unknown.pdf:pdf},
1495+isbn = {0201633922},
1496+issn = {1469-994X},
1497+number = {10},
1498+pmid = {23012339},
1499+title = {{Programming with POSIX Threads Chapter 3}},
1500+url = {http://www.ncbi.nlm.nih.gov/pubmed/23012339},
1501+volume = {14}
1502+}
1503+@article{Pl,
1504+annote = {-2, 3
1505+
1506+
1507+This paper gives a type inference algorithm for Java extended with lambdas, extending earlier work on type inference for a small functional language with subtyping. It is interesting to see how this could work, and I'm sure this would be a welcome addition to Java. However, I didn't find the paper very well organised or presented so it was difficult to get very much from it. There is too much unnecessary detail (such as fragments of the parser or complete sets of coercions and substitutions) and not enough useful context such as syntax of Java_lambda with its typing rules.
1508+
1509+
1510+If there is an implementation, it would also be good to give a url to download it so that the reader can try out some of the ideas given in the paper, and try to reproduce your results!
1511+
1512+
1513+Other comments:
1514+
1515+
1516+p1 The opening sentences don't seem to make sense on their own. It would be useful to know what your language in [7] is.
1517+
1518+
1519+There are several typos which suggest that the paper could use a proof read and spell check. For example:
1520+p2 "The improvement is that, that" => remove a "that"
1521+"not necessary" => "not necessarily"
1522+"can also consists" => "can also consist"
1523+"remainig" => "remaining"
1524+
1525+
1526+p3 What does "The concrete syntax [...] is oriented at [3]" mean? Is the syntax defined in this reference? It would be better to give it explicitly to make the paper more self contained.
1527+
1528+
1529+p4 Is there some reason that you use tuples in the representation of classes, functions and expressions?
1530+
1531+
1532+p9 "Decomposition: ..." I don't understand this sentence.
1533+
1534+
1535+p10 "corecions" => "coercions" (several times)
1536+also "coersions" => "coercions"
1537+
1538+
1539+p14 (and other places similarly) I don't think it helps much to give the full set of substitutions here. A representative selection at most should be fine.
1540+
1541+
1542+
1543+ },
1544+author = {Pl\"{u}micke, Martin},
1545+file = {:Users/edwin/Documents/Mendeley Desktop/Pl{u}micke/Functional implementation of well-typings in/Pl{u}micke - Functional implementation of well-typings in - Unknown.pdf:pdf},
1546+title = {{Functional implementation of well-typings in}}
1547+}
1548+@article{gordon2003authenticity,
1549+author = {Gordon, A.D. and Jeffrey, A.},
1550+file = {:Users/edwin/Documents/Mendeley Desktop/Gordon, Jeffrey/Authenticity by typing for security protocols/Gordon, Jeffrey - Authenticity by typing for security protocols - 2003.pdf:pdf},
1551+journal = {Journal of computer security},
1552+number = {4},
1553+pages = {451--520},
1554+publisher = {IOS Press},
1555+title = {{Authenticity by typing for security protocols}},
1556+url = {http://iospress.metapress.com/index/BHQQUFRA1C7W8TLY.pdf},
1557+volume = {11},
1558+year = {2003}
1559+}
1560+@book{Approach2012,
1561+author = {Hunt, Andrew and Thomas, David},
1562+booktitle = {Carcinogenesis},
1563+doi = {10.1093/carcin/bgs054},
1564+file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/The Pragmatic Programmer Chapter 2/Hunt, Thomas - The Pragmatic Programmer Chapter 2 - Unknown.pdf:pdf},
1565+isbn = {020161622X},
1566+issn = {1460-2180},
1567+number = {3},
1568+pmid = {22383472},
1569+title = {{The Pragmatic Programmer Chapter 2}},
1570+url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
1571+volume = {33}
1572+}
1573+@inproceedings{barras2008implicit,
1574+author = {Barras, B. and Bernardo, B.},
1575+booktitle = {Foundations of Software Science and Computational Structures},
1576+file = {:Users/edwin/Documents/Mendeley Desktop/Barras, Bernardo/The implicit calculus of constructions as a programming language with dependent types/Barras, Bernardo - The implicit calculus of constructions as a programming language with dependent types - 2008.pdf:pdf},
1577+pages = {365--379},
1578+publisher = {Springer},
1579+title = {{The implicit calculus of constructions as a programming language with dependent types}},
1580+url = {http://www.springerlink.com/index/m84h82904546l265.pdf},
1581+year = {2008}
1582+}
1583+@article{Zanasi,
1584+author = {Zanasi, Fabio},
1585+file = {:Users/edwin/Documents/Mendeley Desktop/Zanasi/On the Expressive Power of MSO and WMSO on Trees of Arbitrary Degree ( Extended abstract )/Zanasi - On the Expressive Power of MSO and WMSO on Trees of Arbitrary Degree ( Extended abstract ) - Unknown.pdf:pdf},
1586+pages = {1--6},
1587+title = {{On the Expressive Power of MSO and WMSO on Trees of Arbitrary Degree ( Extended abstract )}}
1588+}
1589+@article{Thiemann,
1590+annote = {1, 4
1591+
1592+
1593+This paper is a case study in dependently typed programming, investigating how an existing Haskell library (Accelerate) could benefit from dependent types by implementing a version of the library in Agda. The Haskell version is a generative library, meaning that programs are constructed as Haskell ADTs, then compiled to code which will run on a GPU. The authos observe that type correctness of Accelerate programs is checked statically, as far as possible, by using advanced features of the Haskell type system such as GADTs, and hypothesise that a language with a stronger type system such as Agda would increase the static guarantees which are expressible.
1594+
1595+
1596+This is an interesting question, well worth asking, and the paper presents mixed results. The presentation of the Agda version is clear, and the relationship with the Haskell version is easy to see. However, some properties which one might hope to express turn out to be difficult in the current form. One conclusion I would draw from this is that to use dependent types well involves more than simply annotating an existing program. The difficulties with filter and fold in particular show that care must be taken to preserve information required for checking later.
1597+
1598+
1599+I wonder if the work has become too constrained by porting directly from the Haskell implementation. Perhaps a question to ask in future work would be - what would a dependently typed API to GPUs look like? What properties do we want to capture, and how can we do so with minimal work for the programmer?
1600+
1601+
1602+Nevertheless, I enjoyed reading the paper and I think this is a good first step towards data parallel programming with dependent types.
1603+
1604+
1605+Minor comments:
1606+
1607+
1608+p3 Given that proceedings are in black and white, maybe it'd be more distinctive to put the Haskell code in a box rather than just a vertical bar?
1609+
1610+
1611+p8 It would be useful to see the type of the zipWith function which corresponds to the Haskell version, if not the implementation (which I suspect is a little tricky).
1612+
1613+
1614+p9 Probably not relevant to this paper, but this comment about properties of floating point arithmetic makes me wonder if it'd be possible to represent floating point error bounds in the type to recover these properties.
1615+
1616+
1617+p10 Another alternative for the type of filter could be a type level function to calculate the length. However, this would probably make proofs even harder. I think this is evidence that dependently typed programming is more than Haskell plus extra type annotations!
1618+
1619+
1620+p14 "We have build" => "We have built"},
1621+author = {Thiemann, Peter and Chakravarty, Manuel M T},
1622+file = {:Users/edwin/Documents/Mendeley Desktop/Thiemann, Chakravarty/Agda Meets Accelerate/Thiemann, Chakravarty - Agda Meets Accelerate - Unknown.pdf:pdf},
1623+keywords = {data parallelism,programming with dependent types},
1624+pages = {1--16},
1625+title = {{Agda Meets Accelerate}}
1626+}
1627+@inproceedings{atkey2009unembedding,
1628+author = {Atkey, R. and Lindley, S. and Yallop, J.},
1629+booktitle = {Proceedings of the 2nd ACM SIGPLAN symposium on Haskell},
1630+pages = {37--48},
1631+publisher = {ACM},
1632+title = {{Unembedding domain-specific languages}},
1633+url = {http://dl.acm.org/citation.cfm?id=1596644},
1634+year = {2009}
1635+}
1636+@inproceedings{ko2011modularising,
1637+author = {Ko, H.S. and Gibbons, J.},
1638+booktitle = {Proceedings of the seventh ACM SIGPLAN workshop on Generic programming},
1639+file = {:Users/edwin/Documents/Mendeley Desktop/Ko, Gibbons/Modularising inductive families/Ko, Gibbons - Modularising inductive families - 2011.pdf:pdf},
1640+pages = {13--24},
1641+publisher = {ACM},
1642+title = {{Modularising inductive families}},
1643+url = {http://www.cs.ox.ac.uk/publications/publication5008-abstract.html http://dl.acm.org/citation.cfm?id=2036921},
1644+year = {2011}
1645+}
1646+@article{Chapman2005epigram,
1647+author = {Chapman, James and Altenkirch, Thorsten and McBride, Conor},
1648+file = {:Users/edwin/Documents/Mendeley Desktop/Chapman, Altenkirch, McBride/Epigram Reloaded A Standalone Typechecker for {ETT}/Chapman, Altenkirch, McBride - Epigram Reloaded A Standalone Typechecker for {ETT} - 2005.pdf:pdf},
1649+journal = {Trends in Functional Programming},
1650+publisher = {Intellect Books},
1651+title = {{Epigram Reloaded: A Standalone Typechecker for {ETT}}},
1652+url = {http://books.google.co.uk/books?hl=en&amp;lr=&amp;id=p0yV1sHLubcC&amp;oi=fnd&amp;pg=PA79&amp;dq=epigram+reloaded&amp;ots=x50ou0VMsm&amp;sig=7TjAGohIatNLTWsHcuNcK5hEGGY},
1653+year = {2005}
1654+}
1655+@article{Hutton,
1656+author = {Hutton, Graham and Fulger, Diana},
1657+file = {:Users/edwin/Documents/Mendeley Desktop/Hutton, Fulger/Reasoning About Effects Seeing the Wood Through the Trees/Hutton, Fulger - Reasoning About Effects Seeing the Wood Through the Trees - Unknown.pdf:pdf},
1658+title = {{Reasoning About Effects : Seeing the Wood Through the Trees}}
1659+}
1660+@article{dybjer1994inductive,
1661+author = {Dybjer, P.},
1662+journal = {Formal aspects of computing},
1663+number = {4},
1664+pages = {440--465},
1665+publisher = {Springer},
1666+title = {{Inductive families}},
1667+url = {http://www.springerlink.com/index/J17824H467X6J288.pdf},
1668+volume = {6},
1669+year = {1994}
1670+}
10411671@misc{TheMendeleySupportTeam2011a,
10421672abstract = {A quick introduction to Mendeley. Learn how Mendeley creates your personal digital library, how to organize and annotate documents, how to collaborate and share with colleagues, and how to generate citations and bibliographies.},
10431673address = {London},
10441674author = {{The Mendeley Support Team}},
10451675booktitle = {Mendeley Desktop},
1046−file = {:Users/edwin/Documents/Mendeley Desktop/The Mendeley Support Team/Mendeley Desktop/The Mendeley Support Team - 2011 - Getting Started with Mendeley.pdf:pdf},
1676+file = {:Users/edwin/Documents/Mendeley Desktop/The Mendeley Support Team/Getting Started with Mendeley/The Mendeley Support Team - Getting Started with Mendeley - 2011.pdf:pdf},
10471677keywords = {Mendeley,how-to,user manual},
10481678pages = {1--16},
10491679publisher = {Mendeley Ltd.},
@@ -1051,35 +1681,21 @@ title = {{Getting Started with Mendeley}},
10511681url = {http://www.mendeley.com},
10521682year = {2011}
10531683}
1054−@article{danielsson2011parsing,
1055−author = {Danielsson, N. and Norell, U.},
1056−journal = {Implementation and Application of Functional Languages},
1057−pages = {80--99},
1058−publisher = {Springer},
1059−title = {{Parsing mixfix operators}},
1060−url = {http://www.springerlink.com/index/386243257W504252.pdf},
1061−year = {2011}
1062−}
1063−@misc{dagand2011transporting,
1064−author = {Dagand, Pierre-Evariste and McBride, Conor},
1065−file = {:Users/edwin/Documents/Mendeley Desktop/Dagand, McBride/Unknown/Dagand, McBride - 2011 - Transporting Functions across Ornaments.pdf:pdf},
1066−title = {{Transporting Functions across Ornaments}},
1067−url = {http://personal.cis.strath.ac.uk/$\sim$dagand/stuffs/paper-2011-patch/paper.pdf},
1068−year = {2011}
1069−}
1070−@book{Fowler,
1071−author = {Fowler, Martin},
1072−booktitle = {Language},
1073−file = {:Users/edwin/Documents/Mendeley Desktop/Fowler/Language/Fowler - Unknown - Domain Specific Languages Chapter 2.pdf:pdf},
1074−isbn = {9780132107549},
1075−title = {{Domain Specific Languages Chapter 2}}
1684+@misc{Brady2012b,
1685+author = {Brooks, Fred},
1686+doi = {10.1093/epirev/mxr031},
1687+file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/The Design of Design Chapter 2/Brooks - The Design of Design Chapter 2 - Unknown.pdf:pdf},
1688+isbn = {9780321702081},
1689+issn = {1478-6729},
1690+pmid = {22215642},
1691+title = {{The Design of Design Chapter 2}}
10761692}
10771693@misc{Bove2008,
10781694abstract = {In these lecture notes we give an introduction to functional programming with dependent types. We use the dependently typed programming language Agda which is based on ideas in Martin-L\"{o}f type theory and Martin-L\"{o}fs logical framework. We begin by showing how to do simply typed functional programming, and discuss the differences between Agdas type system and the Hindley-Milner type system, which underlies mainstream typed functional programming languages like Haskell and ML. We then show how to employ dependent types for programming with functional data structures such as vectors and binary search trees. We go on to explain the Curry-Howard identification of propositions and types, and how it makes Agda not only a programming language but also a programming logic. According to Curry-Howard, we also identify programs and proofs, something which is possible only by requiring that all program terminate. However, we show in the final section a method for encoding general and possibly partial recursive functions as total functions using dependent types.},
10791695author = {Bove, Ana and Dybjer, Peter},
10801696booktitle = {Notes},
10811697doi = {10.1007/978-3-642-03153-3_2},
1082−file = {:Users/edwin/Documents/Mendeley Desktop/Bove, Dybjer/Notes/Bove, Dybjer - 2008 - Dependent Types at Work.pdf:pdf},
1698+file = {:Users/edwin/Documents/Mendeley Desktop/Bove, Dybjer/Dependent Types at Work/Bove, Dybjer - Dependent Types at Work - 2008.pdf:pdf},
10831699number = {February},
10841700pages = {57--99},
10851701publisher = {Springer},
@@ -1088,111 +1704,375 @@ url = {http://www.springerlink.com/index/1039q8qk71257677.pdf},
10881704volume = {5520},
10891705year = {2008}
10901706}
1091−@article{Okasaki1993,
1092−author = {Okasaki, Chris},
1093−file = {:Users/edwin/Documents/Mendeley Desktop/Okasaki/Journal of functional programming/Okasaki - 1993 - Red-Black Trees in A Functional Setting.pdf:pdf},
1094−journal = {Journal of functional programming},
1095−title = {{Red-Black Trees in A Functional Setting}},
1096−year = {1993}
1707+@article{In2012,
1708+author = {Gulhati, Ashish},
1709+doi = {10.1093/geront/gns026},
1710+file = {:Users/edwin/Documents/Mendeley Desktop/Gulhati/Beautiful Code Chapter 11/Gulhati - Beautiful Code Chapter 11 - 2012.pdf:pdf},
1711+isbn = {9780596510046},
1712+issn = {1758-5341},
1713+month = dec,
1714+number = {6},
1715+pages = {NP},
1716+pmid = {23150082},
1717+title = {{Beautiful Code Chapter 11}},
1718+url = {http://www.ncbi.nlm.nih.gov/pubmed/23150082},
1719+volume = {52},
1720+year = {2012}
10971721}
1098−@inproceedings{pj2006gadts,
1099−author = {{Peyton Jones}, S. and Vytiniotis, D. and Weirich, S. and Washburn, G.},
1100−booktitle = {{International Conference on Functional Programming} ({ICFP} '06)},
1101−file = {:Users/edwin/Documents/Mendeley Desktop/Peyton Jones et al/{International Conference on Functional Programming} ({ICFP} '06)/Peyton Jones et al. - 2006 - Simple unification-based type inference for GADTs.pdf:pdf},
1102−number = {9},
1103−pages = {50--61},
1722+@article{McBride2002,
1723+author = {McBride, C},
1724+file = {:Users/edwin/Documents/Mendeley Desktop/McBride/Elimination with a Motive/McBride - Elimination with a Motive - 2000.pdf:pdf},
1725+journal = {Types for proofs and programs ({TYPES 2000})},
1726+title = {{Elimination with a Motive}},
1727+url = {http://www.springerlink.com/index/vbpg19305t46f6dm.pdf},
1728+year = {2000}
1729+}
1730+@inproceedings{lempsink2009type,
1731+author = {Lempsink, E. and Leather, S. and L\"{o}h, A.},
1732+booktitle = {Proceedings of the 2009 ACM SIGPLAN workshop on Generic programming},
1733+file = {:Users/edwin/Documents/Mendeley Desktop/Lempsink, Leather, L\"{o}h/Type-safe diff for families of datatypes/Lempsink, Leather, L\"{o}h - Type-safe diff for families of datatypes - 2009.pdf:pdf},
1734+pages = {61--72},
11041735publisher = {ACM},
1105−title = {{Simple unification-based type inference for GADTs}},
1106−url = {http://dl.acm.org/citation.cfm?id=1159811},
1107−volume = {41},
1108−year = {2006}
1736+title = {{Type-safe diff for families of datatypes}},
1737+url = {http://dl.acm.org/citation.cfm?id=1596624},
1738+year = {2009}
1739+}
1740+@inproceedings{Brady2011a,
1741+address = {New York, New York, USA},
1742+author = {Brady, Edwin},
1743+booktitle = {Proceedings of the 5th {ACM} workshop on Programming languages meets program verification - {PLPV} '11},
1744+doi = {10.1145/1929529.1929536},
1745+file = {:Users/edwin/Documents/Mendeley Desktop/Brady/Idris --- Systems Programming Meets Full Dependent Types/Brady - Idris --- Systems Programming Meets Full Dependent Types - 2011.pdf:pdf},
1746+isbn = {9781450304870},
1747+keywords = {Dependent Types,data description,dependent types},
1748+mendeley-tags = {Dependent Types},
1749+month = jan,
1750+publisher = {ACM Press},
1751+title = {{Idris --- Systems Programming Meets Full Dependent Types}},
1752+url = {http://dl.acm.org/citation.cfm?id=1929529.1929536},
1753+year = {2011}
11091754}
11101755@misc{altenkirch2005dependent,
11111756author = {Altenkirch, T. and McBride, C. and McKinna, J.},
11121757booktitle = {Manuscript, available online},
1113−file = {:Users/edwin/Documents/Mendeley Desktop/Altenkirch, McBride, McKinna/Manuscript, available online/Altenkirch, McBride, McKinna - 2005 - Why dependent types matter.pdf:pdf},
1758+file = {:Users/edwin/Documents/Mendeley Desktop/Altenkirch, McBride, McKinna/Why dependent types matter/Altenkirch, McBride, McKinna - Why dependent types matter - 2005.pdf:pdf},
11141759title = {{Why dependent types matter}},
11151760url = {http://www.cs.nott.ac.uk/$\sim$txa/talks/splst11.pdf},
11161761year = {2005}
11171762}
1118−@misc{The2012c,
1119−author = {Robbins, A and Hannah, E and Lamb, L},
1763+@misc{Nodes2012a,
1764+author = {Brooks, Fred},
11201765doi = {10.1093/epirev/mxr031},
1121−file = {:Users/edwin/Documents/Mendeley Desktop/Robbins, Hannah, Lamb/Unknown/Robbins, Hannah, Lamb - Unknown - Learning the vi and Vim Editors.pdf:pdf},
1122−isbn = {9780596529833},
1766+file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/The Design of Design Chapter 3/Brooks - The Design of Design Chapter 3 - Unknown.pdf:pdf},
1767+isbn = {9780321702081},
11231768issn = {1478-6729},
11241769pmid = {22215642},
1125−title = {{Learning the vi and Vim Editors}}
1770+title = {{The Design of Design Chapter 3}}
11261771}
1127−@misc{Resolution2012a,
1128−author = {Fall, Kevin R and Stevens, W. Richard},
1129−doi = {10.1093/epirev/mxr031},
1130−file = {:Users/edwin/Documents/Mendeley Desktop/Fall, Stevens/Unknown/Fall, Stevens - Unknown - TCPIP Illustrated Volume 1 Chapter 11.pdf:pdf},
1131−issn = {1478-6729},
1132−pmid = {22215642},
1133−title = {{TCP/IP Illustrated Volume 1 Chapter 11}}
1772+@article{danielsson2011parsing,
1773+author = {Danielsson, N. and Norell, U.},
1774+journal = {Implementation and Application of Functional Languages},
1775+pages = {80--99},
1776+publisher = {Springer},
1777+title = {{Parsing mixfix operators}},
1778+url = {http://www.springerlink.com/index/386243257W504252.pdf},
1779+year = {2011}
11341780}
1135−@article{Brady2006a,
1136−author = {Brady, E and Hammond, K},
1137−file = {:Users/edwin/Documents/Mendeley Desktop/Brady, Hammond/\ldots of the 5th international conference on \ldots/Brady, Hammond - 2006 - A verified staged interpreter is a verified compiler.pdf:pdf},
1138−journal = {\ldots of the 5th international conference on \ldots},
1139−keywords = {Dependent Types},
1140−mendeley-tags = {Dependent Types},
1141−title = {{A verified staged interpreter is a verified compiler}},
1142−url = {http://portal.acm.org/citation.cfm?id=1173706.1173724},
1143−year = {2006}
1781+@book{Bird2010,
1782+author = {Bird, Richard},
1783+file = {:Users/edwin/Documents/Mendeley Desktop/Bird/Pearls of Functional Algorithm Design/Bird - Pearls of Functional Algorithm Design - 2010.pdf:pdf},
1784+isbn = {9780521513388},
1785+title = {{Pearls of Functional Algorithm Design}},
1786+year = {2010}
11441787}
1145−@inproceedings{swierstra2007beauty,
1146−author = {Swierstra, W. and Altenkirch, T.},
1147−booktitle = {Proceedings of the ACM SIGPLAN workshop on Haskell workshop},
1148−file = {:Users/edwin/Documents/Mendeley Desktop/Swierstra, Altenkirch/Proceedings of the ACM SIGPLAN workshop on Haskell workshop/Swierstra, Altenkirch - 2007 - Beauty in the beast.pdf:pdf},
1149−pages = {25--36},
1788+@article{Jones1999,
1789+abstract = {Haskell benefits from a sophisticated type system, but implementors, programmers, and researchers suffer because it has no formal description. To remedy this shortcoming, we present a Haskell program that implements a Haskell typechecker, thus providing a mathematically rigorous specification in a notation that is familiar to Haskell users. We expect this program to fill a serious gap in current descriptions of Haskell, both as a starting point for discussions about existing features of the type system, and as a platform from which to explore new proposals.},
1790+author = {Jones, Mark P},
1791+file = {:Users/edwin/Documents/Mendeley Desktop/Jones/Typing Haskell in Haskell/Jones - Typing Haskell in Haskell - 1999.pdf:pdf},
1792+journal = {October},
1793+publisher = {Citeseer},
1794+title = {{Typing Haskell in Haskell}},
1795+url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.134.7274&amp;rep=rep1&amp;type=pdf},
1796+year = {1999}
1797+}
1798+@book{Security2012,
1799+author = {Pfleeger, Charles P and Pfleeger, S. L.},
1800+booktitle = {Nicotine & tobacco research : official journal of the Society for Research on Nicotine and Tobacco},
1801+doi = {10.1093/ntr/nts035},
1802+file = {:Users/edwin/Documents/Mendeley Desktop/Pfleeger, Pfleeger/Security in Computing Chapter 3/Pfleeger, Pfleeger - Security in Computing Chapter 3 - 2012.pdf:pdf},
1803+isbn = {0132390779},
1804+issn = {1469-994X},
1805+month = oct,
1806+number = {10},
1807+pages = {NP},
1808+pmid = {23012339},
1809+title = {{Security in Computing Chapter 3}},
1810+url = {http://www.ncbi.nlm.nih.gov/pubmed/23012339},
1811+volume = {14},
1812+year = {2012}
1813+}
1814+@article{Steiner1988,
1815+author = {Steiner, JG},
1816+file = {:Users/edwin/Documents/Mendeley Desktop/Steiner/Kerberos An authentication service for open network systems/Steiner - Kerberos An authentication service for open network systems - 1988.pdf:pdf},
1817+journal = {Proc. Winter USENIX Conference},
1818+title = {{Kerberos: An authentication service for open network systems}},
1819+url = {http://www.cse.nd.edu/$\sim$dthain/courses/cse598z/fall2004/papers/kerberos.pdf},
1820+year = {1988}
1821+}
1822+@inproceedings{stump2010resource,
1823+author = {Stump, A. and Austin, E.},
1824+booktitle = {Proceedings of the 4th ACM SIGPLAN workshop on Programming languages meets program verification},
1825+file = {:Users/edwin/Documents/Mendeley Desktop/Stump, Austin/Resource typing in Guru/Stump, Austin - Resource typing in Guru - 2010.pdf:pdf},
1826+pages = {27--38},
11501827publisher = {ACM},
1151−title = {{Beauty in the beast}},
1152−url = {http://dl.acm.org/citation.cfm?id=1291206},
1153−year = {2007}
1828+title = {{Resource typing in Guru}},
1829+url = {http://dl.acm.org/citation.cfm?id=1707796},
1830+year = {2010}
11541831}
1155−@article{McBride2004a,
1156−abstract = {ABSTRACT Pattern matching has proved an extremely powerful and durable notion in functional programming. This paper contributes a new programming notation for type theory which elaborates the notion in various ways. First, as is by now quite well-known in the type theory community, definition by pattern matching becomes a more discriminating tool in the presence of dependent types, since it refines the explanation of types as well as values. This becomes all the more true in the presence of the rich class of datatypes known as inductive families (Dybjer, 1991). Secondly, as proposed by Peyton Jones (1997) for Haskell, and independently rediscovered by us, subsidiary case analyses on the results of intermediate computations, which commonly take place on the right-hand side of definitions by pattern matching, should rather be handled on the left. In simply-typed languages, this subsumes the trivial case of Boolean guards; in our setting it becomes yet more powerful. Thirdly, elementary pattern matching decompositions have a well-defined interface given by a dependent type; they correspond to the statement of an induction principle for the datatype. More general, user-definable decompositions may be defined which also have types of the same general form. Elementary pattern matching may therefore be recast in abstract form, with a semantics given by translation. Such abstract decompositions of data generalize Wadler&apos;s (1987) notion of &lsquo;view&rsquo;. The programmer wishing to introduce a new view of a type mathitT, and exploit it directly in pattern matching, may do so via a standard programming idiom. The type theorist, looking through the Curry&ndash;Howard lens, may see this as proving a theorem, one which establishes the validity of a new induction principle for mathitT. We develop enough syntax and semantics to account for this high-level style of programming in dependent type theory. We close with the development of a typechecker for the simply-typed lambda calculus, which furnishes a view of raw terms as either being well-typed, or containing an error. The implementation of this view is ipso facto a proof that typechecking is decidable.},
1157−author = {McBride, Conor and McKinna, James},
1158−doi = {10.1017/S0956796803004829},
1159−file = {:Users/edwin/Documents/Mendeley Desktop/McBride, McKinna/Journal of Functional Programming/McBride, McKinna - 2004 - The view from the left.pdf:pdf},
1160−issn = {09567968},
1832+@article{fisher2006next,
1833+author = {Fisher, K. and Mandelbaum, Y. and Walker, D.},
1834+file = {:Users/edwin/Documents/Mendeley Desktop/Fisher, Mandelbaum, Walker/The next 700 data description languages/Fisher, Mandelbaum, Walker - The next 700 data description languages - 2010.pdf:pdf},
1835+journal = {Journal of the ACM},
1836+number = {2},
1837+pages = {1--51},
1838+publisher = {ACM},
1839+title = {{The next 700 data description languages}},
1840+url = {http://dl.acm.org/citation.cfm?id=1111039},
1841+volume = {15},
1842+year = {2010}
1843+}
1844+@inproceedings{brady2011epic,
1845+author = {Brady, Edwin},
1846+booktitle = {Trends in Functional Programming ({TFP}’11)},
1847+file = {:Users/edwin/Documents/Mendeley Desktop/Brady/Epic --- A Library for Generating Compilers/Brady - Epic --- A Library for Generating Compilers - 2011.pdf:pdf},
1848+title = {{Epic --- A Library for Generating Compilers}},
1849+url = {http://scholar.google.co.uk/scholar?cites=2588300990390214449&as_sdt=2005&sciodt=0,5&hl=en#1},
1850+year = {2011}
1851+}
1852+@inproceedings{Brady2006b,
1853+author = {Brady, Edwin},
1854+booktitle = {Implementation and Application of Functional Languages ({IFL}'06)},
1855+file = {:Users/edwin/Documents/Mendeley Desktop/Brady/Ivor, a proof engine/Brady - Ivor, a proof engine - 2006.pdf:pdf},
1856+isbn = {978-3-540-74129-9},
1857+month = sep,
1858+pages = {145----162},
1859+title = {{Ivor, a proof engine}},
1860+url = {http://dl.acm.org/citation.cfm?id=1757028.1757037},
1861+year = {2006}
1862+}
1863+@article{Reynolds1972,
1864+abstract = {Higher-order programming languages (i.e., languages in which procedures or labels can occur as values) are usually defined by interpreters which are themselves written in a programming language based on the lambda calculus (i.e., an applicative language such as pure LISP). Examples include McCarthy's definition of LISP, Landin's SECD machine, the Vienna definition of PL/I, Reynolds' definitions of GEDANKEN, and recent unpublished work by L. Morris and C. Wadsworth. Such definitions can be classified according to whether the interpreter contains higher-order functions, and whether the order of application (i.e., call-by-value versus call-by-name) in the defined language depends upon the order of application in the defining language. As an example, we consider the definition of a simple applicative programming language by means of an interpreter written in a similar language. Definitions in each of the above classifications are derived from one another by informal but constructive methods. The treatment of imperative features such as jumps and assignment is also discussed.},
1865+author = {Reynolds, John C},
1866+file = {:Users/edwin/Documents/Mendeley Desktop/Reynolds/Definitional interpreters for higher-order programming languages/Reynolds - Definitional interpreters for higher-order programming languages - 1972.pdf:pdf},
1867+journal = {Proceedings of the ACM annual conference on ACM 72},
1868+keywords = {applicative language,closure,continuation,gedanken,higher order function,interpreter,j operator,lambda calculus,language definition,lisp,order application,pal,programming language,reference,secd machine},
1869+number = {30602},
1870+pages = {717--740},
1871+publisher = {ACM Press},
1872+title = {{Definitional interpreters for higher-order programming languages}},
1873+volume = {2},
1874+year = {1972}
1875+}
1876+@book{Hunt,
1877+author = {Hunt, Andrew and Thomas, David},
1878+booktitle = {Design},
1879+file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/The Pragmatic Programmer Chapter 4/Hunt, Thomas - The Pragmatic Programmer Chapter 4 - Unknown.pdf:pdf},
1880+isbn = {020161622X},
1881+title = {{The Pragmatic Programmer Chapter 4}}
1882+}
1883+@article{Epstein2011,
1884+author = {Epstein, Jeff and Black, Andrew P and Peyton-jones, Simon},
1885+institution = {Microsoft Research},
1886+journal = {researchmicrosoftcom},
1887+number = {Section 8},
1888+pages = {1--12},
1889+title = {{Haskell for the cloud}},
1890+url = {http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/remote.pdf},
1891+year = {2011}
1892+}
1893+@book{Bertot2004,
1894+author = {Bertot, Yves and Cast\'{e}ran, Pierre},
1895+publisher = {Springer},
1896+title = {{Interactive theorem proving and program development: {Coq'Art}: the {Calculus of Inductive Constructions}}},
1897+url = {http://books.google.co.uk/books?hl=en&amp;lr=&amp;id=m5w5PRj5Nj4C&amp;oi=fnd&amp;pg=PA1&amp;dq=coq+theorem+prover&amp;ots=VHny1IYV0h&amp;sig=-K0FC67cdkhMDkAocFla8cZyRT4},
1898+year = {2004}
1899+}
1900+@article{Swierstra2011,
1901+author = {Swierstra, W},
1902+file = {:Users/edwin/Documents/Mendeley Desktop/Swierstra/Sorted Verifying the Problem of the {Dutch National} Flag in {Agda}/Swierstra - Sorted Verifying the Problem of the {Dutch National} Flag in {Agda} - 2011.pdf:pdf},
11611903journal = {Journal of Functional Programming},
1904+number = {6},
1905+pages = {575----583},
1906+title = {{Sorted: Verifying the Problem of the {Dutch National} Flag in {Agda}}},
1907+url = {http://journals.cambridge.org/abstract_S0956796811000207},
1908+volume = {21},
1909+year = {2011}
1910+}
1911+@misc{Casinghino2012,
1912+author = {Casinghino, Chris and Sj\"{o}berg, Vilhelm and Weirich, Stephanie},
1913+file = {:Users/edwin/Documents/Mendeley Desktop/Casinghino, Sj{o}berg, Weirich/Combining Proofs and Programs in a Dependently Typed Language/Casinghino, Sj{o}berg, Weirich - Combining Proofs and Programs in a Dependently Typed Language - 2012.pdf:pdf},
1914+keywords = {dependent types,general recursion,termination},
1915+pages = {1--12},
1916+title = {{Combining Proofs and Programs in a Dependently Typed Language}},
1917+year = {2012}
1918+}
1919+@article{Huet1997,
1920+author = {Huet, G},
1921+file = {:Users/edwin/Documents/Mendeley Desktop/Huet/The zipper/Huet - The zipper - 1997.pdf:pdf},
1922+journal = {{Journal of Functional Programming}},
1923+number = {5},
1924+pages = {549----554},
1925+title = {{The zipper}},
1926+url = {http://journals.cambridge.org/abstract_S0956796897002864},
1927+volume = {7},
1928+year = {1997}
1929+}
1930+@inproceedings{bradyresource,
1931+author = {Brady, Edwin and Hammond, Kevin},
1932+booktitle = {Practical Applications of Declarative Languages ({PADL} 2012)},
1933+file = {:Users/edwin/Documents/Mendeley Desktop/Brady, Hammond/Resource-safe Systems Programming with Embedded Domain Specific Languages/Brady, Hammond - Resource-safe Systems Programming with Embedded Domain Specific Languages - 2012.pdf:pdf},
1934+pages = {242----257},
1935+title = {{Resource-safe Systems Programming with Embedded Domain Specific Languages}},
1936+url = {http://www.cs.st-andrews.ac.uk/$\sim$eb/drafts/dsl-idris.pdf},
1937+year = {2012}
1938+}
1939+@book{Management,
1940+author = {Totty, Brian and Gourley, David},
1941+file = {:Users/edwin/Documents/Mendeley Desktop/Totty, Gourley/HTTP The Definitive Guide Chapter 4/Totty, Gourley - HTTP The Definitive Guide Chapter 4 - Unknown.pdf:pdf},
1942+isbn = {1565925092},
1943+title = {{HTTP: The Definitive Guide Chapter 4}}
1944+}
1945+@phdthesis{Brady2005,
1946+author = {Brady, Edwin},
1947+file = {:Users/edwin/Documents/Mendeley Desktop/Brady/Practical Implementation of a Dependently Typed Functional Programming Language/Brady - Practical Implementation of a Dependently Typed Functional Programming Language - 2005.pdf:pdf},
11621948keywords = {Dependent Types},
11631949mendeley-tags = {Dependent Types},
1164−number = {1},
1165−pages = {69--111},
1166−publisher = {Cambridge University Press},
1167−title = {{The view from the left}},
1168−url = {http://www.journals.cambridge.org/abstract_S0956796803004829},
1169−volume = {14},
1170−year = {2004}
1950+school = {University of Durham},
1951+title = {{Practical Implementation of a Dependently Typed Functional Programming Language}},
1952+year = {2005}
1953+}
1954+@article{Lee2001,
1955+author = {Lee, Chin Soon and Jones, Neil D. and Ben-Amram, Amir M.},
1956+doi = {10.1145/373243.360210},
1957+file = {:Users/edwin/Documents/Mendeley Desktop/Lee, Jones, Ben-Amram/The size-change principle for program termination/Lee, Jones, Ben-Amram - The size-change principle for program termination - 2001.pdf:pdf},
1958+isbn = {1-58113-336-7},
1959+issn = {03621340},
1960+journal = {ACM SIGPLAN Notices},
1961+keywords = {PSPACE-completeness,omega automaton,partial evaluation,program analysis,termination},
1962+month = mar,
1963+number = {3},
1964+pages = {81--92},
1965+title = {{The size-change principle for program termination}},
1966+url = {http://dl.acm.org/citation.cfm?id=373243.360210},
1967+volume = {36},
1968+year = {2001}
1969+}
1970+@misc{Bloat,
1971+author = {Brooks, Fred},
1972+file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/The Design of Design Chapter 4/Brooks - The Design of Design Chapter 4 - Unknown.pdf:pdf},
1973+isbn = {9780321702081},
1974+title = {{The Design of Design Chapter 4}}
1975+}
1976+@misc{Caldwell,
1977+author = {Caldwell, James and Roan, Ryan},
1978+file = {:Users/edwin/Documents/Mendeley Desktop/Caldwell, Roan/Type Checking SQL for Secure Database Access/Caldwell, Roan - Type Checking SQL for Secure Database Access - Unknown.pdf:pdf},
1979+title = {{Type Checking SQL for Secure Database Access}}
11711980}
1172−@misc{Nodes2012a,
1173−author = {Brooks, Fred},
1981+@inproceedings{Peterson1993,
1982+address = {New York, New York, USA},
1983+author = {Peterson, John and Jones, Mark},
1984+booktitle = {Proceedings of the ACM SIGPLAN 1993 conference on Programming Language Design and Implementation - PLDI '93},
1985+doi = {10.1145/155090.155112},
1986+file = {:Users/edwin/Documents/Mendeley Desktop/Peterson, Jones/Implementing type classes/Peterson, Jones - Implementing type classes - 1993.pdf:pdf},
1987+isbn = {0897915984},
1988+issn = {0362-1340},
1989+month = aug,
1990+number = {6},
1991+pages = {227--236},
1992+publisher = {ACM Press},
1993+title = {{Implementing type classes}},
1994+url = {http://dl.acm.org/citation.cfm?id=155090.155112},
1995+volume = {28},
1996+year = {1993}
1997+}
1998+@misc{Attacks2012a,
1999+author = {Anderson, Ross},
11742000doi = {10.1093/epirev/mxr031},
1175−file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/Unknown/Brooks - Unknown - The Design of Design Chapter 3.pdf:pdf},
1176−isbn = {9780321702081},
2001+file = {:Users/edwin/Documents/Mendeley Desktop/Anderson/Security Engineering Chapter 18/Anderson - Security Engineering Chapter 18 - Unknown.pdf:pdf},
2002+isbn = {9780470068526},
11772003issn = {1478-6729},
2004+number = {1},
2005+pages = {NP},
11782006pmid = {22215642},
1179−title = {{The Design of Design Chapter 3}}
2007+title = {{Security Engineering Chapter 18}},
2008+volume = {34}
11802009}
1181−@inproceedings{Hancock2000,
1182−author = {Hancock, Peter and Setzer, Anton},
1183−booktitle = {{Proceedings of the 14th Annual Conference of the EACSL on Computer Science Logic}},
1184−file = {:Users/edwin/Documents/Mendeley Desktop/Hancock, Setzer/{Proceedings of the 14th Annual Conference of the EACSL on Computer Science Logic}/Hancock, Setzer - 2000 - Interactive Programs in Dependent Type Theory.pdf:pdf},
1185−isbn = {3-540-67895-6},
1186−month = aug,
1187−pages = {317--331},
1188−title = {{Interactive Programs in Dependent Type Theory}},
1189−url = {http://dl.acm.org/citation.cfm?id=647850.737221},
1190−year = {2000}
2010+@inproceedings{bhargavan2010modular,
2011+author = {Bhargavan, K. and Fournet, C. and Gordon, A.D.},
2012+booktitle = {ACM Sigplan Notices},
2013+number = {1},
2014+pages = {445--456},
2015+publisher = {ACM},
2016+title = {{Modular verification of security protocol code by typing}},
2017+url = {http://dl.acm.org/citation.cfm?id=1707801.1706350},
2018+volume = {45},
2019+year = {2010}
2020+}
2021+@article{Hoare1978,
2022+abstract = {This paper suggests that input and output are basic primitives of programming and that parallel composition of communicating sequential processes is a fundamental program structuring method. When combined with a development of Dijkstra's guarded command, these concepts are surprisingly versatile. Their use is illustrated by sample solutions of a variety of a familiar programming exercises.},
2023+author = {Hoare, C A R},
2024+doi = {10.1016/0167-6423(87)90028-1},
2025+editor = {McKeag, R M and Macnaghten, A M},
2026+file = {:Users/edwin/Documents/Mendeley Desktop/Hoare/Communicating sequential processes/Hoare - Communicating sequential processes - 1978.pdf:pdf},
2027+isbn = {0131532715},
2028+issn = {01676423},
2029+journal = {Communications of the ACM},
2030+number = {8},
2031+pages = {666--677},
2032+pmid = {2142694823583477576},
2033+publisher = {ACM},
2034+series = {International Series in Computer Science},
2035+title = {{Communicating sequential processes}},
2036+url = {http://linkinghub.elsevier.com/retrieve/pii/0167642387900281},
2037+volume = {21},
2038+year = {1978}
2039+}
2040+@article{Overview,
2041+author = {Totty, Brian and Gourley, David},
2042+file = {:Users/edwin/Documents/Mendeley Desktop/Totty, Gourley/HTTP The Definitive Guide Chapter 1/Totty, Gourley - HTTP The Definitive Guide Chapter 1 - Unknown.pdf:pdf},
2043+isbn = {1565925092},
2044+title = {{HTTP: The Definitive Guide Chapter 1}}
2045+}
2046+@inproceedings{Sozeau2008,
2047+author = {Sozeau, Matthieu and Oury, Nicolas},
2048+booktitle = {Theorem Proving in Higher Order Logics ({TPHOLs 2008})},
2049+file = {:Users/edwin/Documents/Mendeley Desktop/Sozeau, Oury/First-Class Type Classes/Sozeau, Oury - First-Class Type Classes - 2008.pdf:pdf},
2050+pages = {278----293},
2051+title = {{First-Class Type Classes}},
2052+year = {2008}
2053+}
2054+@book{Fogel,
2055+author = {Fogel, Karl},
2056+file = {:Users/edwin/Documents/Mendeley Desktop/Fogel/Producing Open Source Software How to Run a Successful Free Software Project/Fogel - Producing Open Source Software How to Run a Successful Free Software Project - Unknown.pdf:pdf},
2057+title = {{Producing Open Source Software: How to Run a Successful Free Software Project}}
2058+}
2059+@book{Brady2012,
2060+author = {Hunt, Andrew and Thomas, David},
2061+booktitle = {Carcinogenesis},
2062+doi = {10.1093/carcin/bgs054},
2063+file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/The Pragmatic Programmer Chapter 5/Hunt, Thomas - The Pragmatic Programmer Chapter 5 - Unknown.pdf:pdf},
2064+isbn = {020161622X},
2065+issn = {1460-2180},
2066+number = {3},
2067+pmid = {22383472},
2068+title = {{The Pragmatic Programmer Chapter 5}},
2069+url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
2070+volume = {33}
11912071}
11922072@inproceedings{augustsson2008paradise,
11932073author = {Augustsson, L. and Mansell, H. and Sittampalam, G.},
11942074booktitle = {International Conference on Functional Programming},
1195−file = {:Users/edwin/Documents/Mendeley Desktop/Augustsson, Mansell, Sittampalam/International Conference on Functional Programming/Augustsson, Mansell, Sittampalam - 2008 - Paradise a two-stage DSL embedded in Haskell.pdf:pdf},
2075+file = {:Users/edwin/Documents/Mendeley Desktop/Augustsson, Mansell, Sittampalam/Paradise a two-stage DSL embedded in Haskell/Augustsson, Mansell, Sittampalam - Paradise a two-stage DSL embedded in Haskell - 2008.pdf:pdf},
11962076number = {9},
11972077pages = {225--228},
11982078publisher = {ACM},
@@ -1201,61 +2081,185 @@ url = {http://dl.acm.org/citation.cfm?id=1411203.1411236},
12012081volume = {43},
12022082year = {2008}
12032083}
1204−@misc{Abel1998,
1205−author = {Abel, Andreas},
1206−booktitle = {Language},
1207−file = {:Users/edwin/Documents/Mendeley Desktop/Abel/Language/Abel - 1998 - foetus - Termination Checker for Simple Functional Programs.pdf:pdf},
1208−title = {{foetus - Termination Checker for Simple Functional Programs}},
1209−year = {1998}
2084+@article{marlow2006making,
2085+author = {Marlow, S. and {Peyton Jones}, S.},
2086+file = {:Users/edwin/Documents/Mendeley Desktop/Marlow, Peyton Jones/Making a fast curry pushenter vs. evalapply for higher-order languages/Marlow, Peyton Jones - Making a fast curry pushenter vs. evalapply for higher-order languages - 2006.pdf:pdf},
2087+journal = {Journal of Functional Programming},
2088+number = {4-5},
2089+pages = {415--449},
2090+publisher = {Cambridge University Press},
2091+title = {{Making a fast curry: push/enter vs. eval/apply for higher-order languages}},
2092+url = {http://dl.acm.org/citation.cfm?id=1166018},
2093+volume = {16},
2094+year = {2006}
12102095}
1211−@article{Jones1999,
1212−abstract = {Haskell benefits from a sophisticated type system, but implementors, programmers, and researchers suffer because it has no formal description. To remedy this shortcoming, we present a Haskell program that implements a Haskell typechecker, thus providing a mathematically rigorous specification in a notation that is familiar to Haskell users. We expect this program to fill a serious gap in current descriptions of Haskell, both as a starting point for discussions about existing features of the type system, and as a platform from which to explore new proposals.},
1213−author = {Jones, Mark P},
1214−journal = {October},
1215−publisher = {Citeseer},
1216−title = {{Typing Haskell in Haskell}},
1217−url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.134.7274&amp;rep=rep1&amp;type=pdf},
2096+@misc{TheMendeleySupportTeam2011b,
2097+abstract = {A quick introduction to Mendeley. Learn how Mendeley creates your personal digital library, how to organize and annotate documents, how to collaborate and share with colleagues, and how to generate citations and bibliographies.},
2098+address = {London},
2099+author = {{The Mendeley Support Team}},
2100+booktitle = {Mendeley Desktop},
2101+file = {:Users/edwin/Documents/Mendeley Desktop/The Mendeley Support Team/Getting Started with Mendeley/The Mendeley Support Team - Getting Started with Mendeley - 2011.pdf:pdf},
2102+keywords = {Mendeley,how-to,user manual},
2103+pages = {1--16},
2104+publisher = {Mendeley Ltd.},
2105+title = {{Getting Started with Mendeley}},
2106+url = {http://www.mendeley.com},
2107+year = {2011}
2108+}
2109+@inproceedings{ko2011modularising,
2110+author = {Ko, H.S. and Gibbons, J.},
2111+booktitle = {Proceedings of the seventh ACM SIGPLAN workshop on Generic programming},
2112+pages = {13--24},
2113+publisher = {ACM},
2114+title = {{Modularising inductive families}},
2115+url = {http://dl.acm.org/citation.cfm?id=2036921},
2116+year = {2011}
2117+}
2118+@book{Fry1985,
2119+author = {Abelson, Harold and Sussman, Gerald and Sussman, Julie},
2120+booktitle = {Computer Music Journal},
2121+doi = {10.2307/3679579},
2122+file = {:Users/edwin/Documents/Mendeley Desktop/Abelson, Sussman, Sussman/Structure and Interpretation of Computer Programs/Abelson, Sussman, Sussman - Structure and Interpretation of Computer Programs - 1985.pdf:pdf},
2123+isbn = {0262011530},
2124+issn = {01489267},
2125+month = jan,
2126+number = {3},
2127+title = {{Structure and Interpretation of Computer Programs}},
2128+url = {http://www.jstor.org/stable/3679579?origin=crossref},
2129+volume = {9},
2130+year = {1985}
2131+}
2132+@article{Bird2012,
2133+annote = {I enjoyed reading this pearl. It describes, clearly and concisely, the calculation of a program for changing the way of representing a graph in response to a challenge of Donald Knuth's, who asked whether such an algorithm could be discovered in a "disciplined manner". The paper describes that disciplined manner.
2134+
2135+
2136+
2137+
2138+In general, I found the paper easy to follow. Section 2 sets up the problem, giving a purely functional representation of graphs and the definitions of some basic, important functions, in particular encode and decode. Section 3 gives a first example of program calculation, assuming the existence of a function 'lengthen' corresponding to 'shorten' and deriving an implementation from its required properties. Later, we see a definition using arrays rather than lists in order to improve the complexity to linear time. Section 4 addresses a condition Knuth imposes, namely that update must be in place and gives an imperative translation.
2139+
2140+
2141+I think this paper gives a nice example of program calculation leading from a functional specification to an imperative program. I do have a few suggestions though which I think would improve the paper:
2142+
2143+
2144+In the introduction, you say there is a reason why the code cannot be purely functional, but I don't see an explicit explanation of why this is. In place update perhaps? Can this be clarified?
2145+
2146+
2147+The equation numbering, e.g. (1) at the bottom of p1 - some equations are clearly important and referred to elsewhere, such as this one. Is it possible to make these stand out more? e.g. with an explicit heading "Equation 1"?
2148+
2149+
2150+p3 In the first examples of program calculation, it is easy to follow the reasoning of why the calculation is correct, but it is not so obvious what the insight was that led to the calculation. Is this simply a matter of experience?
2151+
2152+
2153+p6 I'm surprised to read that // updates an array in place. Is this really what is happening or is there a clever representation of Data.Array.Diff? It appears to use IO operations internally. So it might be nice to say a little more about what is really going on.
2154+
2155+
2156+p7 "...an observation that could have been made earlier" seems an odd thing to say. Why not either make it earlier, or just make it here where it is used?
2157+
2158+
2159+p9 There is no need to give the translation rules to the imperative code in detail, but it would still be useful to sketch what is going on. It seems that the foldr becomes the outer for loop, and apply the inner for loop. It would also be useful, in Figs 1-4 to give the functional code alongside the imperative versions. It is interesting to examine how the mapping works and I think an important point made by the paper (as indeed you say in the conclusion).
2160+
2161+
2162+p14 The last paragraph appears to be largely a comment to the present referees!
2163+
2164+ },
2165+author = {Bird, Richard S},
2166+file = {:Users/edwin/Documents/Mendeley Desktop/Bird/An in-situ algorithm for expanding a graph/Bird - An in-situ algorithm for expanding a graph - 2012(2).pdf:pdf},
2167+journal = {Journal of Functional Programming},
2168+keywords = {a href,journal of functional programming},
2169+title = {{An in-situ algorithm for expanding a graph}},
2170+year = {2012}
2171+}
2172+@article{Ahn,
2173+annote = {-1,5
2174+
2175+
2176+The paper describes Nax, a new functional programming language with term indices which supports logical consistency and Hindley-Milner style type inference. The authors give four key features of Nax (1: strong normalization, 2: type inference, 3: expressivity and 4: support for term indices) and give several examples to demonstrate the simplicity of programming in Nax as compared with Haskell and Agda. Three examples are given, in each language: a type preserving evaluator for an expression language, a generic Path datatype which describes a path through an index type, and a stack safe compiler for the expression language.
2177+
2178+
2179+Presenting examples in this way gives a nice introduction to Nax, in that they are well understood examples already and it is easy to relate them to implementations with which the reader is already familiar. On the other hand, this leads to my main problem with this paper: it doesn't really tell us anything we don't already know, and the promising things about Nax which *would* be an interesting contribution are left out of the paper.
2180+
2181+
2182+Of the four features of Nax given above, 1 and 2 are described as "beyond the scope of this paper" which is a shame because these are the things I'm most interested in hearing about! Existing dependently typed languages lack type inference, and whlie I would argue that it is usually best to write types first in any case, there are still many situations where recovering type inference would be useful - typically small or simply typed helper functions. So this would have been a very nice technical contribution.
2183+
2184+
2185+The third feature (expressivity) is one that the authors claim as a contribution of the paper. They claim that programming in Nax is as "simple" as programming in Haskell or Agda. However, I think this is a strong claim to make given the available evidence - it is quite subjective. I agree that the programs are quite easy to read, but to say that *programming* is as simple really requires some externally verified evidence from other programmers! It seems to me that programming with Mendler-style combinators may take some practice, for example.
2186+
2187+
2188+In summary, I do like the idea behind Nax and some of its features sound as if they could be interesting, and I think this latest contribution to the design space of dependently typed functional programming is welcome. But this paper does not really provide any new insights as it stands.
2189+
2190+
2191+Minor comments:
2192+
2193+
2194+Fig 1,2 and 3 - I'm not sure I would like the rotation of these in print (it's pretty awkward on screen too).},
2195+author = {Ahn, Ki Yung and Sheard, Tim and Fiore, Marcelo and Pitts, Andrew M},
2196+file = {:Users/edwin/Documents/Mendeley Desktop/Ahn et al/Programming with Term-Indexed Types in Nax/Ahn et al. - Programming with Term-Indexed Types in Nax - Unknown.pdf:pdf},
2197+keywords = {gadts,indexed datatypes,lightweight dependent types,term-indexed types,universe polymorphism,universe subtyping},
2198+title = {{Programming with Term-Indexed Types in Nax}}
2199+}
2200+@article{Morrisett1999,
2201+author = {Morrisett, G and Walker, D},
2202+file = {:Users/edwin/Documents/Mendeley Desktop/Morrisett, Walker/From System F to typed assembly language/Morrisett, Walker - From System F to typed assembly language - 1999.pdf:pdf},
2203+journal = {ACM Transactions on \ldots},
2204+title = {{From System F to typed assembly language}},
2205+url = {http://dl.acm.org/citation.cfm?id=319345},
12182206year = {1999}
12192207}
1220−@inproceedings{morris2006exploring,
1221−author = {Morris, P. and Altenkirch, T. and McBride, C.},
1222−booktitle = {Types for Proofs and Programs},
1223−file = {:Users/edwin/Documents/Mendeley Desktop/Morris, Altenkirch, McBride/Types for Proofs and Programs/Morris, Altenkirch, McBride - 2006 - Exploring the regular tree types.pdf:pdf},
1224−pages = {252--267},
1225−publisher = {Springer},
1226−title = {{Exploring the regular tree types}},
1227−url = {http://www.springerlink.com/index/f9p1317716614834.pdf},
1228−year = {2006}
2208+@article{Altenkirch2010a,
2209+abstract = {We begin by revisiting the idea of using a universe of types to write generic programs in a dependently typed setting by constructing a universe for Strictly Positive Types (SPTs). Here we extend this construction to cover dependent types, i.e. Strictly Positive Families (SPFs), thereby fixing a gap left open in previous work. Using the approach presented here we are able to represent all of Epigrams datatypes within Epigram including the universe of datatypes itself.},
2210+author = {Altenkirch, Thorsten and Mcbride, Conor and Morris, Peter},
2211+file = {:Users/edwin/Documents/Mendeley Desktop/Altenkirch, Mcbride, Morris/Generic Programming with Dependent Types/Altenkirch, Mcbride, Morris - Generic Programming with Dependent Types - 2010.pdf:pdf},
2212+journal = {Citeseer},
2213+publisher = {Citeseer},
2214+title = {{Generic Programming with Dependent Types}},
2215+url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.129.2926&amp;rep=rep1&amp;type=pdf},
2216+year = {2010}
12292217}
1230−@inproceedings{Sheard2005,
1231−address = {New York, New York, USA},
1232−author = {Sheard, Tim},
1233−booktitle = {Proceedings of the 2005 ACM SIGPLAN workshop on Haskell - Haskell '05},
1234−doi = {10.1145/1088348.1088356},
1235−file = {:Users/edwin/Documents/Mendeley Desktop/Sheard/Proceedings of the 2005 ACM SIGPLAN workshop on Haskell - Haskell '05/Sheard - 2005 - Putting curry-howard to work.pdf:pdf},
1236−isbn = {159593071X},
1237−keywords = {GADT,curry-howard isomorphism,extensional kind system,haskell,logic},
1238−month = sep,
1239−pages = {74--85},
1240−publisher = {ACM Press},
1241−title = {{Putting curry-howard to work}},
1242−url = {http://dl.acm.org/citation.cfm?id=1088348.1088356},
1243−year = {2005}
2218+@book{Edition2012a,
2219+author = {Pfleeger, Charles P and Pfleeger, S. L.},
2220+booktitle = {Nicotine & tobacco research : official journal of the Society for Research on Nicotine and Tobacco},
2221+doi = {10.1093/ntr/nts035},
2222+file = {:Users/edwin/Documents/Mendeley Desktop/Pfleeger, Pfleeger/Security in Computer Chapter 12/Pfleeger, Pfleeger - Security in Computer Chapter 12 - 2012.pdf:pdf},
2223+isbn = {0132390779},
2224+issn = {1469-994X},
2225+month = oct,
2226+number = {10},
2227+pages = {NP},
2228+pmid = {23012339},
2229+title = {{Security in Computer Chapter 12}},
2230+url = {http://www.ncbi.nlm.nih.gov/pubmed/23012339},
2231+volume = {14},
2232+year = {2012}
12442233}
1245−@misc{Interface2012a,
1246−author = {Kreibich, Jay A.},
1247−doi = {10.1093/epirev/mxr031},
1248−file = {:Users/edwin/Documents/Mendeley Desktop/Kreibich/Unknown/Kreibich - Unknown - Using SQLite Chapter 7.pdf:pdf},
1249−isbn = {9781449394592},
1250−issn = {1478-6729},
1251−pmid = {22215642},
1252−title = {{Using SQLite Chapter 7}}
2234+@book{Pierce2004,
2235+author = {Pierce, Benjamin},
2236+editor = {Pierce, Benjamin},
2237+file = {:Users/edwin/Documents/Mendeley Desktop/Pierce/Advanced topics in types and programming languages/Pierce - Advanced topics in types and programming languages - 2004.pdf:pdf},
2238+publisher = {MIT Press},
2239+title = {{Advanced topics in types and programming languages}},
2240+year = {2004}
2241+}
2242+@inproceedings{taha1997multi,
2243+author = {Taha, W. and Sheard, T.},
2244+booktitle = {ACM SIGPLAN Notices},
2245+number = {12},
2246+pages = {203--217},
2247+publisher = {ACM},
2248+title = {{Multi-stage programming with explicit annotations}},
2249+url = {http://dl.acm.org/citation.cfm?id=259019},
2250+volume = {32},
2251+year = {1997}
2252+}
2253+@misc{Lorenzen,
2254+author = {Lorenzen, Florian},
2255+file = {:Users/edwin/Documents/Mendeley Desktop/Lorenzen/A Statically Typed Functional Language With Programmable Binders/Lorenzen - A Statically Typed Functional Language With Programmable Binders - Unknown.pdf:pdf},
2256+title = {{A Statically Typed Functional Language With Programmable Binders}}
12532257}
12542258@book{The2012,
12552259author = {Hunt, Andrew and Thomas, David},
12562260booktitle = {Carcinogenesis},
12572261doi = {10.1093/carcin/bgs054},
1258−file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/Carcinogenesis/Hunt, Thomas - Unknown - The Pragmatic Programmer Chapter 3.pdf:pdf},
2262+file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/The Pragmatic Programmer Chapter 3/Hunt, Thomas - The Pragmatic Programmer Chapter 3 - Unknown.pdf:pdf},
12592263isbn = {020161622X},
12602264issn = {1460-2180},
12612265number = {3},
@@ -1264,68 +2268,18 @@ title = {{The Pragmatic Programmer Chapter 3}},
12642268url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
12652269volume = {33}
12662270}
1267−@misc{Brady2012b,
1268−author = {Brooks, Fred},
1269−doi = {10.1093/epirev/mxr031},
1270−file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/Unknown/Brooks - Unknown - The Design of Design Chapter 2.pdf:pdf},
1271−isbn = {9780321702081},
1272−issn = {1478-6729},
1273−pmid = {22215642},
1274−title = {{The Design of Design Chapter 2}}
1275−}
1276−@inproceedings{Levitation2010,
1277−author = {Chapman, James and Dagand, Pierre-Evariste and McBride, Conor and Morris, Peter},
1278−booktitle = {{15th ACM SIGPLAN International Conference on Functional programming (ICFP '10)}},
1279−doi = {10.1145/1932681.1863547},
1280−file = {:Users/edwin/Documents/Mendeley Desktop/Chapman et al/{15th ACM SIGPLAN International Conference on Functional programming (ICFP '10)}/Chapman et al. - 2010 - The gentle art of levitation.pdf:pdf},
1281−isbn = {978-1-60558-794-3},
1282−issn = {03621340},
1283−keywords = {Dependent Types,data structure,metaprogramming,monads,proof assistants,type systems},
1284−mendeley-tags = {Dependent Types},
1285−month = sep,
1286−number = {9},
1287−title = {{The gentle art of levitation}},
1288−url = {http://dl.acm.org/citation.cfm?id=1932681.1863547},
1289−volume = {45},
1290−year = {2010}
1291−}
1292−@inproceedings{Xi1999,
1293−abstract = {Note: OCR errors may be found in this Reference List extracted from the full text article. ACM has opted to expose the complete List rather than only correct and linked references.},
1294−author = {Xi, Hongwei and Pfenning, Frank},
1295−booktitle = {Proceedings of the 26th ACM SIGPLANSIGACT symposium on Principles of programming languages POPL 99},
1296−doi = {10.1145/292540.292560},
1297−file = {:Users/edwin/Documents/Mendeley Desktop/Xi, Pfenning/Proceedings of the 26th ACM SIGPLANSIGACT symposium on Principles of programming languages POPL 99/Xi, Pfenning - 1999 - Dependent types in practical programming.pdf:pdf},
1298−isbn = {1581130953},
1299−issn = {07439016},
1300−keywords = {Dependent Types},
1301−mendeley-tags = {Dependent Types},
1302−organization = {Carnegie Mellon University},
1303−pages = {214--227},
1304−publisher = {ACM Press},
1305−series = {POPL '99},
1306−title = {{Dependent types in practical programming}},
1307−url = {http://portal.acm.org/citation.cfm?doid=292540.292560},
1308−volume = {26},
1309−year = {1999}
1310−}
1311−@inproceedings{Brady2003,
1312−author = {Brady, Edwin and McBride, Conor and McKinna, James},
1313−booktitle = {Types for Proofs and Programs {(TYPES 2003)}},
1314−file = {:Users/edwin/Documents/Mendeley Desktop/Brady, McBride, McKinna/Types for Proofs and Programs {(TYPES 2003)}/Brady, McBride, McKinna - 2003 - Inductive families need not store their indices.pdf:pdf},
1315−keywords = {Dependent Types},
1316−mendeley-tags = {Dependent Types},
1317−title = {{Inductive families need not store their indices}},
1318−url = {http://www.springerlink.com/index/WBXJJG717N2W3NU2.pdf},
1319−year = {2003}
2271+@inproceedings{pollack1990implicit,
2272+author = {Pollack, R.},
2273+booktitle = {{Informal Proceedings of First Workshop on Logical Frameworks, Antibes}},
2274+file = {:Users/edwin/Documents/Mendeley Desktop/Pollack/Implicit syntax/Pollack - Implicit syntax - 1990.pdf:pdf},
2275+publisher = {Citeseer},
2276+title = {{Implicit syntax}},
2277+url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.30.7361&amp;rep=rep1&amp;type=pdf},
2278+year = {1990}
13202279}
1321−@inproceedings{fisher2005pads,
1322−author = {Fisher, K. and Gruber, R.},
1323−booktitle = {ACM SIGPLAN Notices},
1324−number = {6},
1325−pages = {295--304},
1326−publisher = {ACM},
1327−title = {{PADS: a domain-specific language for processing ad hoc data}},
1328−url = {http://dl.acm.org/citation.cfm?id=1065046},
1329−volume = {40},
1330−year = {2005}
2280+@article{Bradya,
2281+author = {Hunt, Andrew and Thomas, David},
2282+file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/The Pragmatic Programmer Chapter 7/Hunt, Thomas - The Pragmatic Programmer Chapter 7 - Unknown.pdf:pdf},
2283+isbn = {020161622X},
2284+title = {{The Pragmatic Programmer Chapter 7}}
13312285}
papers/impl-paper/macros.ltx+4−4
@@ -261,7 +261,7 @@
261261\newcommand{\MHRet}[2]{\multicolumn{#1}{l}{\hq #2}}
262262\newcommand{\IRet}[1]{\multicolumn{2}{l}{\iq #1}}
263263\newcommand{\IMRet}[2]{\multicolumn{#1}{l}{\iq #2}}
264−\newcommand{\MoRet}[1]{\multicolumn{2}{l}{\mq #1}}
264+\newcommand{\MoRet}[1]{\multicolumn{2}{l}{= #1}}
265265\newcommand{\MMoRet}[2]{\multicolumn{#1}{l}{\mq #2}}
266266\newcommand{\Data}{\RW{data}}
267267\newcommand{\Codata}{\RW{codata}}
@@ -391,7 +391,7 @@ Program & Version & Instructions & Thunks & Memory Accesses & Cells \\
391391
392392%%%%%%%%%%%% TYPE
393393
394−\newcommand{\Type}{\mbox{\texttt{Set}}} %\star}
394+\newcommand{\Type}{\mbox{\texttt{Type}}} %\star}
395395
396396
397397%%%%%%%%%%%%% ARROWS
@@ -430,7 +430,7 @@ Program & Version & Instructions & Thunks & Memory Accesses & Cells \\
430430\newcommand{\pq}{\pad{\:}{=}}
431431\newcommand{\dq}{\pad{\:}{:=}}
432432\newcommand{\iq}{\pad{\:}{\leadsto}}
433−\newcommand{\mq}{\Longrightarrow}
433+\newcommand{\mq}{=} %\Longrightarrow}
434434\newcommand{\retq}{\Rightarrow}
435435\newcommand{\hq}{\pad{\:}{=}}
436436\newcommand{\defq}{\mapsto}
@@ -559,7 +559,7 @@ Program & Version & Instructions & Thunks & Memory Accesses & Cells \\
559559\newcommand{\VectRebuild}{\FN{vectRebuild}}
560560
561561\newcommand{\Prop}{\TC{Prop}}
562−\newcommand{\Set}{\TC{Set}}
562+\newcommand{\Set}{\TC{Type}}
563563\newcommand{\CoqType}{\TC{Type}}
564564
565565\newcommand{\List}{\TC{List}}
papers/impl-paper/typechecking.tex+273−210
@@ -28,7 +28,7 @@ type of types, and may be extended with other primitives.
2828
2929The function space $\all{\vx}{\vS}\SC\vT$ may also be written as $(\vx\Hab\vS)\to\vT$,
3030or $\vS\to\vT$ if $\vx$ is not free in $\vT$, to make the notation more consistent with
31−the high level language. Universe levels on sets ($\Type_i$) may be left implicit and
31+the high level language. Universe levels on types ($\Type_i$) may be left implicit and
3232inferred by the machine~\cite{pollack1990implicit}.
3333
3434\FFIG{
@@ -37,9 +37,9 @@ inferred by the machine~\cite{pollack1990implicit}.
3737\hg\vb ::= & \lam{\vx}{\vt} & (\mbox{abstraction}) \\
3838
3939 \mid & \vx & (\mbox{variable}) &
40− \mid & \LET\:\vx\defq\vt\Hab\vt & (\mbox{let binding}) \\
40+ \mid & \LET\;\vx\defq\vt\Hab\vt & (\mbox{let binding}) \\
4141
42− \mid & \vb\SC\:\vt & (\mbox{binding}) &
42+ \mid & \vb\SC\;\vt & (\mbox{binding}) &
4343 \mid & \all{\vx}{\vt} & (\mbox{function space}) \\
4444
4545 \mid & \vt\;\vt & (\mbox{application}) &
@@ -73,8 +73,14 @@ $\LET$ binding:
7373\DM{
7474\Axiom{\proves\RW{valid}}
7575\hg
76−\Rule{\Gamma\proves\RW{valid}}
77−{\Gamma;\vb\proves\RW{valid}}
76+\Rule{\Gamma\proves\vS\Hab\Type_i}
77+{\Gamma;\lam{\vx}{\vS}\proves\RW{valid}}
78+\hg
79+\Rule{\Gamma\proves\vS\Hab\Type_i}
80+{\Gamma;\all{\vx}{\vS}\proves\RW{valid}}
81+\hg
82+\Rule{\Gamma\proves\vS\Hab\Type_i\hg\Gamma\proves\vs\Hab\vS}
83+{\Gamma;\LET\;\vx\;\defq\;\vs\Hab\vS\proves\RW{valid}}
7884}
7985
8086\subsubsection{Evaluation}
@@ -97,8 +103,8 @@ The following contextual closure rule reduces a $\LET$ binding by creating
97103a $\delta$-reducible expression:
98104
99105\DM{
100−\Rule{\Gamma;\LET\:\vx\defq\vs\proves\vt\leadsto\vu}
101−{\Gamma\proves\LET\:\vx\defq\vs\Hab\vS\SC\vt\leadsto\vu}
106+\Rule{\Gamma;\LET\;\vx\defq\vs\Hab\vS\proves\vt\leadsto\vu}
107+{\Gamma\proves\LET\;\vx\defq\vs\Hab\vS\SC\vt\leadsto\vu}
102108}
103109
104110\demph{Reduction} ($\reduces$) is the structural closure of contraction, and evaluation
@@ -116,11 +122,11 @@ reduction rules.
116122\begin{array}{lc}
117123\beta\mathrm{-contraction} &
118124\Axiom{
119−\Gamma\proves(\lam{\vx}{\vS}\SC\vt)\:\vs\leadsto\LET\:\vx\defq\vs\Hab\vS\SC\vt
125+\Gamma\proves(\lam{\vx}{\vS}\SC\vt)\;\vs\leadsto\LET\;\vx\defq\vs\Hab\vS\SC\vt
120126} \\
121127\delta\mathrm{-contraction} &
122128\Axiom{
123−\Gamma;\LET\:\vx\defq\vs\Hab\vS;\Gamma'
129+\Gamma;\LET\;\vx\defq\vs\Hab\vS;\Gamma'
124130\proves
125131\vx\leadsto\vs
126132}
@@ -147,71 +153,71 @@ are no cycles. Otherwise, the typing rules are standard and type inference can
147153be implemented in the usual way~\cite{loh2010tutorial}.
148154
149155\FFIG{\begin{array}{c}
150−\mathsf{Type}\:
156+\mathsf{Type}\;
151157\Rule{\Gamma\proves\RW{valid}}
152158{\Gamma\vdash\Type_n\Hab\Type_{n+1}}
153159\\
154−\mathsf{Const}_1\:
160+\mathsf{Const}_1\;
155161\Rule{\Gamma\proves\RW{valid}}
156162{\Gamma\vdash\vi\Hab\TC{Int}}
157163\hg
158−\mathsf{Const}_2\:
164+\mathsf{Const}_2\;
159165\Rule{\Gamma\proves\RW{valid}}
160166{\Gamma\vdash\VV{str}\Hab\TC{String}}
161167\\
162−\mathsf{Const}_3\:
168+\mathsf{Const}_3\;
163169\Rule{\Gamma\proves\RW{valid}}
164170{\Gamma\vdash\TC{Int}\Hab\Type_0}
165171\hg
166−\mathsf{Const}_4\:
172+\mathsf{Const}_4\;
167173\Rule{\Gamma\proves\RW{valid}}
168174{\Gamma\vdash\TC{String}\Hab\Type_0}
169175\\
170−%\mathsf{Pat}_1\:
176+%\mathsf{Pat}_1\;
171177%\Rule{(\pat{\vx}{\vS})\in\Gamma}
172178%{\Gamma\vdash\vx\Hab\vS}
173179%\hg
174−%\mathsf{Pat}_2\:
180+%\mathsf{Pat}_2\;
175181%\Rule{(\pty{\vx}{\vS})\in\Gamma}
176182%{\Gamma\vdash\vx\Hab\vS}
177183\\
178−\mathsf{Var}_1\:
184+\mathsf{Var}_1\;
179185\Rule{(\lam{\vx}{\vS})\in\Gamma}
180186{\Gamma\vdash\vx\Hab\vS}
181187\hg
182−\mathsf{Var}_2\:
188+\mathsf{Var}_2\;
183189\Rule{(\all{\vx}{\vS})\in\Gamma}
184190{\Gamma\vdash\vx\Hab\vS}
185191\hg
186−\mathsf{Val}\:
187−\Rule{(\LET\:\vx\Hab\vS\defq\vs)\in\Gamma}
192+\mathsf{Val}\;
193+\Rule{(\LET\;\vx\defq\vs\Hab\vS)\in\Gamma}
188194{\Gamma\vdash\vx\Hab\vS}
189195\\
190−\mathsf{App}\:
196+\mathsf{App}\;
191197\Rule{\Gamma\vdash\vf\Hab\fbind{\vx}{\vS}{\vT}\hg\Gamma\vdash\vs\Hab\vS}
192−{\Gamma\vdash\vf\:\vs\Hab\vT[\vs/\vx]} % \LET\:\vx\Hab\vS\:\defq\:\vs\:\IN\:\vT}
198+{\Gamma\vdash\vf\;\vs\Hab\vT[\vs/\vx]} % \LET\;\vx\Hab\vS\;\defq\;\vs\;\IN\;\vT}
193199\\
194−\mathsf{Lam}\:
200+\mathsf{Lam}\;
195201\Rule{\Gamma;\lam{\vx}{\vS}\vdash\ve\Hab\vT\hg\Gamma\proves\fbind{\vx}{\vS}{\vT}\Hab\Type_n}
196202{\Gamma\vdash\lam{\vx}{\vS}.\ve\Hab\fbind{\vx}{\vS}{\vT}}
197203\\
198−\mathsf{Forall}\:
204+\mathsf{Forall}\;
199205\Rule{\Gamma;\all{\vx}{\vS}\vdash\vT\Hab\Type_m\hg\Gamma\vdash\vS\Hab\Type_n}
200206{\Gamma\vdash\fbind{\vx}{\vS}{\vT}\Hab\Type_p}
201−\:(\exists\vp.\vm\le\vp,\:\vn\le\vp)
207+\;(\exists\vp.\vm\le\vp,\;\vn\le\vp)
202208\\
203−\mathsf{Let}\:
209+\mathsf{Let}\;
204210\Rule{\begin{array}{c}\Gamma\proves\ve_1\Hab\vS\hg
205− \Gamma;\LET\:\vx\defq\ve_1\Hab\vS\proves\ve_2\Hab\vT\\
211+ \Gamma;\LET\;\vx\defq\ve_1\Hab\vS\proves\ve_2\Hab\vT\\
206212 \Gamma\proves\vS\Hab\Type_n\hg
207− \Gamma;\LET\:\vx\defq\ve_1\Hab\vS\proves\vT\Hab\Type_n\end{array}
213+ \Gamma;\LET\;\vx\defq\ve_1\Hab\vS\proves\vT\Hab\Type_n\end{array}
208214 }
209−{\Gamma\vdash\LET\:\vx\defq\ve_1\Hab\vS\SC\:\ve_2\Hab
215+{\Gamma\vdash\LET\;\vx\defq\ve_1\Hab\vS\SC\;\ve_2\Hab
210216 \vT[\ve_1/\vx]}
211−%\Let\:\vx\Hab\vS\defq\ve_1\:\IN\:\vT}
217+%\Let\;\vx\Hab\vS\defq\ve_1\;\IN\;\vT}
212218\\
213219
214−\mathsf{Conv}\:
220+\mathsf{Conv}\;
215221\Rule{\Gamma\proves\vx\Hab\vA\hg\Gamma\proves\vA'\Hab\Type_n\hg
216222 \Gamma\proves\vA\cumul\vA'}
217223 {\Gamma\proves\vx\Hab\vA'}
@@ -237,6 +243,7 @@ be implemented in the usual way~\cite{loh2010tutorial}.
237243{Cumulativity}
238244{cumul}
239245
246+
240247\subsection{Inductive Families}
241248
242249\label{sect:inductivefams}
@@ -251,21 +258,21 @@ sequence of zero or more $\vx$ (i.e., $\vx_1,\vx_2,\ldots,\vx_n$):
251258
252259\DM{
253260\AR{
254−\Data\hg\TC{T}\:(\tx\Hab\ttt)\Hab\vt\hg\Where\hg
255−\DC{c}_1\Hab\vt\:\mid\:\ldots\:\mid\:\DC{c}_n\Hab\vt
261+\Data\hg\TC{T}\;(\tx\Hab\ttt)\Hab\vt\hg\Where\hg
262+\DC{c}_1\Hab\vt\;\mid\;\ldots\;\mid\;\DC{c}_n\Hab\vt
256263}
257264}
258265
259−Constructors may take recursive arguments in the family
260−$\TC{T}$. Furthermore these arguments may themselves be indexed by another type ---
261−if such indices do not involve $\TC{T}$ then the constructor is
262−\demph{strictly positive}, which ensures that recursive arguments of the
266+Constructors may take recursive arguments in the family $\TC{T}$, which may be
267+higher order. Higher order recursive arguments may be computed from any type
268+which does not involve $\TC{T}$ itself. This restriction is known as
269+\demph{strict positivity} and ensures that recursive arguments of the
263270constructor are structurally smaller than the value itself.
264271
265272For example, the \Idris{} data type \tTC{Nat} would be declared in \TT{} as follows:
266273
267274\DM{
268−\Data\hg\Nat\Hab\Type\hg\Where\hg\Z\Hab\Nat\:\mid\:\suc\Hab\fbind{\vk}{\Nat}{\Nat}
275+\Data\hg\Nat\Hab\Type\hg\Where\hg\Z\Hab\Nat\;\mid\;\suc\Hab\fbind{\vk}{\Nat}{\Nat}
269276}
270277
271278A data type may have zero or more parameters (which are invariant
@@ -274,10 +281,11 @@ example, the \TT{} equivalent of \tTC{List} is parameterised over its element ty
274281
275282\DM{
276283\AR{
277−\Data\hg\List\:(\va\Hab\Type)\Hab\Type\hg\Where
284+\Data\hg\List\:(\va\Hab\Type)\Hab\Type\hg\Where\\
285+\hg\hg
278286\ARd{
279−& \nil\Hab\List\:\va\\
280−\mid & (\cons)\Hab\fbind{\vx}{\va}{\fbind{\vxs}{\List\:\va}{\List\:\va}}
287+& \nil\Hab\List\;\va\\
288+\mid & (\cons)\Hab\fbind{\vx}{\va}{\fbind{\vxs}{\List\;\va}{\List\;\va}}
281289}
282290}
283291}
@@ -292,11 +300,11 @@ index $\vk$ is given \remph{explicitly}.
292300
293301\DM{
294302\AR{
295−\Data\hg\Vect\:(\va\Hab\Type)\Hab\Nat\to\Type\hg\Where \\
303+\Data\hg\Vect\;(\va\Hab\Type)\Hab\Nat\to\Type\hg\Where \\
296304\hg\hg\ARd{
297−& \nil\Hab\Vect\:\va\:\Z\\
305+& \nil\Hab\Vect\;\va\;\Z\\
298306\mid & (\cons)\Hab\fbind{\vk}{\Nat}{
299−\fbind{\vx}{\va}{\fbind{\vxs}{\Vect\:\va\:\vk}{\Vect\:\va\:(\suc\:\vk)}}
307+\fbind{\vx}{\va}{\fbind{\vxs}{\Vect\;\va\;\vk}{\Vect\;\va\;(\suc\;\vk)}}
300308}
301309}
302310}
@@ -306,7 +314,8 @@ index $\vk$ is given \remph{explicitly}.
306314
307315\label{sect:patdefs}
308316
309−\subsubsection{Syntax}
317+%\subsubsection{Syntax}
318+
310319
311320A pattern matching definition for a function named $\FN{f}$ takes the following form,
312321consisting of a type declaration followed by one or more pattern clauses:
@@ -314,9 +323,9 @@ consisting of a type declaration followed by one or more pattern clauses:
314323\DM{
315324\AR{
316325\FN{f}\Hab\vt\\
317−\pat{\tx_1}{\ttt_1}\SC\FN{f}\:\ttt_1\:=\:\vt_1\\
326+\pat{\tx_1}{\ttt_1}\SC\FN{f}\;\ttt_1\;=\;\vt_1\\
318327\ldots\\
319−\pat{\tx_n}{\ttt_n}\SC\FN{f}\:\ttt_n\:=\:\vt_n\\
328+\pat{\tx_n}{\ttt_n}\SC\FN{f}\;\ttt_n\;=\;\vt_n\\
320329}
321330}
322331
@@ -333,152 +342,210 @@ clause is defined by the following rule:
333342
334343\DM{
335344\Rule{
336−\Gamma;\lam{\tx}{\tU}\proves\FN{f}\:\tts\Hab\vS\hg
345+\Gamma;\lam{\tx}{\tU}\proves\FN{f}\;\tts\Hab\vS\hg
337346\Gamma;\lam{\tx}{\tU}\proves\ve\Hab\vT\hg
338347\Gamma\proves\vS\converts\vT}
339348{
340−\Gamma\proves\pat{\tx}{\tU}\SC\FN{f}\:\tts\:=\:\ve\:\RW{valid}
341−}
342−}
343−
344−A valid pattern matching definition effectively extends \TT{} with a new constant,
345−with the given type (extending the initial typing rules given in Section \ref{sect:typerules})
346−and reduction behaviour (extending the initial reduction rules given in Section
347−\ref{sect:evaluation}).
348−
349−\subsubsection{Semantics}
350−
351−Matching on an expression proceeds by comparing the expression to
352−each match clause in order, resulting in either:
353−
354−\begin{itemize}
355−\item \demph{Success}, with pattern variables mapping to expressions
356−\item \demph{Failure}, with matching continuing by proceeding to the next match clause
357−\item Matching being \demph{blocked}, for example by attempting to match a variable
358−against a constructor pattern. In this case, no reduction occurs, because instantiating
359−the variable may provide enough information for the clause to match.
360−\end{itemize}
361−
362−% Pat(x args) => x (Pat' args)
363−% Pat (x) => x
364−% Pat _ => _
365−
366−In order to implement pattern matching, we must separate the \remph{accessible} and
367−\remph{inaccessible} patterns. A pattern is \demph{accessible} (that is, it is possible
368−to match against it) if it is constructor headed, or a variable. Inaccessible patterns
369−are converted to ``match anything'' patterns. Clauses are converted to matchable pattern
370−clauses with the $\MO{Clause}$ operation, given in Figure \ref{mkclause}.
371−We extend the vector notation to meta-operations: the notation $\vec{\MO{Pat}}$ lifts the
372−$\MO{Pat}$ operation across a list of arguments.
349+\Gamma\proves\pat{\tx}{\tU}\SC\FN{f}\;\tts\;=\;\ve\;\RW{valid}
350+}
351+}
352+
353+A valid pattern matching definition effectively extends \TT{} with a new
354+constant, with the given type (extending the initial typing rules given in
355+Section \ref{sect:typerules}) and reduction behaviour (extending the initial
356+reduction rules given in Section \ref{sect:evaluation}).
357+Patterns are separated into the accessible patterns (variables and constructor
358+forms which may be inspected) and inaccessible patterns, following
359+Agda~\cite{norell2007thesis} then implemented by compilation into case
360+trees~\cite{Augustsson1985}.
361+
362+% \subsubsection{Semantics}
363+%
364+% Matching on an expression proceeds by comparing the expression to
365+% each match clause in order, resulting in either:
366+%
367+% \begin{itemize}
368+% \item \demph{Success}, with pattern variables mapping to expressions
369+% \item \demph{Failure}, with matching continuing by proceeding to the next match clause
370+% \item Matching being \demph{blocked}, for example by attempting to match a variable
371+% against a constructor pattern. In this case, no reduction occurs, because instantiating
372+% the variable may provide enough information for the clause to match.
373+% \end{itemize}
374+%
375+% % Pat(x args) => x (Pat' args)
376+% % Pat (x) => x
377+% % Pat _ => _
378+%
379+% In order to implement pattern matching, we must separate the \remph{accessible} and
380+% \remph{inaccessible} patterns. A pattern is \demph{accessible} (that is, it is possible
381+% to match against it) if it is constructor headed, or a variable. Inaccessible patterns
382+% are converted to ``match anything'' patterns. Clauses are converted to matchable pattern
383+% clauses with the $\MO{Clause}$ operation, given in Figure \ref{mkclause}.
384+% We extend the vector notation to meta-operations: the notation $\vec{\MO{Pat}}$ lifts the
385+% $\MO{Pat}$ operation across a list of arguments.
386+%
387+% \FFIG{
388+% \AR{
389+% \PA{\A}{
390+% & \MO{Clause} & (\pat{\tx}{\tU}\SC\FN{f}\;\tts\;=\;\ve)
391+% & \MoRet{\FN{f}\;(\vec{\MO{Pat}}\;\tts)\;=\;\ve}
392+% }
393+% \medskip\\
394+% \PA{\A}{
395+% & \MO{Pat} & (\vx\;\tts) & \MoRet{\vx\;(\vec{\MO{Pat}}\;\tts)
396+% \hg\mbox{(if $\MO{Con}\;\vx$ and $\MO{Arity}\;\vx = \MO{Length}\;\tts$)}} \\
397+% & \MO{Pat} & \vx & \MoRet{\vx} \hg\mbox(if $\vx$ is a pattern variable)\\
398+% & \MO{Pat} & \cdot & \MoRet{\_} \hg\mbox(in all other cases)\\
399+% }
400+% }
401+% }
402+% {Building matchable pattern clauses}
403+% {mkclause}
404+%
405+%
406+% % Match (c args, c args') => Match' (args, args')
407+% % Match (c args, x) => Blocked
408+% % Match (x, t) => Success (x => t)
409+% % Match (_, t) => Success ()
410+%
411+% \newcommand{\Blocked}{\mathsf{Blocked}}
412+% \newcommand{\Success}{\mathsf{Success}}
413+% \newcommand{\Failure}{\mathsf{Failure}}
414+%
415+% Pattern matching is invoked by the evaluator on encountering a function with
416+% a pattern matching definition applied to some arguments. If successful, pattern
417+% matching returns a new expression, which can then be reduced further.
418+% Figure \ref{pmatch} gives the semantics of pattern matching a collection of
419+% matchable clauses
420+% $\tc$ against an expression $\ve$. $\MO{Match}$ attempts to match each clause in
421+% turn against $\ve$. If matching a clause returns $\Success$ or $\Blocked$, then
422+% matching terminates. If matching a clause returns $\Failure$, then matching proceeds
423+% with the next clause. The algorithm uses the following meta-operations:
424+%
425+% \begin{itemize}
426+% \item $\MO{Con}\;\vx$, which returns true if $\vx$ is a constructor name
427+% \item $\MO{Arity}\;\vx$, which, if $\vx$ is a constructor name, returns the number of arguments
428+% $\vx$ requires.
429+% \item $\MO{Length}\;\tts$, which returns the length of the vector $\tts$
430+% \end{itemize}
431+%
432+%
433+% \FFIG{
434+% \AR{
435+% \PA{\A\A}{
436+% & \MO{MatchArg} & (\vx\;\tts) & (\vx\;\tts')
437+% & \MoRet{\vec{\MO{MatchArg}}\;\tts\;\tts'\hg\mbox{(if $\MO{Con}\;\vx$)}}\\
438+% & \MO{MatchArg} & (\vx\;\tts) & \vx & \MoRet{\Blocked} \\
439+% & \MO{MatchArg} & \vx & \vt & \MoRet{\Success\;(\vx\mapsto\vt)} \\
440+% & \MO{MatchArg} & \_ & \vt & \MoRet{\Success\;()} \\
441+% & \MO{MatchArg} & \cdot & \cdot & \MoRet{\Failure}
442+% }
443+% \medskip\\
444+% \PA{\A\A}{
445+% & \MO{MatchClause} & (\vf\;\tp = \ve) & (\vf\;\tts) &
446+% \MoRet{
447+% \AR{
448+% \Success\;\ve[\tx/\tv]\hg\mbox{(if $\vec{\MO{MatchArg}}\;\tp\;\tts \mq \Success\;(\tx,\tv)$)}\\
449+% \Blocked\;\;\;\hg\hg\mbox{(if $\vec{\MO{MatchArg}}\;\tp\;\tts \mq \Blocked$)}\\
450+% \Failure\;\;\;\;\;\hg\hg\mbox{(if $\vec{\MO{MatchArg}}\;\tp\;\tts \mq \Failure$)}\\
451+% }
452+% } \\
453+% & \MO{MatchClause} & (\vf\;\tp = \ve) & \cdot & \MoRet{\Failure} \\
454+% }
455+% \medskip\\
456+% \PA{\A\A}{
457+% & \MO{Match} & (\vc ; \tc) & \ve &
458+% \MoRet{
459+% \AR{
460+% \Success\;\vx\;\;\hg\mbox{(if $\MO{MatchClause}\;\vc\;\ve \mq \Success\;\vx)$} \\
461+% \Blocked\hg\;\;\;\;\mbox{(if $\MO{MatchClause}\;\vc\;\ve \mq \Blocked)$} \\
462+% \MO{Match}\;\tc\;\ve\hg\mbox{(otherwise)}
463+% }
464+% } \\
465+% & \MO{Match} & \cdot & \ve & \MoRet{\Failure}
466+% }
467+% }
468+% }
469+% {Pattern matching semantics}
470+% {pmatch}
471+%
472+% By convention, we write the application of a meta-operation $\MO{Op}$
473+% across a vector $\tx$ as $\vec{\MO{Op}}\;\tx$.
474+% In practice, for efficiency, pattern matching is implemented by compiling the match clauses to
475+% a tree of case expressions~\cite{Augustsson1985}.
476+
477+\subsection{Metatheory}
373478
374479\FFIG{
375−\AR{
376−\PA{\A}{
377−& \MO{Clause} & (\pat{\tx}{\tU}\SC\FN{f}\:\tts\:=\:\ve)
378− & \MoRet{\FN{f}\:(\vec{\MO{Pat}}\:\tts)\:=\:\ve}
379−}
380−\medskip\\
381−\PA{\A}{
382−& \MO{Pat} & (\vx\:\tts) & \MoRet{\vx\:(\vec{\MO{Pat}}\:\tts)
383− \hg\mbox{(if $\MO{Con}\:\vx$ and $\MO{Arity}\:\vx = \MO{Length}\:\tts$)}} \\
384−& \MO{Pat} & \vx & \MoRet{\vx} \hg\mbox(if $\vx$ is a pattern variable)\\
385−& \MO{Pat} & \cdot & \MoRet{\_} \hg\mbox(in all other cases)\\
386−}
387−}
480+\begin{array}{ll}
481+\mbox{\textbf{Church-Rosser}} &
482+\begin{array}{ll}
483+\mbox{If}\hg\Gamma\proves\vs\converts\vt \\
484+\mbox{then there is a common reduct $\vr$ such that}\;\\
485+\Gamma\proves\vs\reducesto\vr\hg\Gamma\proves\vt\reducesto\vr
486+\end{array}
487+\medskip
488+\\
489+\mbox{\textbf{Subject Reduction}} &
490+\begin{array}{ll}
491+\mbox{If} & \Gamma\proves\vs\Hab\vS\hg\Gamma\proves\vs\reduces\vt\\
492+\mbox{then}& \Gamma\proves\vt\Hab\vS
493+\end{array}
494+\medskip
495+\\
496+\mbox{\textbf{Cut}} &
497+\begin{array}{ll}
498+\mbox{If} & \Gamma_0,\LET\;\vx\defq\vs\Hab\vS,\Gamma_1\proves\vt\Hab\vT\\
499+\mbox{then} & \Gamma_0, \Gamma_1[\vs/\vx]\proves\vt[\vs/\vx]\Hab\vT[\vs/\vx]
500+\end{array}
501+\medskip
502+\\
503+\mbox{\textbf{Strengthening}} &
504+\begin{array}{ll}
505+\mbox{If} & \Gamma_0,\mathcal{B}(\vx, \vT),\Gamma_1\proves\vs\Hab\vS
506+\hg\vx\not\in\Gamma_1,\vs,\vS\\
507+\mbox{then} & \Gamma_0,\Gamma_1\proves\vs\Hab\vS\\
508+(\mbox{where} & \mathcal{B}(\vx, \vT) \proves \vx\Hab\vT)
509+\end{array}
510+\\
511+\end{array}
388512}
389−{Building matchable pattern clauses}
390−{mkclause}
391−
392−
393−% Match (c args, c args') => Match' (args, args')
394−% Match (c args, x) => Blocked
395−% Match (x, t) => Success (x => t)
396−% Match (_, t) => Success ()
397−
398−\newcommand{\Blocked}{\mathsf{Blocked}}
399−\newcommand{\Success}{\mathsf{Success}}
400−\newcommand{\Failure}{\mathsf{Failure}}
401−
402−Pattern matching is invoked by the evaluator on encountering a function with
403−a pattern matching definition applied to some arguments. If successful, pattern
404−matching returns a new expression, which can then be reduced further.
405−Figure \ref{pmatch} gives the semantics of pattern matching a collection of
406−matchable clauses
407−$\tc$ against an expression $\ve$. $\MO{Match}$ attempts to match each clause in
408−turn against $\ve$. If matching a clause returns $\Success$ or $\Blocked$, then
409−matching terminates. If matching a clause returns $\Failure$, then matching proceeds
410−with the next clause. The algorithm uses the following meta-operations:
411−
412−\begin{itemize}
413−\item $\MO{Con}\:\vx$, which returns true if $\vx$ is a constructor name
414−\item $\MO{Arity}\:\vx$, which, if $\vx$ is a constructor name, returns the number of arguments
415−$\vx$ requires.
416−\item $\MO{Length}\:\tts$, which returns the length of the vector $\tts$
417−\end{itemize}
418−
513+{Metatheoretic properties of \TT{}}
514+{metatheory}
419515
420−\FFIG{
421−\AR{
422−\PA{\A\A}{
423−& \MO{MatchArg} & (\vx\:\tts) & (\vx\:\tts')
424− & \MoRet{\vec{\MO{MatchArg}}\:\tts\:\tts'\hg\mbox{(if $\MO{Con}\:\vx$)}}\\
425−& \MO{MatchArg} & (\vx\:\tts) & \vx & \MoRet{\Blocked} \\
426−& \MO{MatchArg} & \vx & \vt & \MoRet{\Success\:(\vx\mapsto\vt)} \\
427−& \MO{MatchArg} & \_ & \vt & \MoRet{\Success\:()} \\
428−& \MO{MatchArg} & \cdot & \cdot & \MoRet{\Failure}
429−}
430−\medskip\\
431−\PA{\A\A}{
432−& \MO{MatchClause} & (\vf\:\tp = \ve) & (\vf\:\tts) &
433− \MoRet{
434− \AR{
435− \Success\:\ve[\tx/\tv]\hg\mbox{(if $\vec{\MO{MatchArg}}\:\tp\:\tts \mq \Success\:(\tx,\tv)$)}\\
436− \Blocked\;\;\;\hg\hg\mbox{(if $\vec{\MO{MatchArg}}\:\tp\:\tts \mq \Blocked$)}\\
437− \Failure\;\;\;\;\;\hg\hg\mbox{(if $\vec{\MO{MatchArg}}\:\tp\:\tts \mq \Failure$)}\\
438− }
439− } \\
440−& \MO{MatchClause} & (\vf\:\tp = \ve) & \cdot & \MoRet{\Failure} \\
441−}
442−\medskip\\
443−\PA{\A\A}{
444−& \MO{Match} & (\vc ; \tc) & \ve &
445− \MoRet{
446− \AR{
447− \Success\;\vx\;\;\hg\mbox{(if $\MO{MatchClause}\:\vc\:\ve \mq \Success\:\vx)$} \\
448− \Blocked\hg\;\;\;\;\mbox{(if $\MO{MatchClause}\:\vc\:\ve \mq \Blocked)$} \\
449− \MO{Match}\:\tc\:\ve\hg\mbox{(otherwise)}
450− }
451− } \\
452−& \MO{Match} & \cdot & \ve & \MoRet{\Failure}
453−}
454−}
455−}
456−{Pattern matching semantics}
457−{pmatch}
516+We assume that \TT{} respects the usual metatheoretic properties, as shown in
517+Figure \ref{metatheory}. Specifically: the \demph{Church-Rosser} property
518+(i.e. that distinct reduction sequences lead to the same normal form);
519+\demph{subject reduction} (i.e. that computation preserves type); the
520+\demph{cut} property (i.e. that $\RW{let}$-bound terms may be substituted into
521+their scope); and \demph{strengthening} (i.e. that removing unused definitions
522+from scope does not affect typechecking).
458523
459−By convention, we write the application of a meta-operation $\MO{Op}$
460−across a vector $\tx$ as $\vec{\MO{Op}}\:\tx$.
461−In practice, for efficiency, pattern matching is implemented by compiling the match clauses to
462−a tree of case expressions~\cite{Augustsson1985}.
524+One property which is noticeably absent is \demph{strong normalisation}.
525+Although desirable to preserve termination and decidability of type checking,
526+we allow diverging terms for pragmatic reasons as \Idris{} is primarily a
527+programming language rather than a theorem prover. Nevertheless, we do
528+\emph{check} for totality in order to be sure which terms are safe to
529+evaluate at compile time.
463530
464531\subsection{Totality checking}
465532
466−In order to ensure termination of type checking
467−we must distinguish terms for which evaluation definitely terminates, and
468−those which may diverge. \TT{} takes a simple but pragmatic and
469−effective approach to termination
470−checking: any functions which do not satisfy a syntactic constraint on recursive
471−calls are marked as \emph{partial}. Additionally, any function which calls a partial
533+In order to ensure termination of type checking we must distinguish terms for
534+which evaluation definitely terminates, and those which may diverge. \TT{}
535+takes a simple but pragmatic and effective approach to termination checking:
536+any functions which do not satisfy a syntactic constraint on recursive calls
537+are marked as \emph{partial}. Additionally, any function which calls a partial
472538function or uses a data type which is not strictly positive is also marked as
473539partial. The syntactic constraint we use is that a recursive call in a pattern
474−clause must have an argument which is structurally smaller than an input argument
475−in the same position. \TT{} also marks functions which do not cover all possible
476−inputs as partial. This totality checking is independent of the rest of the type
477−theory, and can be extended.
540+clause must have an argument which is structurally smaller than an input
541+argument in the same position. \TT{} also marks functions which do not cover
542+all possible inputs as partial. This totality checking is independent of the
543+rest of the type theory, and can be extended.
478544
479−This approach, separating the termination requirement from the type theory, means that
480−an \Idris{} programmer makes the decision about the importance of totality for each
481−function rather than having the totality requirement imposed by the type theory.
545+This approach, separating the termination requirement from the type theory,
546+means that an \Idris{} programmer makes the decision about the importance of
547+totality for each function rather than having the totality requirement imposed
548+by the type theory.
482549
483550\subsection{From \Idris{} to \TT{}}
484551
@@ -526,7 +593,7 @@ algorithm:
526593
527594\begin{SaveVerbatim}{vAddImpSolve}
528595
529−vAdd : (a : Set) -> (n : Nat) -> Num a -> Vect a n -> Vect a n -> Vect a n
596+vAdd : (a : Type) -> (n : Nat) -> Num a -> Vect a n -> Vect a n -> Vect a n
530597vAdd a O c (Nil a) (Nil a) = Nil a
531598vAdd a (S k) c ((::) a k x xs) ((::) a k y ys)
532599 = (::) a k ((+) c x y) (vAdd a k c xs ys)
@@ -540,35 +607,29 @@ switching to \TT{} notation from the ASCII \Idris{} syntax.
540607
541608\FFIG{
542609\AR{
543−\begin{array}{ll}
544−\FN{vAdd} & \Hab(\va\Hab\Set)\to(\vn\Hab\Nat)\to\TC{Num}\:\va\to
545− \Vect\:\va\:\vn\to\Vect\:\va\:\vn\to\Vect\:\va\:\vn\\
546−\end{array}
547−\\
548−\begin{array}{lccccccc}
549−\multicolumn{5}{l}{
550−\RW{var}\:\va\Hab\Set,\:\vc\Hab\TC{Num}\;\va\SC}\\
551−\hg\FN{vAdd} & \va & \Z & \vc & (\DC{Nil}\;\va) & (\DC{Nil}\;\va) & \Ret{\DC{Nil}\;\va} \\
552−\multicolumn{5}{l}{
553−\RW{var}\:\AR{
554−\va\Hab\Set,\:\vk\Hab\Nat,\;\vc\Hab\TC{Num}\;\va,\\
610+\FN{vAdd} \Hab(\va\Hab\Type)\to(\vn\Hab\Nat)\to\TC{Num}\;\va\to
611+ \Vect\;\va\;\vn\to\Vect\;\va\;\vn\to\Vect\;\va\;\vn\\
612+\RW{var}\;\va\Hab\Type,\;\vc\Hab\TC{Num}\;\va\SC\\
613+\hg\FN{vAdd} \; \va \; \Z \; \vc \; (\DC{Nil}\;\va) \; (\DC{Nil}\;\va) \;
614+\cq\;\DC{Nil}\;\va \\
615+\RW{var}\;\AR{
616+\va\Hab\Type,\;\vk\Hab\Nat,\;\vc\Hab\TC{Num}\;\va,\\
555617\vx\Hab\va,\;\vxs\Hab\Vect\;\va\;\vk,\;
556618\vy\Hab\va,\;\vys\Hab\Vect\;\va\;\vk
557619\SC
620+\\
621+\FN{vAdd} \; \va \; (\suc\;\vk) \; \vc
622+ \; ((\DC{::})\;\va\;\vk\;\vx\;\vxs)
623+ \; ((\DC{::})\;\va\;\vk\;\vy\;\vys)
624+ \\
625+ \hg\hg\cq\:((\DC{::})\;\va\;\vk\;((+)\;\vc\;\vx\;\vy)\; (\FN{vAdd}\;\va\;\vk\;\vc\;\vxs\;\vys))
558626}
559−}\\
560−\hg\FN{vAdd} & \va & (\suc\;\vk) & \vc
561− & ((\DC{::})\;\va\;\vk\;\vx\;\vxs)
562− & ((\DC{::})\;\va\;\vk\;\vy\;\vys)
563− & \\
564− & & \MRet{5}{((\DC{::})\;\va\;\vk\;((+)\;\vc\;\vx\;\vy)\; (\FN{vAdd}\;\va\;\vk\;\vc\;\vxs\;\vys))}
565−\end{array}
566627}
567628}
568629{Pairwise addition of vectors in \TT{}}
569630{ttvadd}
570631
571−\subsubsection{An observation}
632+\subsubsection{An Observation: Programming vs Theorem Proving}
572633
573634\Idris{} programs may contain several high level constructs not present in \TT{}, such
574635as implicit arguments, type classes, \texttt{where} clauses, pattern matching \texttt{let}
@@ -580,18 +641,20 @@ programming and theorem proving with dependent types, and appropriate mechanisms
580641constructing programs and theorems:
581642
582643\begin{itemize}
583−\item \remph{Pattern matching} is a convenient abstraction for humans to write programs,
584−in that it allows a programmer to express exactly the computational behaviour of a function.
585−\item \remph{Tactics}, such as those used in the Coq theorem prover~\cite{Bertot2004},
586−are a convenient abstraction for building proofs and programs by \remph{refinement}.
644+\item \remph{Pattern matching} is a convenient abstraction for humans to write
645+programs, in that it allows a programmer to express exactly the computational
646+behaviour of a function.
647+\item \remph{Tactics}, such as those used in the Coq theorem
648+prover~\cite{Bertot2004}, are a convenient abstraction for building proofs and
649+programs by \remph{refinement}.
587650\end{itemize}
588651
589−The idea behind the \Idris{} elaborator, therefore, is to use the high level program
590−to direct \demph{tactics} to build \TT{} programs by refinement. The
591−elaborator is implemented as an Embedded Domain Specific Language (EDSL) in Haskell.
592−The remainder
593−of this paper describes the EDSL and demonstrates how it is used to implement
594−all of the high level features of \Idris{}.
652+The idea behind the \Idris{} elaborator, therefore, is to use the high level
653+program to direct \demph{tactics} to build \TT{} programs by refinement. The
654+elaborator is implemented as a Haskell monad capturing proof state, with a
655+collection of tactics for updating and refining the proof state. The remainder
656+of this paper describes this elaborator and demonstrates how it is used to
657+implement the high level features of \Idris{}.
595658
596659
597660
samples/binary.idr+2−2
@@ -1,6 +1,6 @@
11module main
22
3−data Bit : Nat -> Set where
3+data Bit : Nat -> Type where
44 b0 : Bit 0
55 b1 : Bit 1
66
@@ -10,7 +10,7 @@ instance Show (Bit n) where
1010
1111infixl 5 #
1212
13−data Binary : (width : Nat) -> (value : Nat) -> Set where
13+data Binary : (width : Nat) -> (value : Nat) -> Type where
1414 zero : Binary O O
1515 (#) : Binary w v -> Bit bit -> Binary (S w) (bit + 2 * v)
1616
samples/interp-alt.idr+4−4
@@ -2,18 +2,18 @@ module main
22
33data Ty = TyInt | TyBool| TyFun Ty Ty
44
5−interpTy : Ty -> Set
5+interpTy : Ty -> Type
66interpTy TyInt = Int
77interpTy TyBool = Bool
88interpTy (TyFun s t) = interpTy s -> interpTy t
99
1010using (G : Vect Ty n)
1111
12− data Env : Vect Ty n -> Set where
12+ data Env : Vect Ty n -> Type where
1313 Nil : Env Nil
1414 (::) : interpTy a -> Env G -> Env (a :: G)
1515
16−-- data HasType : (i : Fin n) -> Vect Ty n -> Ty -> Set where
16+-- data HasType : (i : Fin n) -> Vect Ty n -> Ty -> Type where
1717-- stop : HasType fO (t :: G) t
1818-- pop : HasType k G t -> HasType (fS k) (u :: G) t
1919
@@ -21,7 +21,7 @@ using (G : Vect Ty n)
2121 lookup fO (x :: xs) = x
2222 lookup (fS i) (x :: xs) = lookup i xs
2323
24− data Expr : Vect Ty n -> Ty -> Set where
24+ data Expr : Vect Ty n -> Ty -> Type where
2525 Var : (i : Fin n) -> Expr G (lookup i G)
2626 Val : (x : Int) -> Expr G TyInt
2727 Lam : Expr (a :: G) t -> Expr G (TyFun a t)
samples/interp.idr+4−4
@@ -2,18 +2,18 @@ module main
22
33data Ty = TyInt | TyBool | TyFun Ty Ty
44
5−interpTy : Ty -> Set
5+interpTy : Ty -> Type
66interpTy TyInt = Int
77interpTy TyBool = Bool
88interpTy (TyFun s t) = interpTy s -> interpTy t
99
1010using (G : Vect Ty n)
1111
12− data Env : Vect Ty n -> Set where
12+ data Env : Vect Ty n -> Type where
1313 Nil : Env Nil
1414 (::) : interpTy a -> Env G -> Env (a :: G)
1515
16− data HasType : (i : Fin n) -> Vect Ty n -> Ty -> Set where
16+ data HasType : (i : Fin n) -> Vect Ty n -> Ty -> Type where
1717 stop : HasType fO (t :: G) t
1818 pop : HasType k G t -> HasType (fS k) (u :: G) t
1919
@@ -21,7 +21,7 @@ using (G : Vect Ty n)
2121 lookup stop (x :: xs) = x
2222 lookup (pop k) (x :: xs) = lookup k xs
2323
24− data Expr : Vect Ty n -> Ty -> Set where
24+ data Expr : Vect Ty n -> Ty -> Type where
2525 Var : HasType i G t -> Expr G t
2626 Val : (x : Int) -> Expr G TyInt
2727 Lam : Expr (a :: G) t -> Expr G (TyFun a t)
src/Core/CaseTree.hs+1−1
@@ -79,7 +79,7 @@ instance TermSize CaseAlt where
7979small :: Name -> [Name] -> SC -> Bool
8080small n args t = let as = findAllUsedArgs t args in
8181 length as == length (nub as) &&
82− termsize n t < 20
82+ termsize n t < 5
8383
8484namesUsed :: SC -> [Name]
8585namesUsed sc = nub $ nu' [] sc where
src/Core/Elaborate.hs+45−21
@@ -15,6 +15,7 @@ import Core.ProofState
1515import Core.TT
1616import Core.Evaluate
1717import Core.Typecheck
18+import Core.Unify
1819
1920import Control.Monad.State
2021import Data.Char
@@ -118,6 +119,10 @@ get_holes :: Elab' aux [Name]
118119get_holes = do ES p _ _ <- get
119120 return (holes (fst p))
120121
122+get_probs :: Elab' aux Fails
123+get_probs = do ES p _ _ <- get
124+ return (problems (fst p))
125+
121126-- get the current goal type
122127goal :: Elab' aux Type
123128goal = do ES p _ _ <- get
@@ -150,10 +155,6 @@ get_deferred :: Elab' aux [Name]
150155get_deferred = do ES p _ _ <- get
151156 return (deferred (fst p))
152157
153−get_inj :: Elab' aux [(Term, Term, Term)]
154−get_inj = do ES p _ _ <- get
155− return (injective (fst p))
156−
157158checkInjective :: (Term, Term, Term) -> Elab' aux ()
158159checkInjective (tm, l, r) = do ctxt <- get_context
159160 if isInj ctxt tm then return ()
@@ -296,6 +297,9 @@ deferType n ty ns = processTactic' (DeferType n ty ns)
296297instanceArg :: Name -> Elab' aux ()
297298instanceArg n = processTactic' (Instance n)
298299
300+setinj :: Name -> Elab' aux ()
301+setinj n = processTactic' (SetInjective n)
302+
299303proofstate :: Elab' aux ()
300304proofstate = processTactic' ProofState
301305
@@ -375,12 +379,14 @@ apply fn imps =
375379 if null imps then [] -- do all we can
376380 else
377381 map fst (filter (not.snd) (zip args (map fst imps)))
378− let (n, hs) = -- trace ("AVOID UNIFY: " ++ show (fn, dont) ++ "\n" ++ show ptm) $
382+ let (n, hunis) = -- trace ("AVOID UNIFY: " ++ show (fn, dont) ++ "\n" ++ show ptm) $
379383 unified p
380384 let unify = -- trace ("Not done " ++ show hs) $
381− dropGiven dont hs
385+ dropGiven dont hunis hs
382386 put (ES (p { dontunify = dont, unified = (n, unify) }, a) s prev)
383387 ptm <- get_term
388+ g <- goal
389+-- trace ("Goal " ++ show g ++ "\n" ++ show (fn, imps, unify) ++ "\n" ++ show ptm) $
384390 end_unify
385391 ptm <- get_term
386392 return (map (updateUnify unify) args)
@@ -461,15 +467,20 @@ simple_app fun arg =
461467 claim a RType
462468 claim b RType
463469 claim f (RBind (MN 0 "aX") (Pi (Var a)) (Var b))
470+ tm <- get_term
464471 start_unify s
465472 claim s (Var a)
466473 prep_fill f [s]
467474 -- try elaborating in both orders, since we might learn something useful
468475 -- either way
469− try (do focus s; arg
470− focus f; fun)
471− (do focus f; fun
472− focus s; arg)
476+-- try (do focus s; arg
477+-- focus f; fun)
478+-- (do focus f; fun
479+-- focus s; arg)
480+ focus f; fun
481+ focus s; arg
482+ tm <- get_term
483+ ps <- get_probs
473484 complete_fill
474485 hs <- get_holes
475486 -- We don't need a and b in the hole queue any more since they were just for
@@ -493,7 +504,8 @@ try t1 t2 = try' t1 t2 False
493504try' :: Elab' aux a -> Elab' aux a -> Bool -> Elab' aux a
494505try' t1 t2 proofSearch
495506 = do s <- get
496− case runStateT t1 s of
507+ ps <- get_probs
508+ case prunStateT ps t1 s of
497509 OK (v, s') -> do put s'
498510 return v
499511 Error e1 -> if proofSearch || recoverableErr e1 then
@@ -525,18 +537,30 @@ tryAll xs = tryAll' [] (cantResolve, 0) (map fst xs)
525537 tryAll' [res] _ [] = res
526538 tryAll' (_:_) _ [] = cantResolve
527539 tryAll' [] (f, _) [] = f
528− tryAll' cs f (x:xs) = do s <- get
529− case runStateT x s of
530− OK (v, s') -> tryAll' ((do put s'
531− return v):cs) f xs
532− Error err -> do put s
533− if (score err) < 100
534− then
535− tryAll' cs (better err f) xs
536− else
537− tryAll' [] (better err f) xs -- give up
540+ tryAll' cs f (x:xs)
541+ = do s <- get
542+ ps <- get_probs
543+ case prunStateT ps x s of
544+ OK (v, s') -> tryAll' ((do put s'
545+ return v):cs) f xs
546+ Error err -> do put s
547+ if (score err) < 100
548+ then tryAll' cs (better err f) xs
549+ else tryAll' [] (better err f) xs -- give up
550+
538551
539552 better err (f, i) = let s = score err in
540553 if (s >= i) then (lift (tfail err), s)
541554 else (f, i)
542555
556+prunStateT ps x s
557+ = case runStateT x s of
558+ OK (v, s'@(ES (p, _) _ _)) ->
559+ if (length (problems p) > length ps)
560+ then case reverse (problems p) of
561+ ((_,_,_,e):_) -> Error e
562+ else OK (v, s')
563+ Error e -> Error e
564+
565+dumpprobs [] = ""
566+dumpprobs ((_,_,_,e):es) = show e ++ "\n" ++ dumpprobs es
src/Core/Evaluate.hs+1−1
@@ -224,7 +224,7 @@ eval traceon ctxt ntimes genv tm opts = ev ntimes [] True [] tm where
224224 do let val = lookupDefAcc Nothing n atRepl ctxt
225225 case val of
226226 [(CaseOp inl inr _ _ _ ns tree _ _, acc)]
227− | acc == Public || simpl -> -- unoptimised version
227+ | acc == Public -> -- unoptimised version
228228 if canSimplify inl inr n stk
229229 then return $ unload env (VP Ref n ty) args
230230 else do c <- evCase ntimes (n:stk) top env ns args tree
src/Core/ProofShell.hs+21−17
@@ -11,6 +11,8 @@ import Core.Elaborate
1111import Control.Monad.State
1212import System.Console.Haskeline
1313
14+import Idris.AbsSyntaxTree (Idris)
15+
1416import Util.Pretty
1517
1618data ShellState = ShellState
@@ -55,21 +57,23 @@ processCommand (Tac e) state
5557 err -> (state, show err)
5658 | otherwise = (state, "No proof in progress")
5759
58−runShell :: ShellState -> InputT IO ShellState
59−runShell st = do (prompt, parser) <-
60− maybe (return ("TT# ", parseCommand))
61− (\st -> do outputStrLn . render . pretty $ st
62− return (show (thname st) ++ "# ", parseTactic))
63− (prf st)
64− x <- getInputLine prompt
65− cmd <- case x of
66− Nothing -> return $ Right Quit
67− Just input -> return (parser input)
68− case cmd of
69− Left err -> do outputStrLn (show err)
70− runShell st
71− Right cmd -> do let (st', r) = processCommand cmd st
72− outputStrLn r
73− if (not (exitNow st')) then runShell st'
74− else return st'
60+runShell :: ShellState -> Idris ShellState
61+runShell st = runInputT defaultSettings $ runShell' st
62+ where
63+ runShell' st = do (prompt, parser) <-
64+ maybe (return ("TT# ", parseCommand))
65+ (\st -> do outputStrLn . render . pretty $ st
66+ return (show (thname st) ++ "# ", parseTactic))
67+ (prf st)
68+ x <- getInputLine prompt
69+ cmd <- case x of
70+ Nothing -> return $ Right Quit
71+ Just input -> return (parser input)
72+ case cmd of
73+ Left err -> do outputStrLn (show err)
74+ runShell' st
75+ Right cmd -> do let (st', r) = processCommand cmd st
76+ outputStrLn r
77+ if (not (exitNow st')) then runShell' st'
78+ else return st'
7579
src/Core/ProofState.hs+98−45
@@ -29,7 +29,7 @@ data ProofState = PS { thname :: Name,
2929 unified :: (Name, [(Name, Term)]),
3030 solved :: Maybe (Name, Term),
3131 problems :: Fails,
32− injective :: [(Term, Term, Term)],
32+ injective :: [Name],
3333 deferred :: [Name], -- names we'll need to define
3434 instances :: [Name], -- instance arguments (for type classes)
3535 previous :: Maybe ProofState, -- for undo
@@ -68,6 +68,7 @@ data Tactic = Attack
6868 | Defer Name
6969 | DeferType Name Raw [Name]
7070 | Instance Name
71+ | SetInjective Name
7172 | MoveLast Name
7273 | ProofState
7374 | Undo
@@ -148,15 +149,28 @@ hole _ = False
148149
149150holeName i = MN i "hole"
150151
152+qshow :: Fails -> String
153+qshow fs = show (map (\ (x, y, _, _) -> (x, y)) fs)
154+
151155unify' :: Context -> Env -> TT Name -> TT Name -> StateT TState TC [(Name, TT Name)]
152−unify' ctxt env topx topy = do (u, inj, fails) <- lift $ unify ctxt env topx topy
153− addInj inj
154− case fails of
155− [] -> return u
156− err ->
157− do ps <- get
158− put (ps { problems = err ++ problems ps })
159− return []
156+unify' ctxt env topx topy =
157+ do ps <- get
158+ (u, fails) <- lift $ unify ctxt env topx topy (injective ps) (holes ps)
159+-- trace ("Unified " ++ show (topx, topy) ++ show (injective ps) ++
160+-- " " ++ show u ++ "\n" ++ qshow fails ++ "\nCurrent problems:\n"
161+-- ++ qshow (problems ps) ++ "\n" ++ show (holes ps)) $
162+ case fails of
163+-- [] -> return u
164+ err ->
165+ do ps <- get
166+ let (h, ns) = unified ps
167+ let (ns', probs') = updateProblems (context ps) (u ++ ns)
168+ (err ++ problems ps)
169+ (injective ps)
170+ (holes ps)
171+ put (ps { problems = probs',
172+ unified = (h, ns') })
173+ return u
160174
161175getName :: Monad m => String -> StateT TState m Name
162176getName tag = do ps <- get
@@ -194,6 +208,7 @@ goalAtFocus :: ProofState -> TC (Binder Type)
194208goalAtFocus ps
195209 | not $ null (holes ps) = do g <- goal (Just (head (holes ps))) (pterm ps)
196210 return (goalType g)
211+ | otherwise = error $ "No goal in " ++ show (holes ps) ++ show (pterm ps)
197212
198213goal :: Hole -> Term -> TC Goal
199214goal h tm = g [] tm where
@@ -288,6 +303,12 @@ instanceArg n ctxt env (Bind x (Hole t) sc)
288303 instances = x:is })
289304 return (Bind x (Hole t) sc)
290305
306+setinj :: Name -> RunTactic
307+setinj n ctxt env (Bind x (Hole t) sc)
308+ = do action (\ps -> let is = injective ps in
309+ ps { injective = n : is })
310+ return (Bind x (Hole t) sc)
311+
291312defer :: Name -> RunTactic
292313defer n ctxt env (Bind x (Hole t) (P nt x' ty)) | x == x' =
293314 do action (\ps -> let hs = holes ps in
@@ -322,10 +343,6 @@ regret ctxt env (Bind x (Hole t) sc) | noOccurrence x sc =
322343 return sc
323344regret ctxt env (Bind x (Hole t) _) = fail $ show x ++ " : " ++ show t ++ " is not solved"
324345
325−addInj :: [(Term, Term, Term)] -> StateT TState TC ()
326−addInj inj = do ps <- get
327− put (ps { injective = inj ++ injective ps })
328−
329346exact :: Raw -> RunTactic
330347exact guess ctxt env (Bind x (Hole ty) sc) =
331348 do (val, valty) <- lift $ check ctxt env guess
@@ -344,7 +361,7 @@ fill guess ctxt env (Bind x (Hole ty) sc) =
344361 ns <- unify' ctxt env valty ty
345362 ps <- get
346363 let (uh, uns) = unified ps
347− put (ps { unified = (uh, uns ++ ns) })
364+-- put (ps { unified = (uh, uns ++ ns) })
348365-- addLog (show (uh, uns ++ ns))
349366 return $ Bind x (Guess ty val) sc
350367fill _ _ _ _ = fail "Can't fill here."
@@ -362,22 +379,25 @@ complete_fill ctxt env (Bind x (Guess ty val) sc) =
362379 ns <- unify' ctxt env valty ty
363380 ps <- get
364381 let (uh, uns) = unified ps
365− put (ps { unified = (uh, uns ++ ns) })
382+-- put (ps { unified = (uh, uns ++ ns) })
366383 return $ Bind x (Guess ty val) sc
367384complete_fill ctxt env t = fail $ "Can't complete fill at " ++ show t
368385
369386solve :: RunTactic
370387solve ctxt env (Bind x (Guess ty val) sc)
371− | pureTerm val = do ps <- get
388+ | True = do ps <- get
372389 let (uh, uns) = unified ps
373390 action (\ps -> ps { holes = holes ps \\ [x],
374391 solved = Just (x, val),
392+-- problems = solveInProblems
393+-- x val (problems ps),
375394 -- dontunify = dontunify ps \\ [x],
376395 -- unified = (uh, uns ++ [(x, val)]),
377396 instances = instances ps \\ [x] })
378397 return $ {- Bind x (Let ty val) sc -}
379398 instantiate val (pToV x sc)
380− | otherwise = lift $ tfail $ IncompleteTerm val
399+ | otherwise = do ps <- get
400+ lift $ tfail $ IncompleteTerm val
381401solve _ _ h = do ps <- get
382402 fail $ "Not a guess " ++ show h ++ "\n" ++ show (holes ps, pterm ps)
383403
@@ -396,7 +416,7 @@ introTy ty mn ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
396416 do ns <- unify' ctxt env s tyv
397417 ps <- get
398418 let (uh, uns) = unified ps
399− put (ps { unified = (uh, uns ++ ns) })
419+-- put (ps { unified = (uh, uns ++ ns) })
400420 return $ Bind n (Lam tyv) (Bind x (Hole t') (P Bound x t'))
401421 _ -> fail "Nothing to introduce"
402422introTy ty n ctxt env _ = fail "Can't introduce here."
@@ -494,7 +514,8 @@ hnf_compute ctxt env (Bind x (Hole ty) sc) =
494514 do let ty' = hnf ctxt env ty in
495515-- trace ("HNF " ++ show (ty, ty')) $
496516 return $ Bind x (Hole ty') sc
497−
517+hnf_compute ctxt env t = return t
518+
498519check_in :: Raw -> RunTactic
499520check_in t ctxt env tm =
500521 do (val, valty) <- lift $ check ctxt env t
@@ -515,7 +536,7 @@ eval_in t ctxt env tm =
515536 return tm
516537
517538start_unify :: Name -> RunTactic
518−start_unify n ctxt env tm = do action (\ps -> ps { unified = (n, []) })
539+start_unify n ctxt env tm = do -- action (\ps -> ps { unified = (n, []) })
519540 return tm
520541
521542tmap f (a, b, c) = (f a, b, c)
@@ -524,22 +545,24 @@ solve_unified :: RunTactic
524545solve_unified ctxt env tm =
525546 do ps <- get
526547 let (_, ns) = unified ps
527− let unify = dropGiven (dontunify ps) ns
548+ let unify = dropGiven (dontunify ps) ns (holes ps)
528549 action (\ps -> ps { holes = holes ps \\ map fst unify })
529550 action (\ps -> ps { pterm = updateSolved unify (pterm ps) })
530− action (\ps -> ps { injective = map (tmap (updateSolved unify)) (injective ps) })
531551 return (updateSolved unify tm)
532552 where
533553
534−dropGiven du [] = []
535−dropGiven du ((n, P Bound t ty) : us) | n `elem` du && not (t `elem` du)
536− = (t, P Bound n ty) : dropGiven du us
537−dropGiven du (u@(n, _) : us) | n `elem` du = dropGiven du us
554+dropGiven du [] hs = []
555+dropGiven du ((n, P Bound t ty) : us) hs
556+ | n `elem` du && not (t `elem` du)
557+ && n `elem` hs && t `elem` hs
558+ = (t, P Bound n ty) : dropGiven du us hs
559+dropGiven du (u@(n, _) : us) hs
560+ | n `elem` du = dropGiven du us hs
538561-- dropGiven du (u@(_, P a n ty) : us) | n `elem` du = dropGiven du us
539−dropGiven du (u : us) = u : dropGiven du us
562+dropGiven du (u : us) hs = u : dropGiven du us hs
540563
541564updateSolved xs x = -- trace ("Updating " ++ show xs ++ " in " ++ show x) $
542− updateSolved' xs x
565+ updateSolved' xs x
543566updateSolved' xs (Bind n (Hole ty) t)
544567 | Just v <- lookup n xs = instantiate v (pToV n (updateSolved' xs t))
545568updateSolved' xs (Bind n b t)
@@ -549,11 +572,30 @@ updateSolved' xs (P _ n _)
549572 | Just v <- lookup n xs = v
550573updateSolved' xs t = t
551574
552−updateProblems ns [] = []
553−updateProblems ns ((x, y, env, err) : ps) =
575+updateEnv ns [] = []
576+updateEnv ns ((n, b) : env) = (n, fmap (updateSolved ns) b) : updateEnv ns env
577+
578+updateError ns (CantUnify b l r e xs sc)
579+ = CantUnify b (updateSolved ns l) (updateSolved ns r) (updateError ns e) xs sc
580+updateError ns e = e
581+
582+solveInProblems x val [] = []
583+solveInProblems x val ((l, r, env, err) : ps)
584+ = ((instantiate val (pToV x l), instantiate val (pToV x r),
585+ updateEnv [(x, val)] env, err) : solveInProblems x val ps)
586+
587+updateProblems ctxt ns ps inj holes = up ns ps where
588+ up ns [] = (ns, [])
589+ up ns ((x, y, env, err) : ps) =
554590 let x' = updateSolved ns x
555− y' = updateSolved ns y in
556− (x',y',env,err) : updateProblems ns ps
591+ y' = updateSolved ns y
592+ err' = updateError ns err
593+ env' = updateEnv ns env in
594+ case unify ctxt env' x' y' inj holes of
595+ OK (v, []) -> -- trace ("Added " ++ show v ++ " from " ++ show (x', y')) $
596+ up (ns ++ v) ps
597+ _ -> let (ns', ps') = up ns ps in
598+ (ns', (x',y',env',err') : ps')
557599
558600processTactic :: Tactic -> ProofState -> TC (ProofState, String)
559601processTactic QED ps = case holes ps of
@@ -568,18 +610,16 @@ processTactic Undo ps = case previous ps of
568610 Just pold -> return (pold, "")
569611processTactic EndUnify ps
570612 = let (h, ns_in) = unified ps
571− ns = dropGiven (dontunify ps) ns_in
613+ ns = dropGiven (dontunify ps) ns_in (holes ps)
572614 ns' = map (\ (n, t) -> (n, updateSolved ns t)) ns
573− tm' = -- trace ("Updating " ++ show ns') $ -- ++ " in " ++ show (pterm ps)) $
574− updateSolved ns' (pterm ps)
575− probs' = updateProblems ns' (problems ps) in
576− case probs' of
577− [] -> return (ps { pterm = tm',
578− unified = (h, []),
579− injective = map (tmap (updateSolved ns'))
580− (injective ps),
581− holes = holes ps \\ map fst ns' }, "")
582− errs@((_,_,_,err):_) -> tfail err
615+ (ns'', probs') = updateProblems (context ps) ns' (problems ps)
616+ (injective ps) (holes ps)
617+ tm' = -- trace ("Updating " ++ show ns' ++ "\n" ++ show ns'') $ -- ++ " in " ++ show (pterm ps)) $
618+ updateSolved ns'' (pterm ps) in
619+ return (ps { pterm = tm',
620+ unified = (h, []),
621+ problems = probs',
622+ holes = holes ps \\ map fst ns'' }, "")
583623processTactic (Reorder n) ps
584624 = do ps' <- execStateT (tactic (Just n) reorder_claims) ps
585625 return (ps' { previous = Just ps, plog = "" }, plog ps')
@@ -590,9 +630,21 @@ processTactic t ps
590630 let pterm' = case solved ps' of
591631 Just s -> updateSolved [s] (pterm ps')
592632 _ -> pterm ps'
593− return (ps' { pterm = pterm',
633+ let (ns', probs')
634+ = case solved ps' of
635+ Just s -> updateProblems (context ps')
636+ [s] (problems ps')
637+ (injective ps')
638+ (holes ps')
639+ _ -> ([], problems ps')
640+ -- rechecking problems may find more solutions, so
641+ -- apply them here
642+ let pterm'' = updateSolved ns' pterm'
643+ return (ps' { pterm = pterm'',
594644 solved = Nothing,
595− previous = Just ps, plog = "" }, plog ps')
645+ problems = probs',
646+ previous = Just ps, plog = "",
647+ holes = holes ps' \\ (map fst ns')}, plog ps')
596648
597649process :: Tactic -> Name -> StateT TState TC ()
598650process EndUnify _
@@ -624,5 +676,6 @@ process t h = tactic (Just h) (mktac t)
624676 mktac (Defer n) = defer n
625677 mktac (DeferType n t a) = deferType n t a
626678 mktac (Instance n) = instanceArg n
679+ mktac (SetInjective n) = setinj n
627680 mktac (MoveLast n) = movelast n
628681
src/Core/TT.hs+7−3
@@ -482,7 +482,7 @@ data Datatype n = Data { d_typename :: n,
482482 deriving (Show, Functor, Eq)
483483
484484instance Eq n => Eq (TT n) where
485− (==) (P xt x _) (P yt y _) = xt == yt && x == y
485+ (==) (P xt x _) (P yt y _) = x == y
486486 (==) (V x) (V y) = x == y
487487 (==) (Bind _ xb xs) (Bind _ yb ys) = xb == yb && xs == ys
488488 (==) (App fx ax) (App fy ay) = fx == fy && ax == ay
@@ -794,13 +794,17 @@ showEnv' env t dbg = se 10 env t where
794794
795795-- Check whether a term has any holes in it - impure if so
796796
797−pureTerm :: TT n -> Bool
797+pureTerm :: TT Name -> Bool
798798pureTerm (App f a) = pureTerm f && pureTerm a
799−pureTerm (Bind n b sc) = pureBinder b && pureTerm sc where
799+pureTerm (Bind n b sc) = notClassName n && pureBinder b && pureTerm sc where
800800 pureBinder (Hole _) = False
801801 pureBinder (Guess _ _) = False
802802 pureBinder (Let t v) = pureTerm t && pureTerm v
803803 pureBinder t = pureTerm (binderTy t)
804+
805+ notClassName (MN _ "class") = False
806+ notClassName _ = True
807+
804808pureTerm _ = True
805809
806810-- weaken a term by adding i to each de Bruijn index (i.e. lift it over i bindings)
src/Core/Typecheck.hs+3−1
@@ -68,7 +68,9 @@ check' holes ctxt env top = chk env top where
6868 let fty' = case uniqueBinders (map fst env) (finalise fty) of
6969 ty@(Bind x (Pi s) t) -> ty
7070 _ -> uniqueBinders (map fst env)
71− $ hnf ctxt env fty
71+ $ case hnf ctxt env fty of
72+ ty@(Bind x (Pi s) t) -> ty
73+ _ -> normalise ctxt env fty
7274 case fty' of
7375 Bind x (Pi s) t ->
7476-- trace ("Converting " ++ show aty ++ " and " ++ show s ++
src/Core/Unify.hs+109−44
@@ -20,25 +20,29 @@ import Debug.Trace
2020type Injs = [(TT Name, TT Name, TT Name)]
2121type Fails = [(TT Name, TT Name, Env, Err)]
2222
23−data UInfo = UI Int Injs Fails
23+data UInfo = UI Int Fails
2424 deriving Show
2525
26−unify :: Context -> Env -> TT Name -> TT Name -> TC ([(Name, TT Name)],
27− Injs, Fails)
28−unify ctxt env topx topy =
29−-- trace ("Unifying " ++ show (topx, topy)) $
26+data UResult a = UOK a
27+ | UPartOK a
28+ | UFail Err
29+
30+unify :: Context -> Env -> TT Name -> TT Name -> [Name] -> [Name] ->
31+ TC ([(Name, TT Name)], Fails)
32+unify ctxt env topx topy injtc holes =
33+-- trace ("Unifying " ++ show (topx, topy)) $
3034 -- don't bother if topx and topy are different at the head
31− case runStateT (un False [] topx topy) (UI 0 [] []) of
32− OK (v, UI _ inj []) -> return (filter notTrivial v, inj, [])
33−-- Error e@(CantUnify False _ _ _ _ _) -> tfail e
35+ case runStateT (un False [] topx topy) (UI 0 []) of
36+ OK (v, UI _ []) -> return (filter notTrivial v, [])
3437 res ->
3538 let topxn = normalise ctxt env topx
3639 topyn = normalise ctxt env topy in
3740-- trace ("Unifying " ++ show (topx, topy) ++ "\n\n==>\n" ++ show (topxn, topyn) ++ "\n\n" ++ show res ++ "\n\n") $
3841 case runStateT (un False [] topxn topyn)
39− (UI 0 [] []) of
40− OK (v, UI _ inj fails) ->
41− return (filter notTrivial v, inj, reverse fails)
42+ (UI 0 []) of
43+ OK (v, UI _ fails) ->
44+ return (filter notTrivial v, reverse fails)
45+-- Error e@(CantUnify False _ _ _ _ _) -> tfail e
4246 Error e -> tfail e
4347 where
4448 notTrivial (x, P _ x' _) = x /= x'
@@ -50,21 +54,22 @@ unify ctxt env topx topy =
5054
5155 injective (P (DCon _ _) _ _) = True
5256 injective (P (TCon _ _) _ _) = True
57+ injective (P _ n _) = n `elem` injtc
5358 injective (App f a) = injective f
5459 injective _ = False
5560
5661 notP (P _ _ _) = False
5762 notP _ = True
5863
59− sc i = do UI s x f <- get
60− put (UI (s+i) x f)
64+ sc i = do UI s f <- get
65+ put (UI (s+i) f)
6166
62− uplus u1 u2 = do UI s i f <- get
67+ uplus u1 u2 = do UI s f <- get
6368 r <- u1
64− UI s _ f' <- get
69+ UI s f' <- get
6570 if (length f == length f')
6671 then return r
67− else do put (UI s i f); u2
72+ else do put (UI s f); u2
6873
6974 un :: Bool -> [(Name, Name)] -> TT Name -> TT Name ->
7075 StateT UInfo
@@ -89,34 +94,53 @@ unify ctxt env topx topy =
8994 = unifyFail topx topy
9095 un' fn names topx@(P (TCon _ _) x _) topy@(P (DCon _ _) y _)
9196 = unifyFail topx topy
92− un' fn bnames (P Bound x _) (P Bound y _)
93− | (x,y) `elem` bnames = do sc 1; return []
94− un' fn bnames (P Bound x _) tm
95− | holeIn env x = do UI s i f <- get
97+ un' fn bnames tx@(P _ x _) ty@(P _ y _)
98+ | (x,y) `elem` bnames || x == y = do sc 1; return []
99+ | injective tx && not (holeIn env y || y `elem` holes)
100+ = unifyFail tx ty
101+ | injective ty && not (holeIn env x || x `elem` holes)
102+ = unifyFail tx ty
103+ un' fn bnames xtm@(P _ x _) tm
104+ | holeIn env x || x `elem` holes
105+ = do UI s f <- get
96106 -- injectivity check
97− when (notP tm && fn) $
107+ if (notP tm && fn)
98108-- trace (show (x, tm, normalise ctxt env tm)) $
99− put (UI s ((tm, topx, topy) : i) f)
100− sc 1
101− checkCycle (x, tm)
102− un' fn bnames tm (P Bound y _)
103− | holeIn env y = do UI s i f <- get
109+-- put (UI s ((tm, topx, topy) : i) f)
110+ then unifyTmpFail xtm tm
111+ else do sc 1
112+ checkCycle (x, tm)
113+ | not (injective xtm) && injective tm = unifyFail xtm tm
114+ un' fn bnames tm ytm@(P _ y _)
115+ | holeIn env y || y `elem` holes
116+ = do UI s f <- get
104117 -- injectivity check
105− when (notP tm && fn) $
118+ if (notP tm && fn)
106119-- trace (show (y, tm, normalise ctxt env tm)) $
107− put (UI s ((tm, topx, topy) : i) f)
108− sc 1
109− checkCycle (y, tm)
110− un' fn bnames (V i) (P Bound x _)
120+-- put (UI s ((tm, topx, topy) : i) f)
121+ then unifyTmpFail tm ytm
122+ else do sc 1
123+ checkCycle (y, tm)
124+ | not (injective ytm) && injective tm = unifyFail ytm tm
125+ un' fn bnames (V i) (P _ x _)
111126 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
112− un' fn bnames (P Bound x _) (V i)
127+ un' fn bnames (P _ x _) (V i)
113128 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
114129
115− un' fn bnames appx@(App fx ax) appy@(App fy ay)
116− = do let (headx, _) = unApply fx
117− let (heady, _) = unApply fy
118− checkHeads headx heady
119− uplus -- do the second one if the first adds any errors
130+ un' fn bnames appx@(App fx ax) appy@(App fy ay)
131+ | injective fx && metavarApp appy
132+ || injective fy && metavarApp appx
133+ || injective fx && injective fy
134+ || fx == fy
135+ = do let (headx, _) = unApply fx
136+ let (heady, _) = unApply fy
137+ -- fail quickly if the heads are disjoint
138+ checkHeads headx heady
139+-- if True then -- (injective fx || injective fy || fx == fy) then
140+-- if (injective fx && metavarApp appy) ||
141+-- (injective fy && metavarApp appx) ||
142+-- (injective fx && injective fy) || fx == fy
143+ uplus
120144 (do hf <- un' True bnames fx fy
121145 let ax' = hnormalise hf ctxt env (substNames hf ax)
122146 let ay' = hnormalise hf ctxt env (substNames hf ay)
@@ -129,8 +153,17 @@ unify ctxt env topx topy =
129153 hf <- un' False bnames fx' fy'
130154 sc 1
131155 combine bnames hf ha)
156+ | otherwise
157+ = do let (headx, argsx) = unApply appx
158+ let (heady, argsy) = unApply appy
159+ if (length argsx == length argsy &&
160+ ((headx == heady) || (argsx == argsy) ||
161+ (notFn headx && notFn heady))) then
162+ do uf <- un' True bnames headx heady
163+ unArgs uf argsx argsy
164+ else unifyTmpFail appx appy
132165 where hnormalise [] _ _ t = t
133− hnormalise ns ctxt env t = normalise ctxt env t
166+ hnormalise ns ctxt env t = hnf ctxt env t
134167 checkHeads (P (DCon _ _) x _) (P (DCon _ _) y _)
135168 | x /= y = unifyFail appx appy
136169 checkHeads (P (TCon _ _) x _) (P (TCon _ _) y _)
@@ -141,6 +174,25 @@ unify ctxt env topx topy =
141174 = unifyFail appx appy
142175 checkHeads _ _ = return []
143176
177+ unArgs as [] [] = return as
178+ unArgs as (x : xs) (y : ys)
179+ = do let x' = hnormalise as ctxt env (substNames as x)
180+ let y' = hnormalise as ctxt env (substNames as y)
181+ as' <- un' False bnames x' y'
182+ vs <- combine bnames as as'
183+ unArgs vs xs ys
184+
185+ metavarApp tm = let (f, args) = unApply tm in
186+ all (\x -> metavar x || notFn x) (f : args)
187+ metavar t = case t of
188+ P _ x _ -> x `elem` holes || holeIn env x
189+ _ -> False
190+ inenv t = case t of
191+ P _ x _ -> x `elem` (map fst env)
192+ _ -> False
193+
194+ notFn t = injective t || metavar t || inenv t
195+
144196 un' fn bnames x (Bind n (Lam t) (App y (P Bound n' _)))
145197 | n == n' = un' False bnames x y
146198 un' fn bnames (Bind n (Lam t) (App x (P Bound n' _))) y
@@ -155,20 +207,28 @@ unify ctxt env topx topy =
155207 combine bnames h1 h2
156208 un' fn bnames x y
157209 | OK True <- convEq' ctxt x y = do sc 1; return []
158− | otherwise = do UI s i f <- get
210+ | otherwise = do UI s f <- get
159211 let r = recoverable x y
160212 let err = CantUnify r
161213 topx topy (CantUnify r x y (Msg "") [] s) (errEnv env) s
162214 if (not r) then lift $ tfail err
163− else do put (UI s i ((x, y, env, err) : f))
215+ else do put (UI s ((x, y, env, err) : f))
164216 return [] -- lift $ tfail err
165217
218+ unifyTmpFail x y
219+ = do UI s f <- get
220+ let r = recoverable x y
221+ let err = CantUnify r
222+ topx topy (CantUnify r x y (Msg "") [] s) (errEnv env) s
223+ put (UI s ((x, y, env, err) : f))
224+ return []
225+
166226 -- shortcut failure, if we *know* nothing can fix it
167− unifyFail x y = do UI s i f <- get
227+ unifyFail x y = do UI s f <- get
168228 let r = recoverable x y
169229 let err = CantUnify r
170230 topx topy (CantUnify r x y (Msg "") [] s) (errEnv env) s
171− put (UI s i ((x, y, env, err) : f))
231+ put (UI s ((x, y, env, err) : f))
172232 lift $ tfail err
173233
174234
@@ -186,12 +246,12 @@ unify ctxt env topx topy =
186246 uB bnames (Pi tx) (Pi ty) = do sc 1; un' False bnames tx ty
187247 uB bnames (Hole tx) (Hole ty) = un' False bnames tx ty
188248 uB bnames (PVar tx) (PVar ty) = un' False bnames tx ty
189− uB bnames x y = do UI s i f <- get
249+ uB bnames x y = do UI s f <- get
190250 let r = recoverable (binderTy x) (binderTy y)
191251 let err = CantUnify r topx topy
192252 (CantUnify r (binderTy x) (binderTy y) (Msg "") [] s)
193253 (errEnv env) s
194− put (UI s i ((binderTy x, binderTy y, env, err) : f))
254+ put (UI s ((binderTy x, binderTy y, env, err) : f))
195255 return [] -- lift $ tfail err
196256
197257 checkCycle p@(x, P _ _ _) = return [p]
@@ -199,6 +259,11 @@ unify ctxt env topx topy =
199259 | not (x `elem` freeNames tm) = return [(x, tm)]
200260 | otherwise = lift $ tfail (InfiniteUnify x tm (errEnv env))
201261
262+ combineArgs bnames args = ca [] args where
263+ ca acc [] = return acc
264+ ca acc (x : xs) = do x' <- combine bnames acc x
265+ ca x' xs
266+
202267 combine bnames as [] = return as
203268 combine bnames as ((n, t) : bs)
204269 = case lookup n as of
src/IRTS/CodegenJavaScript.hs+169−181
@@ -1,10 +1,5 @@
11{-# LANGUAGE PatternGuards #-}
22
3−{-
4− BigInteger Javascript code taken from:
5− https://github.com/peterolson/BigInteger.js
6−-}
7−
83module IRTS.CodegenJavaScript (codegenJavaScript) where
94
105import Idris.AbsSyntax
@@ -19,11 +14,10 @@ import Util.System
1914import Control.Arrow
2015import Data.Char
2116import Data.List
17+import qualified Data.Map as Map
2218import System.IO
2319
24−type NamespaceName = String
25−
26−idrNamespace :: NamespaceName
20+idrNamespace :: String
2721idrNamespace = "__IDR__"
2822
2923codegenJavaScript
@@ -31,10 +25,14 @@ codegenJavaScript
3125 -> FilePath
3226 -> OutputType
3327 -> IO ()
34−codegenJavaScript definitions filename outputType =
35− writeFile filename output
28+codegenJavaScript definitions filename outputType = do
29+ path <- getDataDir
30+ idrRuntime <- readFile (path ++ "/js/Runtime.js")
31+ writeFile filename (idrRuntime ++ modules ++ functions ++ mainLoop)
3632 where
3733 def = map (first translateNamespace) definitions
34+
35+ functions = concatMap translateDeclaration def
3836
3937 mainLoop :: String
4038 mainLoop = intercalate "\n" [ "\nfunction main() {"
@@ -42,115 +40,72 @@ codegenJavaScript definitions filename outputType =
4240 , "}\n\nmain();\n"
4341 ]
4442
45− output :: String
46− output = concat [ idrRuntime
47− , concatMap (translateModule Nothing) def
48− , mainLoop
49− ]
50−
51−idrRuntime :: String
52−idrRuntime =
53− createModule Nothing idrNamespace $ concat
54− [ "__IDR__.Type = function(type) { this.type = type; };"
55− , "__IDR__.Int = new __IDR__.Type('Int');"
56− , "__IDR__.Char = new __IDR__.Type('Char');"
57− , "__IDR__.String = new __IDR__.Type('String');"
58− , "__IDR__.Integer = new __IDR__.Type('Integer');"
59− , "__IDR__.Float = new __IDR__.Type('Float');"
60− , "__IDR__.Forgot = new __IDR__.Type('Forgot');"
61−
62− , "__IDR__.bigInt=function(){var e=1e7,t=7,n={positive:!1,negative:!0},r=function(e,t){var n=e.value,r=t.value,i=n.length>r.length?n.length:r.length;for(var s=0;s<i;s++)n[s]=n[s]||0,r[s]=r[s]||0;for(var s=i-1;s>=0;s--){if(n[s]!==0||r[s]!==0)break;n.pop(),r.pop()}n.length||(n=[0],r=[0]),e.value=n,t.value=r},i=function(e,s){if(typeof e=='object')return e;e+='';var u=n.positive,a=[];e[0]==='-'&&(u=n.negative,e=e.slice(1));var e=e.split('e');if(e.length>2)throw new Error('Invalid integer');if(e[1]){var f=e[1];f[0]==='+'&&(f=f.slice(1)),f=i(f);if(f.lesser(0))throw new Error('Cannot include negative exponent part for integers');while(f.notEquals(0))e[0]+='0',f=f.prev()}e=e[0],e==='-0'&&(e='0');var l=/^([1-9][0-9]*)$|^0$/.test(e);if(!l)throw new Error('Invalid integer');while(e.length){var c=e.length>t?e.length-t:0;a.push(+e.slice(c)),e=e.slice(0,c)}var h=o(a,u);return s&&r(s,h),h},s=function(e,t){var e=o(e,n.positive),t=o(t,n.positive);if(e.equals(0))throw new Error('Cannot divide by 0');var r=0;do{var i=1,s=o(e.value,n.positive),u=s.times(10);while(u.lesser(t))s=u,i*=10,u=u.times(10);while(s.lesserOrEquals(t))t=t.minus(s),r+=i}while(e.lesserOrEquals(t));return{remainder:t.value,result:r}},o=function(f,l){var c={value:f,sign:l},h={value:f,sign:l,negate:function(e){var t=e||c;return o(t.value,!t.sign)},abs:function(e){var t=e||c;return o(t.value,n.positive)},add:function(t,s){var u,a=c,f;s?(a=i(t))&&(f=i(s)):f=i(t,a),u=a.sign;if(a.sign!==f.sign)return a=o(a.value,n.positive),f=o(f.value,n.positive),u===n.positive?h.subtract(a,f):h.subtract(f,a);r(a,f);var l=a.value,p=f.value,d=[],v=0;for(var m=0;m<l.length||v>0;m++){var g=l[m]+p[m]+v;v=g>e?1:0,g-=v*e,d.push(g)}return o(d,u)},plus:function(e,t){return h.add(e,t)},subtract:function(t,r){var s=c,u;r?(s=i(t))&&(u=i(r)):u=i(t,s);if(s.sign!==u.sign)return h.add(s,h.negate(u));if(s.sign===n.negative)return h.subtract(h.negate(u),h.negate(s));if(h.compare(s,u)===-1)return h.negate(h.subtract(u,s));var a=s.value,f=u.value,l=[],p=0;for(var d=0;d<a.length;d++){a[d]-=p,p=a[d]<f[d]?1:0;var v=p*e+a[d]-f[d];l.push(v)}return o(l,n.positive)},minus:function(e,t){return h.subtract(e,t)},multiply:function(t,n){var r,s=c,u;n?(s=i(t))&&(u=i(n)):u=i(t,s),r=s.sign!==u.sign;var a=s.value,f=u.value,l=[];for(var h=0;h<a.length;h++){l[h]=[];var p=h;while(p--)l[h].push(0)}var d=0;for(var h=0;h<a.length;h++){var v=a[h];for(var p=0;p<f.length||d>0;p++){var m=f[p],g=m?v*m+d:d;d=g>e?Math.floor(g/e):0,g-=d*e,l[h].push(g)}}var y=-1;for(var h=0;h<l.length;h++){var b=l[h].length;b>y&&(y=b)}var w=[],d=0;for(var h=0;h<y||d>0;h++){var E=d;for(var p=0;p<l.length;p++)E+=l[p][h]||0;d=E>e?Math.floor(E/e):0,E-=d*e,w.push(E)}return o(w,r)},times:function(e,t){return h.multiply(e,t)},divmod:function(e,t){var r,u=c,a;t?(u=i(e))&&(a=i(t)):a=i(e,u),r=u.sign!==a.sign;if(o(u.value,u.sign).equals(0))return{quotient:o([0],n.positive),remainder:o([0],n.positive)};if(a.equals(0))throw new Error('Cannot divide by zero');var f=u.value,l=a.value,h=[],p=[];for(var d=f.length-1;d>=0;d--){var e=[f[d]].concat(p),v=s(l,e);h.push(v.result),p=v.remainder}return h.reverse(),{quotient:o(h,r),remainder:o(p,u.sign)}},divide:function(e,t){return h.divmod(e,t).quotient},over:function(e,t){return h.divide(e,t)},mod:function(e,t){return h.divmod(e,t).remainder},pow:function(e,t){var n=c,r;t?(n=i(e))&&(r=i(t)):r=i(e,n);var s=n,f=r;if(f.lesser(0))return u;if(f.equals(0))return a;var l=o(s.value,s.sign);if(f.mod(2).equals(0)){var h=l.pow(f.over(2));return h.times(h)}return l.times(l.pow(f.minus(1)))},next:function(e){var t=e||c;return h.add(t,1)},prev:function(e){var t=e||c;return h.subtract(t,1)},compare:function(e,t){var s=c,o;t?(s=i(e))&&(o=i(t,s)):o=i(e,s),r(s,o);if(s.value.length===1&&o.value.length===1&&s.value[0]===0&&o.value[0]===0)return 0;if(o.sign!==s.sign)return s.sign===n.positive?1:-1;var u=s.sign===n.positive?1:-1,a=s.value,f=o.value;for(var l=a.length-1;l>=0;l--){if(a[l]>f[l])return 1*u;if(f[l]>a[l])return-1*u}return 0},compareAbs:function(e,t){var r=c,s;return t?(r=i(e))&&(s=i(t,r)):s=i(e,r),r.sign=s.sign=n.positive,h.compare(r,s)},equals:function(e,t){return h.compare(e,t)===0},notEquals:function(e,t){return!h.equals(e,t)},lesser:function(e,t){return h.compare(e,t)<0},greater:function(e,t){return h.compare(e,t)>0},greaterOrEquals:function(e,t){return h.compare(e,t)>=0},lesserOrEquals:function(e,t){return h.compare(e,t)<=0},isPositive:function(e){var t=e||c;return t.sign===n.positive},isNegative:function(e){var t=e||c;return t.sign===n.negative},isEven:function(e){var t=e||c;return t.value[0]%2===0},isOdd:function(e){var t=e||c;return t.value[0]%2===1},toString:function(r){var i=r||c,s='',o=i.value.length;while(o--)s+=(e.toString()+i.value[o]).slice(-t);while(s[0]==='0')s=s.slice(1);s.length||(s='0');var u=i.sign===n.positive?'':'-';return u+s},toJSNumber:function(e){return+h.toString(e)},valueOf:function(e){return h.toJSNumber(e)}};return h},u=o([0],n.positive),a=o([1],n.positive),f=o([1],n.negative),l=function(e){return typeof e=='undefined'?u:i(e)};return l.zero=u,l.one=a,l.minusOne=f,l}();typeof module!='undefined'&&(module.exports=__IDR__.bigInt);"
63−
64− , "__IDR__.Tailcall = function(f) { this.f = f };"
65−
66− , "__IDR__.Con = function(i,name,vars)"
67− , "{this.i = i;this.name = name;this.vars = vars;};\n"
68−
69− , "__IDR__.tailcall = function(f){\n"
70− ++ "var __f = f;\n"
71− ++ "while (__f) {\n"
72− ++ "var f = __f;\n"
73− ++ "__f = null;\n"
74− ++ "var ret = f();\n"
75− ++ "if (ret instanceof __IDR__.Tailcall) {\n"
76− ++ "__f = ret.f;"
77− ++ "\n} else {\n"
78− ++ "return ret;"
79− ++ "\n}"
80− ++ "\n}"
81− ++ "\n};\n"
82−
83− , "var newline_regex =/(.*)\\n$/;\n"
84−
85− , "__IDR__.print = function(s){\n"
86− ++ "var m = s.match(newline_regex);\n"
87− ++ "console.log(m ? m[1] : s);"
88− ++ "\n};\n"
89− ]
90−
91−createModule :: Maybe String -> NamespaceName -> String -> String
92−createModule toplevel modname body =
93− concat [header modname, body, footer modname]
94− where
95− header :: NamespaceName -> String
96− header modname =
97− concatMap (++ "\n")
98− [ "\nvar " ++ modname ++ ";"
99− , "(function(" ++ modname ++ "){"
100− ]
101−
102− footer :: NamespaceName -> String
103− footer modname =
104− let m = maybe "" (++ ".") toplevel ++ modname in
105− "\n})("
106− ++ m
107− ++ " || ("
108− ++ m
109− ++ " = {})"
110− ++ ");\n"
111−
112−translateModule :: Maybe String -> ([String], SDecl) -> String
113−translateModule toplevel ([modname], decl) =
114− let body = translateDeclaration modname decl in
115− createModule toplevel modname body
116−translateModule toplevel (n:ns, decl) =
117− createModule toplevel n $ translateModule (Just n) (ns, decl)
43+ modules =
44+ concatMap allocMod mods
45+ where
46+ allocMod m = intercalate "." m ++ " = {};\n"
47+ sortMods a b = compare (length a) (length b)
48+
49+ mods =
50+ drop 1 $ sortBy sortMods $ nub $ concatMap (inits . fst) def
11851
11952translateIdentifier :: String -> String
12053translateIdentifier =
121− concatMap replaceBadChars
54+ replaceReserved . concatMap replaceBadChars
12255 where replaceBadChars :: Char -> String
123− replaceBadChars ' ' = "_"
124− replaceBadChars '_' = "__"
125− replaceBadChars '@' = "_at"
126− replaceBadChars '[' = "_OSB"
127− replaceBadChars ']' = "_CSB"
128− replaceBadChars '(' = "_OP"
129− replaceBadChars ')' = "_CP"
130− replaceBadChars '{' = "_OB"
131− replaceBadChars '}' = "_CB"
132− replaceBadChars '!' = "_bang"
133− replaceBadChars '#' = "_hash"
134− replaceBadChars '.' = "_dot"
135− replaceBadChars ',' = "_comma"
136− replaceBadChars ':' = "_colon"
137− replaceBadChars '+' = "_plus"
138− replaceBadChars '-' = "_minus"
139− replaceBadChars '*' = "_times"
140− replaceBadChars '<' = "_lt"
141− replaceBadChars '>' = "_gt"
142− replaceBadChars '=' = "_eq"
143− replaceBadChars '|' = "_pipe"
144− replaceBadChars '&' = "_amp"
145− replaceBadChars '/' = "_SL"
146− replaceBadChars '\\' = "_BSL"
147− replaceBadChars '%' = "_per"
148− replaceBadChars '?' = "_que"
149− replaceBadChars '~' = "_til"
150− replaceBadChars '\'' = "_apo"
15156 replaceBadChars c
57+ | ' ' <- c = "_"
58+ | '_' <- c = "__"
15259 | isDigit c = "_" ++ [c] ++ "_"
60+ | not (isLetter c && isAscii c) = '_' : show (ord c)
15361 | otherwise = [c]
62+ replaceReserved s
63+ | s `elem` reserved = '_' : s
64+ | otherwise = s
65+ reserved = [ "break"
66+ , "case"
67+ , "catch"
68+ , "continue"
69+ , "debugger"
70+ , "default"
71+ , "delete"
72+ , "do"
73+ , "else"
74+ , "finally"
75+ , "for"
76+ , "function"
77+ , "if"
78+ , "in"
79+ , "instanceof"
80+ , "new"
81+ , "return"
82+ , "switch"
83+ , "this"
84+ , "throw"
85+ , "try"
86+ , "typeof"
87+ , "var"
88+ , "void"
89+ , "while"
90+ , "with"
91+
92+ , "class"
93+ , "enum"
94+ , "export"
95+ , "extends"
96+ , "import"
97+ , "super"
98+
99+ , "implements"
100+ , "interface"
101+ , "let"
102+ , "package"
103+ , "private"
104+ , "protected"
105+ , "public"
106+ , "static"
107+ , "yield"
108+ ]
154109
155110translateNamespace :: Name -> [String]
156111translateNamespace (UN _) = [idrNamespace]
@@ -162,42 +117,36 @@ translateName (UN name) = translateIdentifier name
162117translateName (NS name _) = translateName name
163118translateName (MN i name) = translateIdentifier name ++ show i
164119
165−translateQualifiedName :: Name -> String
166−translateQualifiedName name =
167− intercalate "." (translateNamespace name) ++ "." ++ translateName name
168−
169120translateConstant :: Const -> String
170121translateConstant (I i) = show i
171−translateConstant (BI i) = "__IDR__.bigInt('" ++ show i ++ "')"
122+translateConstant (BI i) = "__IDRRT__.bigInt('" ++ show i ++ "')"
172123translateConstant (Fl f) = show f
173124translateConstant (Ch c) = show c
174125translateConstant (Str s) = show s
175−translateConstant IType = "__IDR__.Int"
176−translateConstant ChType = "__IDR__.Char"
177−translateConstant StrType = "__IDR__.String"
178−translateConstant BIType = "__IDR__.Integer"
179−translateConstant FlType = "__IDR__.Float"
180−translateConstant Forgot = "__IDR__.Forgot"
126+translateConstant IType = "__IDRRT__.Int"
127+translateConstant ChType = "__IDRRT__.Char"
128+translateConstant StrType = "__IDRRT__.String"
129+translateConstant BIType = "__IDRRT__.Integer"
130+translateConstant FlType = "__IDRRT__.Float"
131+translateConstant Forgot = "__IDRRT__.Forgot"
181132translateConstant c =
182133 "(function(){throw 'Unimplemented Const: " ++ show c ++ "';})()"
183134
184135translateParameterlist =
185136 map translateParameter
186− where translateParameter (MN i name) = name ++ show i
187− translateParameter (UN name) = name
137+ where translateParameter (MN i name) = translateIdentifier name ++ show i
138+ translateParameter (UN name) = translateIdentifier name
188139
189−translateDeclaration :: NamespaceName -> SDecl -> String
190−translateDeclaration modname (SFun name params stackSize body) =
191− modname
192− ++ "."
193− ++ translateName name
140+translateDeclaration :: ([String], SDecl) -> String
141+translateDeclaration (path, SFun name params stackSize body) =
142+ intercalate "." (path ++ [translateName name])
194143 ++ " = function("
195144 ++ intercalate "," p
196145 ++ "){\n"
197146 ++ concatMap assignVar (zip [0..] p)
198147 ++ concatMap allocVar [numP..(numP+stackSize-1)]
199148 ++ "return "
200− ++ translateExpression modname body
149+ ++ translateExpression body
201150 ++ ";\n};\n"
202151 where
203152 numP :: Int
@@ -216,32 +165,32 @@ translateVariableName :: LVar -> String
216165translateVariableName (Loc i) =
217166 "__var_" ++ show i
218167
219−translateExpression :: NamespaceName -> SExp -> String
220−translateExpression modname (SLet name value body) =
168+translateExpression :: SExp -> String
169+translateExpression (SLet name value body) =
221170 "(function("
222171 ++ translateVariableName name
223172 ++ "){\nreturn "
224− ++ translateExpression modname body
173+ ++ translateExpression body
225174 ++ ";\n})("
226− ++ translateExpression modname value
175+ ++ translateExpression value
227176 ++ ")"
228177
229−translateExpression _ (SConst cst) =
178+translateExpression (SConst cst) =
230179 translateConstant cst
231180
232−translateExpression _ (SV var) =
181+translateExpression (SV var) =
233182 translateVariableName var
234183
235−translateExpression modname (SApp False name vars) =
184+translateExpression (SApp False name vars) =
236185 createTailcall $ translateFunctionCall name vars
237186
238−translateExpression modname (SApp True name vars) =
239− "new __IDR__.Tailcall("
187+translateExpression (SApp True name vars) =
188+ "new __IDRRT__.Tailcall("
240189 ++ "function(){\n"
241190 ++ "return " ++ translateFunctionCall name vars
242191 ++ ";\n});"
243192
244−translateExpression _ (SOp op vars)
193+translateExpression (SOp op vars)
245194 | LPlus <- op
246195 , (lhs:rhs:_) <- vars = translateBinaryOp "+" lhs rhs
247196 | LMinus <- op
@@ -329,13 +278,13 @@ translateExpression _ (SOp op vars)
329278 | LIntStr <- op
330279 , (arg:_) <- vars = "String(" ++ translateVariableName arg ++ ")"
331280 | LIntBig <- op
332− , (arg:_) <- vars = "__IDR__.bigint(" ++ translateVariableName arg ++ ")"
281+ , (arg:_) <- vars = "__IDRRT__.bigInt(" ++ translateVariableName arg ++ ")"
333282 | LBigInt <- op
334283 , (arg:_) <- vars = translateVariableName arg ++ ".valueOf()"
335284 | LBigStr <- op
336285 , (arg:_) <- vars = translateVariableName arg ++ ".toString()"
337286 | LStrBig <- op
338− , (arg:_) <- vars = "__IDR__.bigint(" ++ translateVariableName arg ++ ")"
287+ , (arg:_) <- vars = "__IDRRT__.bigInt(" ++ translateVariableName arg ++ ")"
339288 | LFloatStr <- op
340289 , (arg:_) <- vars = "String(" ++ translateVariableName arg ++ ")"
341290 | LStrFloat <- op
@@ -394,78 +343,117 @@ translateExpression _ (SOp op vars)
394343 ++ f
395344 ++ translateVariableName rhs
396345
397−translateExpression _ (SError msg) =
346+translateExpression (SError msg) =
398347 "(function(){throw \'" ++ msg ++ "\';})();"
399348
400−translateExpression _ (SForeign _ _ "putStr" [(FString, var)]) =
401− "__IDR__.print(" ++ translateVariableName var ++ ");"
349+translateExpression (SForeign _ _ "putStr" [(FString, var)]) =
350+ "__IDRRT__.print(" ++ translateVariableName var ++ ");"
402351
403−translateExpression _ (SForeign _ _ fun args) =
404− fun
405− ++ "("
406− ++ intercalate "," (map (translateVariableName . snd) args)
407− ++ ");"
352+translateExpression (SForeign _ _ fun args)
353+ | "." `isPrefixOf` fun, "[]=" `isSuffixOf` fun
354+ , (obj:idx:val:[]) <- args =
355+ concat [object obj, field, index idx, assign val]
408356
409−translateExpression modname (SChkCase var cases) =
357+ | "." `isPrefixOf` fun, "[]" `isSuffixOf` fun
358+ , (obj:idx:[]) <- args =
359+ concat [object obj, field, index idx]
360+
361+ | "." `isPrefixOf` fun, "=" `isSuffixOf` fun
362+ , (obj:val:[]) <- args =
363+ concat [object obj, field, assign val]
364+
365+ | "." `isPrefixOf` fun
366+ , (obj:[]) <- args =
367+ object obj ++ field
368+
369+ | "." `isPrefixOf` fun
370+ , (obj:[(FUnit, _)]) <- args =
371+ concat [object obj, method, "()"]
372+
373+ | "." `isPrefixOf` fun
374+ , (obj:as) <- args =
375+ concat [object obj, method, arguments as]
376+
377+ | "[]=" == fun
378+ , (idx:val:[]) <- args =
379+ concat [array, index idx, assign val]
380+
381+ | "[]" == fun
382+ , (idx:[]) <- args =
383+ array ++ index idx
384+
385+ | otherwise = fun ++ arguments args
386+ where
387+ name = filter (`notElem` "[]=") fun
388+ method = name
389+ field = name
390+ array = name
391+ object o = translateVariableName (snd o)
392+ index i = "[" ++ translateVariableName (snd i) ++ "]"
393+ assign v = '=' : translateVariableName (snd v)
394+ arguments as =
395+ '(' : intercalate "," (map (translateVariableName . snd) as) ++ ")"
396+
397+translateExpression (SChkCase var cases) =
410398 "(function(e){\n"
411− ++ intercalate " else " (map (translateCase modname "e") cases)
399+ ++ intercalate " else " (map (translateCase "e") cases)
412400 ++ "\n})("
413401 ++ translateVariableName var
414402 ++ ")"
415403
416−translateExpression modname (SCase var cases) =
404+translateExpression (SCase var cases) =
417405 "(function(e){\n"
418− ++ intercalate " else " (map (translateCase modname "e") cases)
406+ ++ intercalate " else " (map (translateCase "e") cases)
419407 ++ "\n})("
420408 ++ translateVariableName var
421409 ++ ")"
422410
423−translateExpression _ (SCon i name vars) =
424− concat [ "new __IDR__.Con("
411+translateExpression (SCon i name vars) =
412+ concat [ "new __IDRRT__.Con("
425413 , show i
426− , ","
427− , '\'' : translateQualifiedName name ++ "\',["
414+ , ",["
428415 , intercalate "," $ map translateVariableName vars
429416 , "])"
430417 ]
431418
432−translateExpression modname (SUpdate var e) =
433− translateVariableName var ++ " = " ++ translateExpression modname e
419+translateExpression (SUpdate var e) =
420+ translateVariableName var ++ " = " ++ translateExpression e
434421
435−translateExpression modname (SProj var i) =
422+translateExpression (SProj var i) =
436423 translateVariableName var ++ ".vars[" ++ show i ++"]"
437424
438−translateExpression _ SNothing = "null"
425+translateExpression SNothing = "null"
439426
440−translateExpression _ e =
427+translateExpression e =
441428 "(function(){throw 'Not yet implemented: "
442429 ++ filter (/= '\'') (show e)
443430 ++ "';})()"
444431
445−translateCase :: String -> String -> SAlt -> String
446−translateCase modname _ (SDefaultCase e) =
447− createIfBlock "true" (translateExpression modname e)
432+translateCase :: String -> SAlt -> String
433+translateCase _ (SDefaultCase e) =
434+ createIfBlock "true" (translateExpression e)
448435
449−translateCase modname var (SConstCase ty e)
436+translateCase var (SConstCase ty e)
450437 | ChType <- ty = matchHelper "Char"
451438 | StrType <- ty = matchHelper "String"
452439 | IType <- ty = matchHelper "Int"
453440 | BIType <- ty = matchHelper "Integer"
454441 | FlType <- ty = matchHelper "Float"
442+ | PtrType <- ty = matchHelper "Pointer"
455443 | Forgot <- ty = matchHelper "Forgot"
456444 where
457− matchHelper tyName = translateTypeMatch modname var tyName e
445+ matchHelper tyName = translateTypeMatch var tyName e
458446
459−translateCase modname var (SConstCase cst@(BI _) e) =
447+translateCase var (SConstCase cst@(BI _) e) =
460448 let cond = var ++ ".equals(" ++ translateConstant cst ++ ")" in
461− createIfBlock cond (translateExpression modname e)
449+ createIfBlock cond (translateExpression e)
462450
463−translateCase modname var (SConstCase cst e) =
451+translateCase var (SConstCase cst e) =
464452 let cond = var ++ " == " ++ translateConstant cst in
465− createIfBlock cond (translateExpression modname e)
453+ createIfBlock cond (translateExpression e)
466454
467−translateCase modname var (SConCase a i name vars e) =
468− let isCon = var ++ " instanceof __IDR__.Con"
455+translateCase var (SConCase a i name vars e) =
456+ let isCon = var ++ " instanceof __IDRRT__.Con"
469457 isI = show i ++ " == " ++ var ++ ".i"
470458 params = intercalate "," $ map (("__var_" ++) . show) [a..(a+length vars)]
471459 args = ".apply(this," ++ var ++ ".vars)"
@@ -474,13 +462,13 @@ translateCase modname var (SConCase a i name vars e) =
474462 ++ params
475463 ++ "){\nreturn " ++ b ++ "\n})" ++ args
476464 cond = intercalate " && " [isCon, isI] in
477− createIfBlock cond $ f (translateExpression modname e)
465+ createIfBlock cond $ f (translateExpression e)
478466
479−translateTypeMatch :: String -> String -> String -> SExp -> String
480−translateTypeMatch modname var ty exp =
481− let e = translateExpression modname exp in
467+translateTypeMatch :: String -> String -> SExp -> String
468+translateTypeMatch var ty exp =
469+ let e = translateExpression exp in
482470 createIfBlock (var
483− ++ " instanceof __IDR__.Type && "
471+ ++ " instanceof __IDRRT__.Type && "
484472 ++ var ++ ".type == '"++ ty ++"'") e
485473
486474
@@ -490,7 +478,7 @@ createIfBlock cond e =
490478 ++ ";\n}"
491479
492480createTailcall call =
493− "__IDR__.tailcall(function(){return " ++ call ++ "})"
481+ "__IDRRT__.tailcall(function(){return " ++ call ++ "})"
494482
495483translateFunctionCall name vars =
496484 concat (intersperse "." $ translateNamespace name)
src/IRTS/Compiler.hs+3−3
@@ -73,7 +73,7 @@ compile target f tm
7373 Bytecode -> liftIO $ dumpBC c f
7474 ToJavaScript -> liftIO $ codegenJavaScript c f outty
7575 Error e -> fail $ show e
76− where checkMVs = do i <- get
76+ where checkMVs = do i <- getIState
7777 case idris_metavars i \\ primDefs of
7878 [] -> return ()
7979 ms -> fail $ "There are undefined metavariables: " ++ show ms
@@ -91,7 +91,7 @@ irMain tm = do i <- ir tm
9191
9292allNames :: [Name] -> Name -> Idris [Name]
9393allNames ns n | n `elem` ns = return []
94−allNames ns n = do i <- get
94+allNames ns n = do i <- getIState
9595 case lookupCtxt Nothing n (idris_callgraph i) of
9696 [ns'] -> do more <- mapM (allNames (n:ns)) (map fst (calls ns'))
9797 return (nub (n : concat more))
@@ -193,7 +193,7 @@ instance ToIR (TT Name) where
193193 | (P (DCon t a) n _, args) <- unApply tm
194194 = irCon env t a n args
195195 | (P _ n _, args) <- unApply tm
196− = do i <- get
196+ = do i <- getIState
197197 args' <- mapM (ir' env) args
198198 case getPrim i n args' of
199199 Just tm -> return tm
src/Idris/AbsSyntax.hs+92−92
@@ -26,57 +26,57 @@ import Util.Pretty
2626
2727
2828getContext :: Idris Context
29−getContext = do i <- get; return (tt_ctxt i)
29+getContext = do i <- getIState; return (tt_ctxt i)
3030
3131getObjectFiles :: Idris [FilePath]
32−getObjectFiles = do i <- get; return (idris_objs i)
32+getObjectFiles = do i <- getIState; return (idris_objs i)
3333
3434addObjectFile :: FilePath -> Idris ()
35−addObjectFile f = do i <- get; put (i { idris_objs = f : idris_objs i })
35+addObjectFile f = do i <- getIState; putIState $ i { idris_objs = f : idris_objs i }
3636
3737getLibs :: Idris [String]
38−getLibs = do i <- get; return (idris_libs i)
38+getLibs = do i <- getIState; return (idris_libs i)
3939
4040addLib :: String -> Idris ()
41−addLib f = do i <- get; put (i { idris_libs = f : idris_libs i })
41+addLib f = do i <- getIState; putIState $ i { idris_libs = f : idris_libs i }
4242
4343addHdr :: String -> Idris ()
44−addHdr f = do i <- get; put (i { idris_hdrs = f : idris_hdrs i })
44+addHdr f = do i <- getIState; putIState $ i { idris_hdrs = f : idris_hdrs i }
4545
4646totcheck :: (FC, Name) -> Idris ()
47−totcheck n = do i <- get; put (i { idris_totcheck = idris_totcheck i ++ [n] })
47+totcheck n = do i <- getIState; putIState $ i { idris_totcheck = idris_totcheck i ++ [n] }
4848
4949setFlags :: Name -> [FnOpt] -> Idris ()
50−setFlags n fs = do i <- get; put (i { idris_flags = addDef n fs (idris_flags i) })
50+setFlags n fs = do i <- getIState; putIState $ i { idris_flags = addDef n fs (idris_flags i) }
5151
5252setAccessibility :: Name -> Accessibility -> Idris ()
5353setAccessibility n a
54− = do i <- get
54+ = do i <- getIState
5555 let ctxt = setAccess n a (tt_ctxt i)
56− put (i { tt_ctxt = ctxt })
56+ putIState $ i { tt_ctxt = ctxt }
5757
5858setTotality :: Name -> Totality -> Idris ()
5959setTotality n a
60− = do i <- get
60+ = do i <- getIState
6161 let ctxt = setTotal n a (tt_ctxt i)
62− put (i { tt_ctxt = ctxt })
62+ putIState $ i { tt_ctxt = ctxt }
6363
6464getTotality :: Name -> Idris Totality
6565getTotality n
66− = do i <- get
66+ = do i <- getIState
6767 case lookupTotal n (tt_ctxt i) of
6868 [t] -> return t
6969 _ -> return (Total [])
7070
7171addToCG :: Name -> CGInfo -> Idris ()
7272addToCG n cg
73− = do i <- get
74− put (i { idris_callgraph = addDef n cg (idris_callgraph i) })
73+ = do i <- getIState
74+ putIState $ i { idris_callgraph = addDef n cg (idris_callgraph i) }
7575
7676addDocStr :: Name -> String -> Idris ()
7777addDocStr n doc
78− = do i <- get
79− put (i { idris_docstrings = addDef n doc (idris_docstrings i) })
78+ = do i <- getIState
79+ putIState $ i { idris_docstrings = addDef n doc (idris_docstrings i) }
8080
8181addToCalledG :: Name -> [Name] -> Idris ()
8282addToCalledG n ns = return () -- TODO
@@ -87,13 +87,13 @@ addToCalledG n ns = return () -- TODO
8787
8888addInstance :: Bool -> Name -> Name -> Idris ()
8989addInstance int n i
90− = do ist <- get
90+ = do ist <- getIState
9191 case lookupCtxt Nothing n (idris_classes ist) of
9292 [CI a b c d ins] ->
9393 do let cs = addDef n (CI a b c d (addI i ins)) (idris_classes ist)
94− put (ist { idris_classes = cs })
94+ putIState $ ist { idris_classes = cs }
9595 _ -> do let cs = addDef n (CI (MN 0 "none") [] [] [] [i]) (idris_classes ist)
96− put (ist { idris_classes = cs })
96+ putIState $ ist { idris_classes = cs }
9797 where addI i ins | int = i : ins
9898 | chaser n = ins ++ [i]
9999 | otherwise = insI i ins
@@ -107,45 +107,45 @@ addInstance int n i
107107
108108addClass :: Name -> ClassInfo -> Idris ()
109109addClass n i
110− = do ist <- get
110+ = do ist <- getIState
111111 let i' = case lookupCtxt Nothing n (idris_classes ist) of
112112 [c] -> c { class_instances = class_instances i }
113113 _ -> i
114− put (ist { idris_classes = addDef n i' (idris_classes ist) })
114+ putIState $ ist { idris_classes = addDef n i' (idris_classes ist) }
115115
116116addIBC :: IBCWrite -> Idris ()
117117addIBC ibc@(IBCDef n)
118− = do i <- get
118+ = do i <- getIState
119119 when (notDef (ibc_write i)) $
120− put (i { ibc_write = ibc : ibc_write i })
120+ putIState $ i { ibc_write = ibc : ibc_write i }
121121 where notDef [] = True
122122 notDef (IBCDef n': is) | n == n' = False
123123 notDef (_ : is) = notDef is
124−addIBC ibc = do i <- get; put (i { ibc_write = ibc : ibc_write i })
124+addIBC ibc = do i <- getIState; putIState $ i { ibc_write = ibc : ibc_write i }
125125
126126clearIBC :: Idris ()
127−clearIBC = do i <- get; put (i { ibc_write = [] })
127+clearIBC = do i <- getIState; putIState $ i { ibc_write = [] }
128128
129129getHdrs :: Idris [String]
130−getHdrs = do i <- get; return (idris_hdrs i)
130+getHdrs = do i <- getIState; return (idris_hdrs i)
131131
132132setErrLine :: Int -> Idris ()
133−setErrLine x = do i <- get;
133+setErrLine x = do i <- getIState;
134134 case (errLine i) of
135− Nothing -> put (i { errLine = Just x })
135+ Nothing -> putIState $ i { errLine = Just x }
136136 Just _ -> return ()
137137
138138clearErr :: Idris ()
139−clearErr = do i <- get
140− put (i { errLine = Nothing })
139+clearErr = do i <- getIState
140+ putIState $ i { errLine = Nothing }
141141
142142getSO :: Idris (Maybe String)
143−getSO = do i <- get
143+getSO = do i <- getIState
144144 return (compiled_so i)
145145
146146setSO :: Maybe String -> Idris ()
147−setSO s = do i <- get
148− put (i { compiled_so = s })
147+setSO s = do i <- getIState
148+ putIState $ (i { compiled_so = s })
149149
150150getIState :: Idris IState
151151getIState = get
@@ -154,9 +154,9 @@ putIState :: IState -> Idris ()
154154putIState = put
155155
156156getName :: Idris Int
157−getName = do i <- get;
157+getName = do i <- getIState;
158158 let idx = idris_name i;
159− put (i { idris_name = idx + 1 })
159+ putIState $ (i { idris_name = idx + 1 })
160160 return idx
161161
162162checkUndefined :: FC -> Name -> Idris ()
@@ -175,24 +175,24 @@ isUndefined fc n
175175 _ -> return True
176176
177177setContext :: Context -> Idris ()
178−setContext ctxt = do i <- get; put (i { tt_ctxt = ctxt } )
178+setContext ctxt = do i <- getIState; putIState $ (i { tt_ctxt = ctxt } )
179179
180180updateContext :: (Context -> Context) -> Idris ()
181−updateContext f = do i <- get; put (i { tt_ctxt = f (tt_ctxt i) } )
181+updateContext f = do i <- getIState; putIState $ (i { tt_ctxt = f (tt_ctxt i) } )
182182
183183addConstraints :: FC -> (Int, [UConstraint]) -> Idris ()
184184addConstraints fc (v, cs)
185− = do i <- get
185+ = do i <- getIState
186186 let ctxt = tt_ctxt i
187187 let ctxt' = ctxt { uconstraints = cs ++ uconstraints ctxt,
188188 next_tvar = v }
189189 let ics = zip cs (repeat fc) ++ idris_constraints i
190− put (i { tt_ctxt = ctxt', idris_constraints = ics })
190+ putIState $ i { tt_ctxt = ctxt', idris_constraints = ics }
191191
192192addDeferred :: [(Name, Type)] -> Idris ()
193193addDeferred ns = do mapM_ (\(n, t) -> updateContext (addTyDecl n (tidyNames [] t))) ns
194− i <- get
195− put (i { idris_metavars = map fst ns ++ idris_metavars i })
194+ i <- getIState
195+ putIState $ i { idris_metavars = map fst ns ++ idris_metavars i }
196196 where tidyNames used (Bind (MN i x) b sc)
197197 = let n' = uniqueName (UN x) used in
198198 Bind n' b $ tidyNames (n':used) sc
@@ -202,8 +202,8 @@ addDeferred ns = do mapM_ (\(n, t) -> updateContext (addTyDecl n (tidyNames [] t
202202 tidyNames used b = b
203203
204204solveDeferred :: Name -> Idris ()
205−solveDeferred n = do i <- get
206− put (i { idris_metavars = idris_metavars i \\ [n] })
205+solveDeferred n = do i <- getIState
206+ putIState $ i { idris_metavars = idris_metavars i \\ [n] }
207207
208208iputStrLn :: String -> Idris ()
209209iputStrLn = liftIO . putStrLn
@@ -212,164 +212,164 @@ iWarn :: FC -> String -> Idris ()
212212iWarn fc err = liftIO $ putStrLn (show fc ++ ":" ++ err)
213213
214214setLogLevel :: Int -> Idris ()
215−setLogLevel l = do i <- get
215+setLogLevel l = do i <- getIState
216216 let opts = idris_options i
217217 let opt' = opts { opt_logLevel = l }
218− put (i { idris_options = opt' } )
218+ putIState $ i { idris_options = opt' }
219219
220220setCmdLine :: [Opt] -> Idris ()
221−setCmdLine opts = do i <- get
221+setCmdLine opts = do i <- getIState
222222 let iopts = idris_options i
223− put (i { idris_options = iopts { opt_cmdline = opts } })
223+ putIState $ i { idris_options = iopts { opt_cmdline = opts } }
224224
225225getDumpDefun :: Idris (Maybe FilePath)
226−getDumpDefun = do i <- get
226+getDumpDefun = do i <- getIState
227227 return $ findC (opt_cmdline (idris_options i))
228228 where findC [] = Nothing
229229 findC (DumpDefun x : _) = Just x
230230 findC (_ : xs) = findC xs
231231
232232getDumpCases :: Idris (Maybe FilePath)
233−getDumpCases = do i <- get
233+getDumpCases = do i <- getIState
234234 return $ findC (opt_cmdline (idris_options i))
235235 where findC [] = Nothing
236236 findC (DumpCases x : _) = Just x
237237 findC (_ : xs) = findC xs
238238
239239logLevel :: Idris Int
240−logLevel = do i <- get
240+logLevel = do i <- getIState
241241 return (opt_logLevel (idris_options i))
242242
243243setErrContext :: Bool -> Idris ()
244−setErrContext t = do i <- get
244+setErrContext t = do i <- getIState
245245 let opts = idris_options i
246246 let opt' = opts { opt_errContext = t }
247− put (i { idris_options = opt' })
247+ putIState $ i { idris_options = opt' }
248248
249249errContext :: Idris Bool
250−errContext = do i <- get
250+errContext = do i <- getIState
251251 return (opt_errContext (idris_options i))
252252
253253useREPL :: Idris Bool
254−useREPL = do i <- get
254+useREPL = do i <- getIState
255255 return (opt_repl (idris_options i))
256256
257257setREPL :: Bool -> Idris ()
258−setREPL t = do i <- get
258+setREPL t = do i <- getIState
259259 let opts = idris_options i
260260 let opt' = opts { opt_repl = t }
261− put (i { idris_options = opt' })
261+ putIState $ i { idris_options = opt' }
262262
263263setTarget :: Target -> Idris ()
264−setTarget t = do i <- get
264+setTarget t = do i <- getIState
265265 let opts = idris_options i
266266 let opt' = opts { opt_target = t }
267− put (i { idris_options = opt' })
267+ putIState $ i { idris_options = opt' }
268268
269269target :: Idris Target
270−target = do i <- get
270+target = do i <- getIState
271271 return (opt_target (idris_options i))
272272
273273setOutputTy :: OutputType -> Idris ()
274−setOutputTy t = do i <- get
274+setOutputTy t = do i <- getIState
275275 let opts = idris_options i
276276 let opt' = opts { opt_outputTy = t }
277− put (i { idris_options = opt' })
277+ putIState $ i { idris_options = opt' }
278278
279279outputTy :: Idris OutputType
280−outputTy = do i <- get
280+outputTy = do i <- getIState
281281 return $ opt_outputTy $ idris_options i
282282
283283verbose :: Idris Bool
284−verbose = do i <- get
284+verbose = do i <- getIState
285285 return (opt_verbose (idris_options i))
286286
287287setVerbose :: Bool -> Idris ()
288−setVerbose t = do i <- get
288+setVerbose t = do i <- getIState
289289 let opts = idris_options i
290290 let opt' = opts { opt_verbose = t }
291− put (i { idris_options = opt' })
291+ putIState $ i { idris_options = opt' }
292292
293293typeInType :: Idris Bool
294−typeInType = do i <- get
294+typeInType = do i <- getIState
295295 return (opt_typeintype (idris_options i))
296296
297297setTypeInType :: Bool -> Idris ()
298−setTypeInType t = do i <- get
298+setTypeInType t = do i <- getIState
299299 let opts = idris_options i
300300 let opt' = opts { opt_typeintype = t }
301− put (i { idris_options = opt' })
301+ putIState $ i { idris_options = opt' }
302302
303303coverage :: Idris Bool
304−coverage = do i <- get
304+coverage = do i <- getIState
305305 return (opt_coverage (idris_options i))
306306
307307setCoverage :: Bool -> Idris ()
308−setCoverage t = do i <- get
308+setCoverage t = do i <- getIState
309309 let opts = idris_options i
310310 let opt' = opts { opt_coverage = t }
311− put (i { idris_options = opt' })
311+ putIState $ i { idris_options = opt' }
312312
313313setIBCSubDir :: FilePath -> Idris ()
314−setIBCSubDir fp = do i <- get
314+setIBCSubDir fp = do i <- getIState
315315 let opts = idris_options i
316316 let opt' = opts { opt_ibcsubdir = fp }
317− put (i { idris_options = opt' })
317+ putIState $ i { idris_options = opt' }
318318
319319valIBCSubDir :: IState -> Idris FilePath
320320valIBCSubDir i = return (opt_ibcsubdir (idris_options i))
321321
322322addImportDir :: FilePath -> Idris ()
323−addImportDir fp = do i <- get
323+addImportDir fp = do i <- getIState
324324 let opts = idris_options i
325325 let opt' = opts { opt_importdirs = fp : opt_importdirs opts }
326− put (i { idris_options = opt' })
326+ putIState $ i { idris_options = opt' }
327327
328328setImportDirs :: [FilePath] -> Idris ()
329−setImportDirs fps = do i <- get
329+setImportDirs fps = do i <- getIState
330330 let opts = idris_options i
331331 let opt' = opts { opt_importdirs = fps }
332− put (i { idris_options = opt' })
332+ putIState $ i { idris_options = opt' }
333333
334334allImportDirs :: IState -> Idris [FilePath]
335335allImportDirs i = do let optdirs = opt_importdirs (idris_options i)
336336 return ("." : optdirs)
337337
338338impShow :: Idris Bool
339−impShow = do i <- get
339+impShow = do i <- getIState
340340 return (opt_showimp (idris_options i))
341341
342342setImpShow :: Bool -> Idris ()
343−setImpShow t = do i <- get
343+setImpShow t = do i <- getIState
344344 let opts = idris_options i
345345 let opt' = opts { opt_showimp = t }
346− put (i { idris_options = opt' })
346+ putIState $ i { idris_options = opt' }
347347
348348logLvl :: Int -> String -> Idris ()
349−logLvl l str = do i <- get
349+logLvl l str = do i <- getIState
350350 let lvl = opt_logLevel (idris_options i)
351351 when (lvl >= l)
352352 $ do liftIO (putStrLn str)
353− put (i { idris_log = idris_log i ++ str ++ "\n" } )
353+ putIState $ i { idris_log = idris_log i ++ str ++ "\n" }
354354
355355cmdOptType :: Opt -> Idris Bool
356−cmdOptType x = do i <- get
356+cmdOptType x = do i <- getIState
357357 return $ x `elem` opt_cmdline (idris_options i)
358358
359359iLOG :: String -> Idris ()
360360iLOG = logLvl 1
361361
362362noErrors :: Idris Bool
363−noErrors = do i <- get
363+noErrors = do i <- getIState
364364 case errLine i of
365365 Nothing -> return True
366366 _ -> return False
367367
368368setTypeCase :: Bool -> Idris ()
369−setTypeCase t = do i <- get
369+setTypeCase t = do i <- getIState
370370 let opts = idris_options i
371371 let opt' = opts { opt_typecase = t }
372− put (i { idris_options = opt' })
372+ putIState $ i { idris_options = opt' }
373373
374374
375375-- For inferring types of things
@@ -634,8 +634,8 @@ addStatics n tm ptm =
634634 let statics' = nub $ map fst statics ++
635635 filter (\x -> not (elem x dnames)) stnames
636636 let stpos = staticList statics' tm
637− i <- get
638− put (i { idris_statics = addDef n stpos (idris_statics i) })
637+ i <- getIState
638+ putIState $ i { idris_statics = addDef n stpos (idris_statics i) }
639639 addIBC (IBCStatic n)
640640 where
641641 initStatics (Bind n (Pi ty) sc) (PPi p _ _ s)
@@ -659,14 +659,14 @@ implicit syn n ptm = implicit' syn [] n ptm
659659
660660implicit' :: SyntaxInfo -> [Name] -> Name -> PTerm -> Idris PTerm
661661implicit' syn ignore n ptm
662− = do i <- get
662+ = do i <- getIState
663663 let (tm', impdata) = implicitise syn ignore i ptm
664664-- let (tm'', spos) = findStatics i tm'
665− put (i { idris_implicits = addDef n impdata (idris_implicits i) })
665+ putIState $ i { idris_implicits = addDef n impdata (idris_implicits i) }
666666 addIBC (IBCImp n)
667667 logLvl 5 ("Implicit " ++ show n ++ " " ++ show impdata)
668668-- i <- get
669−-- put (i { idris_statics = addDef n spos (idris_statics i) })
669+-- putIState $ i { idris_statics = addDef n spos (idris_statics i) }
670670 return tm'
671671
672672implicitise :: SyntaxInfo -> [Name] -> IState -> PTerm -> (PTerm, [PArg])
src/Idris/AbsSyntaxTree.hs+5−2
@@ -136,7 +136,7 @@ idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
136136
137137-- The monad for the main REPL - reading and processing files and updating
138138-- global state (hence the IO inner monad).
139−type Idris = StateT IState (InputT IO)
139+type Idris = StateT IState IO
140140
141141-- Commands in the REPL
142142
@@ -524,6 +524,7 @@ type PDo = PDo' PTerm
524524-- The priority gives a hint as to elaboration order. Best to elaborate
525525-- things early which will help give a more concrete type to other
526526-- variables, e.g. a before (interpTy a).
527+-- TODO: priority no longer serves any purpose, drop it!
527528
528529data PArg' t = PImp { priority :: Int,
529530 lazyarg :: Bool, pname :: Name, getTm :: t,
@@ -579,7 +580,9 @@ deriving instance Binary OptInfo
579580!-}
580581
581582
582−data TypeInfo = TI { con_names :: [Name], codata :: Bool }
583+data TypeInfo = TI { con_names :: [Name],
584+ codata :: Bool,
585+ param_pos :: [Int] }
583586 deriving Show
584587{-!
585588deriving instance Binary TypeInfo
src/Idris/Completion.hsnew file+143
@@ -0,0 +1,143 @@
1+module Idris.Completion (replCompletion, proverCompletion) where
2+
3+import Core.Evaluate (ctxtAlist)
4+import Core.TT
5+
6+import Idris.AbsSyntaxTree
7+
8+import Control.Monad.State.Strict
9+
10+import Data.List
11+import Data.Maybe
12+
13+import System.Console.Haskeline
14+
15+-- TODO: add specific classes of identifiers to complete, fx metavariables
16+-- | A specification of the arguments that REPL commands can take
17+data CmdArg = ExprArg -- ^ The command takes an expression
18+ | NameArg -- ^ The command takes a name
19+ | FileArg -- ^ The command takes a file
20+ | ModuleArg -- ^ The command takes a module name
21+ | OptionArg -- ^ The command takes an option
22+
23+-- | Information about how to complete the various commands
24+cmdArgs :: [(String, CmdArg)]
25+cmdArgs = [ (":t", ExprArg)
26+ , (":miss", NameArg)
27+ , (":missing", NameArg)
28+ , (":i", NameArg)
29+ , (":info", NameArg)
30+ , (":total", NameArg)
31+ , (":l", FileArg)
32+ , (":load", FileArg)
33+ , (":m", ModuleArg) -- NOTE: Argumentless form is a different command
34+ , (":p", NameArg)
35+ , (":prove", NameArg)
36+ , (":a", NameArg)
37+ , (":addproof", NameArg)
38+ , (":rmproof", NameArg)
39+ , (":showproof", NameArg)
40+ , (":c", FileArg)
41+ , (":compile", FileArg)
42+ , (":js", FileArg)
43+ , (":javascript", FileArg)
44+ , (":set", OptionArg)
45+ , (":unset", OptionArg)
46+ ]
47+commands = map fst cmdArgs
48+
49+-- | A specification of the arguments that tactics can take
50+data TacticArg = NameTArg -- ^ Names: n1, n2, n3, ... n
51+ | ExprTArg
52+ | AltsTArg
53+
54+-- | A list of available tactics and their argument requirements
55+tacticArgs :: [(String, Maybe TacticArg)]
56+tacticArgs = [ ("intro", Nothing)
57+ , ("intros", Nothing)
58+ , ("refine", Just ExprTArg)
59+ , ("rewrite", Just ExprTArg)
60+ , ("let", Nothing) -- FIXME syntax for let
61+ , ("focus", Just ExprTArg)
62+ , ("exact", Just ExprTArg)
63+ , ("reflect", Just ExprTArg)
64+ , ("try", Just AltsTArg)
65+ ] ++ map (\x -> (x, Nothing)) [
66+ "intro", "intros", "compute", "trivial", "solve", "attack",
67+ "state", "term", "undo", "qed", "abandon", ":q"
68+ ]
69+tactics = map fst tacticArgs
70+
71+-- | Convert a name into a string usable for completion. Filters out names
72+-- that users probably don't want to see.
73+nameString :: Name -> Maybe String
74+nameString (UN ('@':_)) = Nothing
75+nameString (UN ('#':_)) = Nothing
76+nameString (UN n) = Just n
77+nameString (NS n _) = nameString n
78+nameString _ = Nothing
79+
80+-- FIXME: Respect module imports
81+-- | Get the user-visible names from the current interpreter state.
82+names :: Idris[String]
83+names = do i <- get
84+ let ctxt = tt_ctxt i
85+ return $ nub $ mapMaybe (nameString . fst) $ ctxtAlist ctxt
86+
87+
88+modules :: Idris [String]
89+modules = do i <- get
90+ return $ map show $ imported i
91+
92+
93+
94+completeWith :: [String] -> String -> [Completion]
95+completeWith ns n = if uniqueExists
96+ then [simpleCompletion n]
97+ else map simpleCompletion prefixMatches
98+ where prefixMatches = filter (isPrefixOf n) ns
99+ uniqueExists = n `elem` prefixMatches
100+
101+completeName :: [String] -> String -> Idris [Completion]
102+completeName extra n = do ns <- names
103+ return $ completeWith (extra ++ ns) n
104+
105+completeExpr :: [String] -> CompletionFunc Idris
106+completeExpr extra = completeWord Nothing " \t" (completeName extra)
107+
108+completeOption :: CompletionFunc Idris
109+completeOption = completeWord Nothing " \t" completeOpt
110+ where completeOpt = return . (completeWith ["errorcontext", "showimplicits"])
111+
112+isWhitespace :: Char -> Bool
113+isWhitespace = (flip elem) " \t\n"
114+
115+-- | Get the completion function for a particular command
116+completeCmd :: String -> CompletionFunc Idris
117+completeCmd cmd (prev, next) = fromMaybe completeCmdName $ fmap completeArg $ lookup cmd cmdArgs
118+ where completeArg FileArg = completeFilename (prev, next)
119+ completeArg NameArg = completeExpr [] (prev, next) -- FIXME only complete one name
120+ completeArg OptionArg = completeOption (prev, next)
121+ completeArg ModuleArg = noCompletion (prev, next) -- FIXME do later
122+ completeArg ExprArg = completeExpr [] (prev, next)
123+ completeCmdName = return $ ("", completeWith commands cmd)
124+
125+replCompletion :: CompletionFunc Idris
126+replCompletion (prev, next) = case firstWord of
127+ ':':cmdName -> completeCmd (':':cmdName) (prev, next)
128+ _ -> completeExpr [] (prev, next)
129+ where firstWord = fst $ break isWhitespace $ dropWhile isWhitespace $ reverse prev
130+
131+
132+completeTactic :: [String] -> String -> CompletionFunc Idris
133+completeTactic as tac (prev, next) = fromMaybe completeTacName $ fmap completeArg $ lookup tac tacticArgs
134+ where completeTacName = return $ ("", completeWith tactics tac)
135+ completeArg Nothing = noCompletion (prev, next)
136+ completeArg (Just NameTArg) = noCompletion (prev, next) -- this is for binding new names!
137+ completeArg (Just ExprTArg) = completeExpr as (prev, next)
138+ completeArg (Just AltsTArg) = noCompletion (prev, next) -- TODO
139+
140+
141+proverCompletion :: [String] -> CompletionFunc Idris
142+proverCompletion assumptions (prev, next) = completeTactic assumptions firstWord (prev, next)
143+ where firstWord = fst $ break isWhitespace $ dropWhile isWhitespace $ reverse prev
src/Idris/Coverage.hs+18−16
@@ -33,23 +33,23 @@ genMissing fn args sc
3333-- covering...)
3434
3535mkPatTm :: PTerm -> Idris Term
36−mkPatTm t = do i <- get
36+mkPatTm t = do i <- getIState
3737 let timp = addImpl' True [] [] i t
3838 evalStateT (toTT timp) 0
3939 where
40− toTT (PRef _ n) = do i <- lift $ get
40+ toTT (PRef _ n) = do i <- lift getIState
4141 case lookupDef Nothing n (tt_ctxt i) of
4242 [TyDecl nt _] -> return $ P nt n Erased
4343 _ -> return $ P Ref n Erased
4444 toTT (PApp _ t args) = do t' <- toTT t
4545 args' <- mapM (toTT . getTm) args
4646 return $ mkApp t' args'
47− toTT _ = do v <- get
47+ toTT _ = do v <- get
4848 put (v + 1)
4949 return (P Bound (MN v "imp") Erased)
5050
5151mkPTerm :: Name -> [TT Name] -> Idris PTerm
52−mkPTerm f args = do i <- get
52+mkPTerm f args = do i <- getIState
5353 let fapp = mkApp (P Bound f Erased) (map eraseName args)
5454 return $ delab i fapp
5555 where eraseName (App f a) = App (eraseName f) (eraseName a)
@@ -90,7 +90,7 @@ dropDefault (c : cs) = c : dropDefault cs
9090dropDefault [] = []
9191
9292expandTree :: SC -> Idris SC
93−expandTree (Case n alts) = do i <- get
93+expandTree (Case n alts) = do i <- getIState
9494 as <- expandAlts i (dropDefault alts)
9595 (getDefault alts)
9696 alts' <- mapM expandTreeA as
@@ -110,8 +110,8 @@ expandAlts i all@(ConCase n _ _ _ : alts) def
110110 | (TyDecl c@(DCon _ arity) ty : _) <- lookupDef Nothing n (tt_ctxt i)
111111 = do let tyn = getTy n (tt_ctxt i)
112112 case lookupCtxt Nothing tyn (idris_datatypes i) of
113− (TI ns _ : _) -> do let ps = map mkPat ns
114− return $ addAlts ps (altsFor all) all
113+ (TI ns _ _: _) -> do let ps = map mkPat ns
114+ return $ addAlts ps (altsFor all) all
115115 _ -> return all
116116 where
117117 altsFor [] = []
@@ -225,7 +225,7 @@ genAll i args = case filter (/=Placeholder) $ concatMap otherPats (nub args) of
225225 let p = PApp fc (PRef fc n) (zipWith upd xs' xs)
226226 let tyn = getTy n (tt_ctxt i)
227227 case lookupCtxt Nothing tyn (idris_datatypes i) of
228− (TI ns _ : _) -> p : map (mkPat fc) (ns \\ [n])
228+ (TI ns _ _ : _) -> p : map (mkPat fc) (ns \\ [n])
229229 _ -> [p]
230230 ops fc n arg o = return Placeholder
231231
@@ -300,14 +300,14 @@ calcProd i fc n pats = do patsprod <- mapM prodRec pats
300300 cotype ty
301301 | (P _ t _, _) <- unApply (getRetTy ty)
302302 = case lookupCtxt Nothing t (idris_datatypes i) of
303− [TI _ True] -> True
303+ [TI _ True _] -> True
304304 _ -> False
305305 | otherwise = False
306306
307307calcTotality :: [Name] -> FC -> Name -> [([Name], Term, Term)]
308308 -> Idris Totality
309309calcTotality path fc n pats
310− = do i <- get
310+ = do i <- getIState
311311 let opts = case lookupCtxt Nothing n (idris_flags i) of
312312 [fs] -> fs
313313 _ -> []
@@ -370,7 +370,7 @@ checkTotality path fc n
370370 totalityError t = tclift $ tfail (At fc (Msg (show n ++ " is " ++ show t)))
371371
372372 warnPartial n t
373− = do i <- get
373+ = do i <- getIState
374374 case lookupDef Nothing n (tt_ctxt i) of
375375 [x] -> do
376376 iputStrLn $ show fc ++ ":Warning - " ++ show n ++ " is " ++ show t
@@ -399,11 +399,11 @@ checkDeclTotality (fc, n)
399399
400400buildSCG :: (FC, Name) -> Idris ()
401401buildSCG (_, n) = do
402− ist <- get
402+ ist <- getIState
403403 case lookupCtxt Nothing n (idris_callgraph ist) of
404404 [cg] -> case lookupDef Nothing n (tt_ctxt ist) of
405405 [CaseOp _ _ _ _ _ args sc _ _] ->
406− do logLvl 5 $ "Building SCG for " ++ show n ++ " from\n"
406+ do logLvl 3 $ "Building SCG for " ++ show n ++ " from\n"
407407 ++ show sc
408408 let newscg = buildSCG' ist sc args
409409 logLvl 5 $ show newscg
@@ -495,11 +495,12 @@ buildSCG' ist sc args = -- trace ("Building SCG for " ++ show sc) $
495495
496496checkSizeChange :: Name -> Idris Totality
497497checkSizeChange n = do
498− ist <- get
498+ ist <- getIState
499499 case lookupCtxt Nothing n (idris_callgraph ist) of
500500 [cg] -> do let ms = mkMultiPaths ist [] (scg cg)
501− logLvl 6 ("Multipath for " ++ show n ++ ":\n" ++
501+ logLvl 5 ("Multipath for " ++ show n ++ ":\n" ++
502502 "from " ++ show (scg cg) ++ "\n" ++
503+ show (length ms) ++ "\n" ++
503504 showSep "\n" (map show ms))
504505 logLvl 6 (show cg)
505506 -- every multipath must have an infinitely descending
@@ -507,7 +508,8 @@ checkSizeChange n = do
507508 -- also need to checks functions called are all total
508509 -- (Unchecked is okay as we'll spot problems here)
509510 let tot = map (checkMP ist (length (argsdef cg))) ms
510− logLvl 3 $ "Paths for " ++ show n ++ " yield " ++ (show tot)
511+ logLvl 4 $ "Generated " ++ show (length tot) ++ " paths"
512+ logLvl 6 $ "Paths for " ++ show n ++ " yield " ++ (show tot)
511513 return (noPartial tot)
512514 [] -> do logLvl 5 $ "No paths for " ++ show n
513515 return Unchecked
src/Idris/DataOpts.hs+2−2
@@ -48,8 +48,8 @@ forceArgs n t = do i <- getIState
4848
4949 guarded :: Term -> [Int]
5050 guarded t@(App f a)
51− | (P (TCon _ _) _ _, args) <- unApply t
52− = mapMaybe isF args ++ concatMap guarded args
51+-- | (P (TCon _ _) _ _, args) <- unApply t
52+-- = mapMaybe isF args ++ concatMap guarded args
5353 | (P (DCon _ _) _ _, args) <- unApply t
5454 = mapMaybe isF args ++ concatMap guarded args
5555 guarded t = mapMaybe isF [t]
src/Idris/ElabDecls.hs+155−50
@@ -44,7 +44,7 @@ elabType info syn doc fc opts n ty' = {- let ty' = piBind (params info) ty_in
4444 n = liftname info n_in in -}
4545 do checkUndefined fc n
4646 ctxt <- getContext
47− i <- get
47+ i <- getIState
4848 logLvl 3 $ show n ++ " pre-type " ++ showImp True ty'
4949 ty' <- implicit syn n ty'
5050 let ty = addImpl i ty'
@@ -67,7 +67,7 @@ elabType info syn doc fc opts n ty' = {- let ty' = piBind (params info) ty_in
6767 let (t, _) = unApply (getRetTy nty')
6868 let corec = case t of
6969 P _ rcty _ -> case lookupCtxt Nothing rcty (idris_datatypes i) of
70− [TI _ True] -> True
70+ [TI _ True _] -> True
7171 _ -> False
7272 _ -> False
7373 let opts' = if corec then (Coinductive : opts) else opts
@@ -91,7 +91,7 @@ elabPostulate info syn doc fc opts n ty
9191 fty <- case lookupTy Nothing n ctxt of
9292 [] -> tclift $ tfail $ (At fc (NoTypeDecl n)) -- can't happen!
9393 [ty] -> return ty
94− ist <- get
94+ ist <- getIState
9595 let (ap, _) = unApply (getRetTy fty)
9696 logLvl 5 $ "Checking collapsibility of " ++ show (ap, fty)
9797 let postOK = case ap of
@@ -110,7 +110,7 @@ elabData info syn doc fc codata (PLaterdecl n t_in)
110110 = do iLOG (show (fc, doc))
111111 checkUndefined fc n
112112 ctxt <- getContext
113− i <- get
113+ i <- getIState
114114 t_in <- implicit syn n t_in
115115 let t = addImpl i t_in
116116 ((t', defer, is), log) <- tclift $ elaborate ctxt n (TType (UVal 0)) []
@@ -126,7 +126,7 @@ elabData info syn doc fc codata (PDatadecl n t_in dcons)
126126 = do iLOG (show fc)
127127 undef <- isUndefined fc n
128128 ctxt <- getContext
129− i <- get
129+ i <- getIState
130130 t_in <- implicit syn n t_in
131131 let t = addImpl i t_in
132132 ((t', defer, is), log) <- tclift $ elaborate ctxt n (TType (UVal 0)) []
@@ -140,8 +140,11 @@ elabData info syn doc fc codata (PDatadecl n t_in dcons)
140140 when undef $ updateContext (addTyDecl n cty)
141141 cons <- mapM (elabCon info syn n codata) dcons
142142 ttag <- getName
143− i <- get
144− put (i { idris_datatypes = addDef n (TI (map fst cons) codata)
143+ i <- getIState
144+ let as = map (const Nothing) (getArgTys cty)
145+ let params = findParams (zip as (repeat True)) (map snd cons)
146+ logLvl 2 $ "Parameters : " ++ show params
147+ putIState (i { idris_datatypes = addDef n (TI (map fst cons) codata params)
145148 (idris_datatypes i) })
146149 addIBC (IBCDef n)
147150 addIBC (IBCData n)
@@ -150,13 +153,42 @@ elabData info syn doc fc codata (PDatadecl n t_in dcons)
150153 collapseCons n cons
151154 updateContext (addDatatype (Data n ttag cty cons))
152155 mapM_ (checkPositive n) cons
156+ where
157+ -- parameters are names which are unchanged across the structure,
158+ -- which appear exactly once in the return type of a constructor
159+ findParams :: [(Maybe Name, Bool)] -> [Type] -> [Int]
160+ findParams ps [] = mapMaybe (\ ((x, y), n) ->
161+ if y then Just n else Nothing)
162+ (zip ps [0..])
163+ findParams ps (t : ts) = findParams (updateParams ps t) ts
164+
165+ updateParams ps (Bind n (Pi t) sc)
166+ = updateParams (updateParams ps (instantiate (P Bound n t) sc)) t
167+ updateParams ps tm@(App f a)
168+ | (P _ fn _, args) <- unApply tm
169+ = if fn == n
170+ then updateParamsA ps args (tail args)
171+ else updateParams (updateParams ps f) a
172+ | otherwise = updateParams (updateParams ps f) a
173+ updateParams ps _ = ps
174+
175+ updateParamsA ((mn, _) : ns) (p@(P _ n' _) : args) all
176+ | n' `elem` concatMap freeNames all
177+ = (mn, False) : updateParamsA ns args (p : all)
178+ updateParamsA ((Nothing, b) : ns) (p@(P _ n' _) : args) all
179+ = (Just n', b) : updateParamsA ns args (p : all)
180+ updateParamsA ((Just p, b) : ns) (tm@(P _ n' _) : args) all
181+ = (Just n', b && p == n') : updateParamsA ns args (tm : all)
182+ updateParamsA ((mn, _) : ns) (p : args) all
183+ = (mn, False) : updateParamsA ns args (p : all)
184+ updateParamsA ps args all = ps
153185
154186elabRecord :: ElabInfo -> SyntaxInfo -> String -> FC -> Name ->
155187 PTerm -> String -> Name -> PTerm -> Idris ()
156188elabRecord info syn doc fc tyn ty cdoc cn cty
157189 = do elabData info syn doc fc False (PDatadecl tyn ty [(cdoc, cn, cty, fc)])
158190 cty' <- implicit syn cn cty
159− i <- get
191+ i <- getIState
160192 cty <- case lookupTy Nothing cn (tt_ctxt i) of
161193 [t] -> return (delab i t)
162194 _ -> fail "Something went inexplicably wrong"
@@ -181,13 +213,13 @@ elabRecord info syn doc fc tyn ty cdoc cn cty
181213 isNonImp _ = Nothing
182214
183215 tryElabDecl info (fn, ty, val)
184− = do i <- get
216+ = do i <- getIState
185217 idrisCatch (do elabDecl' EAll info ty
186218 elabDecl' EAll info val)
187219 (\v -> do iputStrLn $ show fc ++
188220 ":Warning - can't generate setter for " ++
189221 show fn ++ " (" ++ show ty ++ ")"
190− put i)
222+ putIState i)
191223
192224 getImplB k (PPi (Imp l s _) n Placeholder sc)
193225 = getImplB k sc
@@ -265,7 +297,7 @@ elabCon :: ElabInfo -> SyntaxInfo -> Name -> Bool ->
265297elabCon info syn tn codata (doc, n, t_in, fc)
266298 = do checkUndefined fc n
267299 ctxt <- getContext
268− i <- get
300+ i <- getIState
269301 t_in <- implicit syn n (if codata then mkLazy t_in else t_in)
270302 let t = addImpl i t_in
271303 logLvl 2 $ show fc ++ ":Constructor " ++ show n ++ " : " ++ showImp True t
@@ -311,7 +343,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
311343 (zip [0..] cs)
312344 -- if the return type of 'ty' is collapsible, the optimised version should
313345 -- just do nothing
314− ist <- get
346+ ist <- getIState
315347 let (ap, _) = unApply (getRetTy fty)
316348 logLvl 5 $ "Checking collapsibility of " ++ show (ap, fty)
317349 -- FIXME: Really ought to only do this for total functions!
@@ -322,17 +354,17 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
322354 _ -> False
323355 _ -> False
324356 solveDeferred n
325− ist <- get
357+ ist <- getIState
326358 when doNothing $
327359 case lookupCtxt Nothing n (idris_optimisation ist) of
328360 [oi] -> do let opts = addDef n (oi { collapsible = True })
329361 (idris_optimisation ist)
330− put (ist { idris_optimisation = opts })
362+ putIState (ist { idris_optimisation = opts })
331363 _ -> do let opts = addDef n (Optimise True [] [])
332364 (idris_optimisation ist)
333− put (ist { idris_optimisation = opts })
365+ putIState (ist { idris_optimisation = opts })
334366 addIBC (IBCOpt n)
335− ist <- get
367+ ist <- getIState
336368 let pats = pats_in
337369 -- logLvl 3 (showSep "\n" (map (\ (l,r) ->
338370 -- show l ++ " = " ++
@@ -369,7 +401,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
369401 pdef' <- applyOpts optpdef
370402 logLvl 2 $ "Optimised patterns"
371403 logLvl 5 $ show pdef'
372− ist <- get
404+ ist <- getIState
373405 -- let wf = wellFounded ist n sc
374406 let tot = if pcover || AssertTotal `elem` opts
375407 then Unchecked -- finish checking later
@@ -393,8 +425,8 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
393425 logLvl 3 (show tree)
394426 logLvl 3 $ "Optimised: " ++ show tree'
395427 ctxt <- getContext
396− ist <- get
397− put (ist { idris_patdefs = addDef n pdef' (idris_patdefs ist) })
428+ ist <- getIState
429+ putIState (ist { idris_patdefs = addDef n pdef' (idris_patdefs ist) })
398430 case lookupTy (namespace info) n ctxt of
399431 [ty] -> do updateContext (addCasedef n (inlinable opts)
400432 tcase knowncovering
@@ -405,7 +437,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
405437 setTotality n tot
406438 totcheck (fc, n)
407439 when (tot /= Unchecked) $ addIBC (IBCTotal n tot)
408− i <- get
440+ i <- getIState
409441 case lookupDef Nothing n (tt_ctxt i) of
410442 (CaseOp _ _ _ _ _ scargs sc scargs' sc' : _) ->
411443 do let calls = findCalls sc' scargs'
@@ -453,7 +485,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
453485elabVal :: ElabInfo -> Bool -> PTerm -> Idris (Term, Type)
454486elabVal info aspat tm_in
455487 = do ctxt <- getContext
456− i <- get
488+ i <- getIState
457489 let tm = addImpl i tm_in
458490 logLvl 10 (showImp True tm)
459491 -- try:
@@ -478,7 +510,7 @@ elabVal info aspat tm_in
478510checkPossible :: ElabInfo -> FC -> Bool -> Name -> PTerm -> Idris Bool
479511checkPossible info fc tcgen fname lhs_in
480512 = do ctxt <- getContext
481− i <- get
513+ i <- getIState
482514 let lhs = addImpl i lhs_in
483515 -- if the LHS type checks, it is possible
484516 case elaborate ctxt (MN 0 "patLHS") infP []
@@ -505,15 +537,25 @@ elabClause info tcgen (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
505537 = do ctxt <- getContext
506538 -- Build the LHS as an "Infer", and pull out its type and
507539 -- pattern bindings
508− i <- get
509− let lhs = addImplPat i lhs_in
540+ i <- getIState
541+ -- get the parameters first, to pass through to any where block
542+ let fn_ty = case lookupTy Nothing fname (tt_ctxt i) of
543+ [t] -> t
544+ _ -> error "Can't happen (elabClause function type)"
545+ let fn_is = case lookupCtxt Nothing fname (idris_implicits i) of
546+ [t] -> t
547+ _ -> []
548+ let params = getParamsInType i [] fn_is fn_ty
549+ let lhs = addImplPat i (propagateParams params lhs_in)
510550 logLvl 5 ("LHS: " ++ show fc ++ " " ++ showImp True lhs)
551+ logLvl 4 ("Fixed parameters: " ++ show params ++ " from " ++ show (fn_ty, fn_is))
511552 ((lhs', dlhs, []), _) <-
512553 tclift $ elaborate ctxt (MN 0 "patLHS") infP []
513554 (erun fc (buildTC i info True tcgen fname (infTerm lhs)))
514555 let lhs_tm = orderPats (getInferTerm lhs')
515556 let lhs_ty = getInferType lhs'
516557 logLvl 3 ("Elaborated: " ++ show lhs_tm)
558+ logLvl 3 ("Elaborated type: " ++ show lhs_ty)
517559 (clhs, clhsty) <- recheckC fc [] lhs_tm
518560 logLvl 5 ("Checked " ++ show clhs)
519561 -- Elaborate where block
@@ -533,7 +575,7 @@ elabClause info tcgen (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
533575 logLvl 5 $ "Where block:\n " ++ show wbefore ++ "\n" ++ show wafter
534576 mapM_ (elabDecl' EAll info) wbefore
535577 -- Now build the RHS, using the type of the LHS as the goal.
536− i <- get -- new implicits from where block
578+ i <- getIState -- new implicits from where block
537579 logLvl 5 (showImp True (expandParams decorate newargs defs (defs \\ decls) rhs_in))
538580 let rhs = addImplBoundInf i (map fst newargs) (defs \\ decls)
539581 (expandParams decorate newargs defs (defs \\ decls) rhs_in)
@@ -567,7 +609,7 @@ elabClause info tcgen (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
567609 case converts ctxt [] clhsty crhsty of
568610 OK _ -> return ()
569611 Error e -> ierror (At fc (CantUnify False clhsty crhsty e [] 0))
570− i <- get
612+ i <- getIState
571613 checkInferred fc (delab' i crhs True) rhs
572614 return $ Right (clhs, crhs)
573615 where
@@ -598,11 +640,45 @@ elabClause info tcgen (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
598640 -- _ -> MN i (show n)) . l
599641 }
600642
643+ getParamsInType i env (PExp _ _ _ _ : is) (Bind n (Pi t) sc)
644+ = getParamsInType i env is (instantiate (P Bound n t) sc)
645+ getParamsInType i env (_ : is) (Bind n (Pi t) sc)
646+ = getParamsInType i (n : env) is (instantiate (P Bound n t) sc)
647+ getParamsInType i env is tm@(App f a)
648+ | (P _ tn _, args) <- unApply tm
649+ = case lookupCtxt Nothing tn (idris_datatypes i) of
650+ [t] -> nub $ paramNames args env (param_pos t) ++
651+ getParamsInType i env is f ++
652+ getParamsInType i env is a
653+ [] -> nub $ getParamsInType i env is f ++
654+ getParamsInType i env is a
655+ | otherwise = nub $ getParamsInType i env is f ++
656+ getParamsInType i env is a
657+ getParamsInType i _ _ _ = []
658+
659+ paramNames args env [] = []
660+ paramNames args env (p : ps)
661+ | length args > p = case args!!p of
662+ P _ n _ -> if n `elem` env
663+ then n : paramNames args env ps
664+ else paramNames args env ps
665+ _ -> paramNames args env ps
666+ | otherwise = paramNames args env ps
667+
668+ propagateParams :: [Name] -> PTerm -> PTerm
669+ propagateParams ps (PApp _ (PRef fc n) args)
670+ = PApp fc (PRef fc n) (map addP args)
671+ where addP imp@(PImp _ _ _ Placeholder _)
672+ | pname imp `elem` ps = imp { getTm = PRef fc (pname imp) }
673+ addP t = t
674+ propagateParams ps (PRef fc n)
675+ = PApp fc (PRef fc n) (map (\x -> pimp x (PRef fc x)) ps)
676+
601677elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
602678 = do ctxt <- getContext
603679 -- Build the LHS as an "Infer", and pull out its type and
604680 -- pattern bindings
605− i <- get
681+ i <- getIState
606682 let lhs = addImpl i lhs_in
607683 logLvl 5 ("LHS: " ++ showImp True lhs)
608684 ((lhs', dlhs, []), _) <-
@@ -655,7 +731,7 @@ elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
655731 logLvl 3 ("New function type " ++ show wtype)
656732 let wname = MN windex (show fname)
657733 let imps = getImps wtype -- add to implicits context
658− put (i { idris_implicits = addDef wname imps (idris_implicits i) })
734+ putIState (i { idris_implicits = addDef wname imps (idris_implicits i) })
659735 addIBC (IBCDef wname)
660736 def' <- checkDef fc [(wname, wtype)]
661737 addDeferred def'
@@ -673,9 +749,9 @@ elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
673749 (map (pexp . (PRef fc) . fst) bargs_pre ++
674750 pexp wval :
675751 (map (pexp . (PRef fc) . fst) bargs_post))
676− logLvl 1 ("New RHS " ++ show rhs)
752+ logLvl 5 ("New RHS " ++ showImp True rhs)
677753 ctxt <- getContext -- New context with block added
678− i <- get
754+ i <- getIState
679755 ((rhs', defer, is), _) <-
680756 tclift $ elaborate ctxt (MN 0 "wpatRHS") clhsty []
681757 (do pbinds lhs_tm
@@ -686,6 +762,7 @@ elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
686762 def' <- checkDef fc defer
687763 addDeferred def'
688764 mapM_ (elabCaseBlock info) is
765+ logLvl 5 ("Checked RHS " ++ show rhs')
689766 (crhs, crhsty) <- recheckC fc [] rhs'
690767 return $ Right (clhs, crhs)
691768 where
@@ -699,7 +776,7 @@ elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
699776 mkAuxC wname lhs ns ns' d = return $ d
700777
701778 mkAux wname toplhs ns ns' (PClause fc n tm_in (w:ws) rhs wheres)
702− = do i <- get
779+ = do i <- getIState
703780 let tm = addImpl i tm_in
704781 logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
705782 showImp True toplhs)
@@ -710,7 +787,7 @@ elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
710787 lhs <- updateLHS n wname mvars ns ns' (fullApp tm) w
711788 return $ PClause fc wname lhs ws rhs wheres
712789 mkAux wname toplhs ns ns' (PWith fc n tm_in (w:ws) wval withs)
713− = do i <- get
790+ = do i <- getIState
714791 let tm = addImpl i tm_in
715792 logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
716793 showImp True toplhs)
@@ -765,6 +842,8 @@ elabClass info syn doc fc constraints tn ps ds
765842 (filter clause ds)
766843 let (methods, imethods)
767844 = unzip (map (\ ( x,y,z) -> (x, y)) ims)
845+ let defaults = map (\ (x, (y, z)) -> (x,y)) defs
846+ addClass tn (CI cn (map nodoc imethods) defaults (map fst ps) [])
768847 -- build instance constructor type
769848 -- decorate names of functions to ensure they can't be referred
770849 -- to elsewhere in the class declaration
@@ -785,9 +864,7 @@ elabClass info syn doc fc constraints tn ps ds
785864 mapM_ (elabDecl EAll info) (concat fns)
786865 -- add the default definitions
787866 mapM_ (elabDecl EAll info) (concat (map (snd.snd) defs))
788− i <- get
789− let defaults = map (\ (x, (y, z)) -> (x,y)) defs
790− addClass tn (CI cn (map nodoc imethods) defaults (map fst ps) [])
867+ i <- getIState
791868 addIBC (IBCClass tn)
792869 where
793870 nodoc (n, (_, o, t)) = (n, (o, t))
@@ -800,7 +877,7 @@ elabClass info syn doc fc constraints tn ps ds
800877
801878 impbind [] x = x
802879 impbind ((n, ty): ns) x = PPi impl n ty (impbind ns x)
803− conbind (ty : ns) x = PPi constraint (MN 0 "c") ty (conbind ns x)
880+ conbind (ty : ns) x = PPi constraint (MN 0 "class") ty (conbind ns x)
804881 conbind [] x = x
805882
806883 getMName (PTy _ _ _ _ n _) = nsroot n
@@ -818,7 +895,7 @@ elabClass info syn doc fc constraints tn ps ds
818895 Just (syn, o, ty) -> do let ty' = insertConstraint c ty
819896 let ds = map (decorateid defaultdec)
820897 [PTy "" syn fc [] n ty',
821− PClauses fc (TCGen:o ++ opts) n cs]
898+ PClauses fc (Inlinable:TCGen:o ++ opts) n cs]
822899 iLOG (show ds)
823900 return (n, ((defaultdec n, ds!!1), ds))
824901 _ -> fail $ show n ++ " is not a method"
@@ -841,7 +918,7 @@ elabClass info syn doc fc constraints tn ps ds
841918 let ty = PPi constraint (MN 0 "pc") c con
842919 iLOG (showImp True ty)
843920 iLOG (showImp True lhs ++ " = " ++ showImp True rhs)
844− i <- get
921+ i <- getIState
845922 let conn = case con of
846923 PRef _ n -> n
847924 PApp _ (PRef _ n) _ -> n
@@ -888,7 +965,7 @@ elabClass info syn doc fc constraints tn ps ds
888965
889966 insertConstraint c (PPi p@(Imp _ _ _) n ty sc)
890967 = PPi p n ty (insertConstraint c sc)
891− insertConstraint c sc = PPi constraint (MN 0 "c") c sc
968+ insertConstraint c sc = PPi constraint (MN 0 "class") c sc
892969
893970 -- make arguments explicit and don't bind class parameters
894971 toExp ns e (PPi (Imp l s _) n ty sc)
@@ -905,10 +982,11 @@ elabInstance :: ElabInfo -> SyntaxInfo ->
905982 Maybe Name -> -- explicit name
906983 [PDecl] -> Idris ()
907984elabInstance info syn fc cs n ps t expn ds
908− = do i <- get
985+ = do i <- getIState
909986 (n, ci) <- case lookupCtxtName (namespace info) n (idris_classes i) of
910987 [c] -> return c
911988 _ -> fail $ show fc ++ ":" ++ show n ++ " is not a type class"
989+ let constraint = PApp fc (PRef fc n) (map pexp ps)
912990 let iname = case expn of
913991 Nothing -> UN ('@':show n ++ "$" ++ show ps)
914992 Just nm -> nm
@@ -945,9 +1023,7 @@ elabInstance info syn fc cs n ps t expn ds
9451023 logLvl 3 $ "Method types " ++ showSep "\n" (map (showDeclImp True . mkTyDecl) mtys)
9461024 logLvl 3 $ "Instance is " ++ show ps ++ " implicits " ++
9471025 show (concat (nub wparams))
948− let lhs = case concat (nub wparams) of
949− [] -> PRef fc iname
950− as -> PApp fc (PRef fc iname) as
1026+ let lhs = PRef fc iname
9511027 let rhs = PApp fc (PRef fc (instanceName ci))
9521028 (map (pexp . mkMethApp) mtys)
9531029 let idecls = [PClauses fc [Inlinable, TCGen] iname
@@ -955,6 +1031,10 @@ elabInstance info syn fc cs n ps t expn ds
9551031 iLOG (show idecls)
9561032 mapM (elabDecl EAll info) idecls
9571033 addIBC (IBCInstance intInst n iname)
1034+-- -- for each constraint, build a top level function to chase it
1035+-- logLvl 5 $ "Building functions"
1036+-- fns <- mapM (cfun (instanceName ci) constraint syn idecls) cs
1037+-- mapM_ (elabDecl EAll info) (concat fns)
9581038 where
9591039 intInst = case ps of
9601040 [PConstant IType] -> True
@@ -1010,7 +1090,7 @@ elabInstance info syn fc cs n ps t expn ds
10101090
10111091 mkTyDecl (n, op, t, _) = PTy "" syn fc op n t
10121092
1013− conbind (ty : ns) x = PPi constraint (MN 0 "c") ty (conbind ns x)
1093+ conbind (ty : ns) x = PPi constraint (MN 0 "class") ty (conbind ns x)
10141094 conbind [] x = x
10151095
10161096 coninsert cs (PPi p@(Imp _ _ _) n t sc) = PPi p n t (coninsert cs sc)
@@ -1046,6 +1126,31 @@ elabInstance info syn fc cs n ps t expn ds
10461126 = decorate ns iname m == decorate ns iname m'
10471127 clauseFor m iname ns _ = False
10481128
1129+{- This won't work yet. Can it ever, in this form?
1130+
1131+ cfun cn c syn all con
1132+ = do let cfn = UN ('@':'@':show cn ++ "#" ++ show con)
1133+ let mnames = take (length all) $ map (\x -> MN x "meth") [0..]
1134+ let capp = PApp fc (PRef fc cn) (map (pexp . PRef fc) mnames)
1135+ let lhs = PApp fc (PRef fc cfn) [pconst capp]
1136+ let rhs = PResolveTC (FC "HACK" 0)
1137+ let ty = PPi constraint (MN 0 "pc") c con
1138+ iLOG (showImp True ty)
1139+ iLOG (showImp True lhs ++ " = " ++ showImp True rhs)
1140+ i <- getIState
1141+ let conn = case con of
1142+ PRef _ n -> n
1143+ PApp _ (PRef _ n) _ -> n
1144+ let conn' = case lookupCtxtName Nothing conn (idris_classes i) of
1145+ [(n, _)] -> n
1146+ _ -> conn
1147+ addInstance False conn' cfn
1148+ addIBC (IBCInstance False conn' cfn)
1149+ iputStrLn ("Added " ++ show (conn, cfn, ty) ++ "\n" ++ show (lhs, rhs))
1150+ return [PTy "" syn fc [] cfn ty,
1151+ PClauses fc [Inlinable,TCGen] cfn [PClause fc cfn lhs [] rhs []]]
1152+-}
1153+
10491154decorateid decorate (PTy doc s f o n t) = PTy doc s f o (decorate n) t
10501155decorateid decorate (PClauses f o n cs)
10511156 = PClauses f o (decorate n) (map dc cs)
@@ -1109,7 +1214,7 @@ elabDecl' what info (PData doc s f co d)
11091214elabDecl' what info d@(PClauses f o n ps)
11101215 | what /= ETypes
11111216 = do iLOG $ "Elaborating clause " ++ show n
1112− i <- get -- get the type options too
1217+ i <- getIState -- get the type options too
11131218 let o' = case lookupCtxt Nothing n (idris_flags i) of
11141219 [fs] -> fs
11151220 [] -> []
@@ -1118,7 +1223,7 @@ elabDecl' what info (PMutual f ps)
11181223 = do mapM_ (elabDecl ETypes info) ps
11191224 mapM_ (elabDecl EDefns info) ps
11201225elabDecl' what info (PParams f ns ps)
1121− = do i <- get
1226+ = do i <- getIState
11221227 iLOG $ "Expanding params block with " ++ show ns ++ " decls " ++
11231228 show (concatMap tldeclared ps)
11241229 let nblock = pblock i
@@ -1151,8 +1256,8 @@ elabDecl' what info (PRecord doc s f tyn ty cdoc cn cty)
11511256 = do iLOG $ "Elaborating record " ++ show tyn
11521257 elabRecord info s doc f tyn ty cdoc cn cty
11531258elabDecl' _ info (PDSL n dsl)
1154− = do i <- get
1155− put (i { idris_dsls = addDef n dsl (idris_dsls i) })
1259+ = do i <- getIState
1260+ putIState (i { idris_dsls = addDef n dsl (idris_dsls i) })
11561261 addIBC (IBCDSL n)
11571262elabDecl' what info (PDirective i)
11581263 | what /= EDefns = i
@@ -1174,7 +1279,7 @@ checkInferred fc inf user =
11741279 do logLvl 6 $ "Checked to\n" ++ showImp True inf ++ "\n\nFROM\n\n" ++
11751280 showImp True user
11761281 logLvl 10 $ "Checking match"
1177− i <- get
1282+ i <- getIState
11781283 tclift $ case matchClause' True i user inf of
11791284 Right vs -> return ()
11801285 Left (x, y) -> tfail $ At fc
@@ -1188,7 +1293,7 @@ checkInferred fc inf user =
11881293
11891294inferredDiff :: FC -> PTerm -> PTerm -> Idris Bool
11901295inferredDiff fc inf user =
1191− do i <- get
1296+ do i <- getIState
11921297 logLvl 6 $ "Checked to\n" ++ showImp True inf ++ "\n" ++
11931298 showImp True user
11941299 tclift $ case matchClause' True i user inf of
src/Idris/ElabTerm.hs+145−59
@@ -39,6 +39,27 @@ build :: IState -> ElabInfo -> Bool -> Name -> PTerm ->
3939 ElabD (Term, [(Name, Type)], [PDecl])
4040build ist info pattern fn tm
4141 = do elab ist info pattern False fn tm
42+ ivs <- get_instances
43+ hs <- get_holes
44+ ptm <- get_term
45+ -- Resolve remaining type classes. Two passes - first to get the
46+ -- default Num instances, second to clean up the rest
47+ when (not pattern) $
48+ mapM_ (\n -> when (n `elem` hs) $
49+ do focus n
50+ try (resolveTC 7 fn ist)
51+ (movelast n)) ivs
52+ ivs <- get_instances
53+ hs <- get_holes
54+ when (not pattern) $
55+ mapM_ (\n -> when (n `elem` hs) $
56+ do focus n
57+ resolveTC 7 fn ist) ivs
58+ probs <- get_probs
59+ tm <- get_term
60+ case probs of
61+ [] -> return ()
62+ ((_,_,_,e):es) -> lift (Error e)
4263 is <- getAux
4364 tt <- get_term
4465 let (tm, ds) = runState (collectDeferred tt) []
@@ -54,6 +75,11 @@ buildTC :: IState -> ElabInfo -> Bool -> Bool -> Name -> PTerm ->
5475 ElabD (Term, [(Name, Type)], [PDecl])
5576buildTC ist info pattern tcgen fn tm
5677 = do elab ist info pattern tcgen fn tm
78+ probs <- get_probs
79+ tm <- get_term
80+ case probs of
81+ [] -> return ()
82+ ((_,_,_,e):es) -> lift (Error e)
5783 is <- getAux
5884 tt <- get_term
5985 let (tm, ds) = runState (collectDeferred tt) []
@@ -72,8 +98,6 @@ elab ist info pattern tcgen fn tm
7298 (do update_term orderPats
7399-- tm <- get_term
74100 mkPat)
75− inj <- get_inj
76− mapM_ checkInjective inj
77101 where
78102 isph arg = case getTm arg of
79103 Placeholder -> (True, priority arg)
@@ -110,11 +134,11 @@ elab ist info pattern tcgen fn tm
110134 elab' ina (PResolveTC (FC "HACK" _)) -- for chasing parent classes
111135 = resolveTC 5 fn ist
112136 elab' ina (PResolveTC fc)
113− | pattern = do c <- unique_hole (MN 0 "c")
114− instanceArg c
137+ | True = do c <- unique_hole (MN 0 "class")
138+ instanceArg c
115139 | otherwise = do g <- goal
116140 try (resolveTC 2 fn ist)
117− (do c <- unique_hole (MN 0 "c")
141+ (do c <- unique_hole (MN 0 "class")
118142 instanceArg c)
119143 elab' ina (PRefl fc t) = elab' ina (PApp fc (PRef fc eqCon) [pimp (MN 0 "a") Placeholder,
120144 pimp (MN 0 "x") t])
@@ -122,15 +146,23 @@ elab ist info pattern tcgen fn tm
122146 pimp (MN 0 "b") Placeholder,
123147 pexp l, pexp r])
124148 elab' ina@(_, a) (PPair fc l r)
125− = try (elabE (True, a) (PApp fc (PRef fc pairTy)
126− [pexp l,pexp r]))
127− (elabE (True, a) (PApp fc (PRef fc pairCon)
149+ = do hnf_compute
150+ g <- goal
151+ case g of
152+ TType _ -> elabE (True, a) (PApp fc (PRef fc pairTy)
153+ [pexp l,pexp r])
154+ _ -> elabE (True, a) (PApp fc (PRef fc pairCon)
128155 [pimp (MN 0 "A") Placeholder,
129156 pimp (MN 0 "B") Placeholder,
130− pexp l, pexp r]))
157+ pexp l, pexp r])
131158 elab' ina (PDPair fc l@(PRef _ n) t r)
132159 = case t of
133− Placeholder -> try asType asValue
160+ Placeholder ->
161+ do hnf_compute
162+ g <- goal
163+ case g of
164+ TType _ -> asType
165+ _ -> asValue
134166 _ -> asType
135167 where asType = elab' ina (PApp fc (PRef fc sigmaTy)
136168 [pexp t,
@@ -144,10 +176,14 @@ elab ist info pattern tcgen fn tm
144176 pimp (MN 0 "P") Placeholder,
145177 pexp l, pexp r])
146178 elab' ina (PAlternative True as)
147− = do ty <- goal
179+ = do hnf_compute
180+ ty <- goal
148181 ctxt <- get_context
149182 let (tc, _) = unApply ty
150183 let as' = pruneByType tc ctxt as
184+-- case as' of
185+-- [a] -> elab' ina a
186+-- as -> lift $ tfail $ CantResolveAlts (map showHd as)
151187 tryAll (zip (map (elab' ina) as') (map showHd as'))
152188 where showHd (PApp _ h _) = show h
153189 showHd x = show x
@@ -181,6 +217,7 @@ elab ist info pattern tcgen fn tm
181217 = do -- n' <- unique_hole n
182218 -- let sc' = mapPT (repN n n') sc
183219 ptm <- get_term
220+ g <- goal
184221 attack; intro (Just n);
185222 -- trace ("------ intro " ++ show n ++ " ---- \n" ++ show ptm)
186223 elabE (True, a) sc; solve
@@ -231,6 +268,7 @@ elab ist info pattern tcgen fn tm
231268 focus valn
232269 elabE (True, a) val
233270 elabE (True, a) sc
271+ ptm <- get_term
234272 solve
235273 elab' ina tm@(PApp fc (PInferRef _ f) args) = do
236274 rty <- goal
@@ -277,43 +315,58 @@ elab ist info pattern tcgen fn tm
277315 Just xs@(_:_) -> NS n xs
278316 _ -> n
279317
318+ -- if f is local, just do a simple_app
280319 elab' (ina, g) tm@(PApp fc (PRef _ f) args')
281320 = do let args = {- case lookupCtxt f (inblock info) of
282321 Just ps -> (map (pexp . (PRef fc)) ps ++ args')
283322 _ ->-} args'
284323-- newtm <- mkSpecialised ist fc f (map getTm args') tm
285− ivs <- get_instances
286− -- HACK: we shouldn't resolve type classes if we're defining an instance
287− -- function or default definition.
288− let isinf = f == inferCon || tcname f
289− ctxt <- get_context
290− let guarded = isConName Nothing f ctxt
291−-- when True
292− tryWhen True
293− (do ns <- apply (Var f) (map isph args)
324+ env <- get_env
325+ if (f `elem` map fst env && length args' == 1)
326+ then -- simple app, as below
327+ do simple_app (elabE (ina, g) (PRef fc f))
328+ (elabE (True, g) (getTm (head args')))
329+ solve
330+ else
331+ do ivs <- get_instances
332+ ps <- get_probs
333+ -- HACK: we shouldn't resolve type classes if we're defining an instance
334+ -- function or default definition.
335+ let isinf = f == inferCon || tcname f
336+ -- if f is a type class, we need to know its arguments so that
337+ -- we can unify with them
338+ case lookupCtxt Nothing f (idris_classes ist) of
339+ [] -> return ()
340+ _ -> mapM_ setInjective (map getTm args')
341+ ctxt <- get_context
342+ let guarded = isConName Nothing f ctxt
343+ ns <- apply (Var f) (map isph args)
294344 ptm <- get_term
345+ g <- goal
295346 let (ns', eargs) = unzip $
296347 sortBy (\(_,x) (_,y) ->
297348 compare (priority x) (priority y))
298349 (zip ns args)
299− tryWhen True
300− (elabArgs (ina || not isinf, guarded)
301− [] False ns' (map (\x -> (lazyarg x, getTm x)) eargs))
302− (elabArgs (ina || not isinf, guarded)
303− [] False (reverse ns')
304− (map (\x -> (lazyarg x, getTm x)) (reverse eargs)))
350+ elabArgs (ina || not isinf, guarded)
351+ [] False ns' (map (\x -> (lazyarg x, getTm x)) eargs)
305352 mkSpecialised ist fc f (map getTm args') tm
306− solve)
307− (do apply_elab f (map (toElab (ina || not isinf, guarded)) args)
308− mkSpecialised ist fc f (map getTm args') tm
309− solve)
310−-- ptm <- get_term
311−-- elog (show ptm)
312− ivs' <- get_instances
313− when (not pattern || (ina && not tcgen)) $
314− mapM_ (\n -> do focus n
315− -- let insts = filter tcname $ map fst (ctxtAlist (tt_ctxt ist))
316− resolveTC 7 fn ist) (ivs' \\ ivs)
353+ solve
354+ ptm <- get_term
355+ ivs' <- get_instances
356+ ps' <- get_probs
357+ -- Attempt to resolve any type classes which have 'complete' types,
358+ -- i.e. no holes in them
359+ when (not pattern || (ina && not tcgen && not guarded)) $
360+ mapM_ (\n -> do focus n
361+ g <- goal
362+ env <- get_env
363+ hs <- get_holes
364+ if all (\n -> not (n `elem` hs)) (freeNames g)
365+ -- let insts = filter tcname $ map fst (ctxtAlist (tt_ctxt ist))
366+ then try (resolveTC 7 fn ist)
367+ (movelast n)
368+ else movelast n)
369+ (ivs' \\ ivs)
317370 where tcArg (n, PConstraint _ _ Placeholder _) = True
318371 tcArg _ = False
319372
@@ -321,10 +374,13 @@ elab ist info pattern tcgen fn tm
321374 tacTm (PProof _) = True
322375 tacTm _ = False
323376
377+ setInjective (PRef _ n) = setinj n
378+ setInjective (PApp _ (PRef _ n) _) = setinj n
379+ setInjective _ = return ()
380+
324381 elab' ina@(_, a) (PApp fc f [arg])
325382 = erun fc $
326− do ptm <- get_term
327− simple_app (elabE ina f) (elabE (True, a) (getTm arg))
383+ do simple_app (elabE ina f) (elabE (True, a) (getTm arg))
328384 solve
329385 elab' ina Placeholder = do (h : hs) <- get_holes
330386 movelast h
@@ -436,22 +492,29 @@ pruneAlt xs = map prune xs
436492
437493-- Rule out alternatives that don't return the same type as the head of the goal
438494-- (If there are none left as a result, do nothing)
439−
440495pruneByType :: Term -> Context -> [PTerm] -> [PTerm]
441496pruneByType (P _ n _) c as
442− = let as' = filter (headIs n) as in
443− case as' of
444− [] -> as
445− _ -> as'
497+-- if the goal type is polymorphic, keep e
498+ | [] <- lookupTy Nothing n c = as
499+ | otherwise
500+ = let asV = filter (headIs True n) as
501+ as' = filter (headIs False n) as in
502+ case as' of
503+ [] -> case asV of
504+ [] -> as
505+ _ -> asV
506+ _ -> as'
446507 where
447− headIs f (PApp _ (PRef _ f') _) = typeHead f f'
448− headIs f (PApp _ f' _) = headIs f f'
449− headIs f (PPi _ _ _ sc) = headIs f sc
450− headIs _ _ = True -- keep if it's not an application
508+ headIs var f (PApp _ (PRef _ f') _) = typeHead var f f'
509+ headIs var f (PApp _ f' _) = headIs var f f'
510+ headIs var f (PPi _ _ _ sc) = headIs var f sc
511+ headIs _ _ _ = True -- keep if it's not an application
451512
452− typeHead f f' = case lookupTy Nothing f' c of
513+ typeHead var f f'
514+ = case lookupTy Nothing f' c of
453515 [ty] -> case unApply (getRetTy ty) of
454516 (P _ ftyn _, _) -> ftyn == f
517+ (V _, _) -> var -- keep, variable
455518 _ -> False
456519 _ -> False
457520
@@ -462,13 +525,20 @@ trivial ist = try' (do elab ist toplevel False False (MN 0 "tac")
462525 (PRefl (FC "prf" 0) Placeholder)
463526 return ())
464527 (do env <- get_env
465− tryAll (map fst env)
528+ g <- goal
529+ tryAll env
466530 return ()) True
467531 where
468532 tryAll [] = fail "No trivial solution"
469− tryAll (x:xs) = try' (elab ist toplevel False False
533+ tryAll ((x, b):xs)
534+ = do -- if type of x has any holes in it, move on
535+ hs <- get_holes
536+ g <- goal
537+ if all (\n -> not (n `elem` hs)) (freeNames (binderTy b))
538+ then try' (elab ist toplevel False False
470539 (MN 0 "tac") (PRef (FC "prf" 0) x))
471540 (tryAll xs) True
541+ else tryAll xs
472542
473543findInstances :: IState -> Term -> [Name]
474544findInstances ist t
@@ -483,7 +553,11 @@ resolveTC 0 fn ist = fail $ "Can't resolve type class"
483553resolveTC 1 fn ist = try' (trivial ist) (resolveTC 0 fn ist) True
484554resolveTC depth fn ist
485555 = do hnf_compute
486− try' (trivial ist)
556+ g <- goal
557+ ptm <- get_term
558+ hs <- get_holes
559+ if True -- all (\n -> not (n `elem` hs)) (freeNames g)
560+ then try' (trivial ist)
487561 (do t <- goal
488562 let insts = findInstances ist t
489563 let (tc, ttypes) = unApply t
@@ -491,17 +565,23 @@ resolveTC depth fn ist
491565 tm <- get_term
492566-- traceWhen (depth > 6) ("GOAL: " ++ show t ++ "\nTERM: " ++ show tm) $
493567-- (tryAll (map elabTC (map fst (ctxtAlist (tt_ctxt ist)))))
568+-- if scopeOnly then fail "Can't resolve" else
494569 let depth' = if scopeOnly then 2 else depth
495570 blunderbuss t depth' insts) True
571+ else do try' (trivial ist)
572+ (do g <- goal
573+ fail $ "Can't resolve " ++ show g) True
574+-- tm <- get_term
575+-- fail $ "Can't resolve yet in " ++ show tm
496576 where
497577 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
498578 | otherwise = (fail "Can't resolve", show n)
499579
500−-- needsDefault t num@(P _ (NS (UN "Num") ["builtins"]) _) [P Bound a _]
501−-- = do focus a
502−-- fill (RConstant IType) -- default Int
503−-- solve
504−-- return False
580+ needsDefault t num@(P _ (NS (UN "Num") ["Builtins"]) _) [P Bound a _]
581+ = do focus a
582+ fill (RConstant IType) -- default Int
583+ solve
584+ return False
505585 needsDefault t f as
506586 | all boundVar as = return True -- fail $ "Can't resolve " ++ show t
507587 needsDefault t f a = return False -- trace (show t) $ return ()
@@ -509,7 +589,9 @@ resolveTC depth fn ist
509589 boundVar (P Bound _ _) = True
510590 boundVar _ = False
511591
512− blunderbuss t d [] = lift $ tfail $ CantResolve t
592+ blunderbuss t d [] = do -- c <- get_env
593+ -- ps <- get_probs
594+ lift $ tfail $ CantResolve t
513595 blunderbuss t d (n:ns)
514596 | n /= fn && tcname n = try' (resolve n d)
515597 (blunderbuss t d ns) True
@@ -526,8 +608,11 @@ resolveTC depth fn ist
526608 let imps = case lookupCtxtName Nothing n (idris_implicits ist) of
527609 [] -> []
528610 [args] -> map isImp (snd args) -- won't be overloaded!
611+ ps <- get_probs
529612 args <- apply (Var n) imps
530− -- traceWhen (all boundVar ttypes) ("Progress: " ++ show t ++ " with " ++ show n) $
613+ ps' <- get_probs
614+ when (length ps < length ps') $ fail "Can't apply type class"
615+-- traceWhen (all boundVar ttypes) ("Progress: " ++ show t ++ " with " ++ show n) $
531616 mapM_ (\ (_,n) -> do focus n
532617 t' <- goal
533618 let (tc', ttype) = unApply t'
@@ -535,6 +620,7 @@ resolveTC depth fn ist
535620 resolveTC depth' fn ist)
536621 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
537622 -- if there's any arguments left, we've failed to resolve
623+ hs <- get_holes
538624 solve
539625 where isImp (PImp p _ _ _ _) = (True, p)
540626 isImp arg = (False, priority arg)
src/Idris/Error.hs+3−3
@@ -20,7 +20,7 @@ import Data.Typeable
2020iucheck :: Idris ()
2121iucheck = do tit <- typeInType
2222 when (not tit) $
23− do ist <- get
23+ do ist <- getIState
2424 idrisCatch (tclift $ ucheck (idris_constraints ist))
2525 (\e -> do let msg = show e
2626 setErrLine (getErrLine msg)
@@ -46,13 +46,13 @@ ifail :: String -> Idris ()
4646ifail str = throwIO (IErr str)
4747
4848ierror :: Err -> Idris ()
49−ierror err = do i <- get
49+ierror err = do i <- getIState
5050 throwIO (IErr $ pshow i err)
5151
5252tclift :: TC a -> Idris a
5353tclift tc = case tc of
5454 OK v -> return v
55− Error err -> do i <- get
55+ Error err -> do i <- getIState
5656 case err of
5757 At (FC f l) e -> setErrLine l
5858 _ -> return ()
src/Idris/IBC.hs+6−4
@@ -21,7 +21,7 @@ import System.Directory
2121import Paths_idris
2222
2323ibcVersion :: Word8
24−ibcVersion = 24
24+ibcVersion = 25
2525
2626data IBCFile = IBCFile { ver :: Word8,
2727 sourcefile :: FilePath,
@@ -1535,11 +1535,13 @@ instance Binary OptInfo where
15351535 return (Optimise x1 x2 x3)
15361536
15371537instance Binary TypeInfo where
1538− put (TI x1 x2) = do put x1
1539− put x2
1538+ put (TI x1 x2 x3) = do put x1
1539+ put x2
1540+ put x3
15401541 get = do x1 <- get
15411542 x2 <- get
1542− return (TI x1 x2)
1543+ x3 <- get
1544+ return (TI x1 x2 x3)
15431545
15441546instance Binary SynContext where
15451547 put x
src/Idris/Parser.hs+12−11
@@ -63,12 +63,13 @@ fixErrorMsg msg fixes = msg ++ ", possible fixes:\n" ++ (concat $ intersperse "\
6363loadModule :: FilePath -> Idris String
6464loadModule f
6565 = idrisCatch (do i <- getIState
66+ let file = takeWhile (/= ' ') f
6667 ibcsd <- valIBCSubDir i
6768 ids <- allImportDirs i
68− fp <- liftIO $ findImport ids ibcsd f
69− if f `elem` imported i
70− then iLOG $ "Already read " ++ f
71− else do putIState (i { imported = f : imported i })
69+ fp <- liftIO $ findImport ids ibcsd file
70+ if file `elem` imported i
71+ then iLOG $ "Already read " ++ file
72+ else do putIState (i { imported = file : imported i })
7273 case fp of
7374 IDR fn -> loadSource False fn
7475 LIDR fn -> loadSource True fn
@@ -78,7 +79,7 @@ loadModule f
7879 case src of
7980 IDR sfn -> loadSource False sfn
8081 LIDR sfn -> loadSource True sfn)
81− let (dir, fh) = splitFileName f
82+ let (dir, fh) = splitFileName file
8283 return (dropExtension fh))
8384 (\e -> do let msg = show e
8485 setErrLine (getErrLine msg)
@@ -110,7 +111,7 @@ loadSource lidr f
110111 v <- verbose
111112 when v $ iputStrLn $ "Type checking " ++ f
112113 elabDecls toplevel ds
113− i <- get
114+ i <- getIState
114115 -- simplify every definition do give the totality checker
115116 -- a better chance
116117 mapM_ (\n -> do logLvl 5 $ "Simplifying " ++ show n
@@ -118,7 +119,7 @@ loadSource lidr f
118119 (map snd (idris_totcheck i))
119120 -- build size change graph from simplified definitions
120121 iLOG "Totality checking"
121− i <- get
122+ i <- getIState
122123 mapM_ buildSCG (idris_totcheck i)
123124 mapM_ checkDeclTotality (idris_totcheck i)
124125 iLOG ("Finished " ++ f)
@@ -162,7 +163,7 @@ parseTac i = runParser (do t <- pTactic defaultSyntax
162163
163164parseImports :: FilePath -> String -> Idris ([String], [String], String, SourcePos)
164165parseImports fname input
165− = do i <- get
166+ = do i <- getIState
166167 case runParser (do whiteSpace
167168 mname <- pHeader
168169 ps <- many pImport
@@ -170,7 +171,7 @@ parseImports fname input
170171 pos <- getPosition
171172 return ((mname, ps, rest, pos), i)) i fname input of
172173 Left err -> fail (show err)
173− Right (x, i) -> do put i
174+ Right (x, i) -> do putIState i
174175 return x
175176
176177pHeader :: IParser [String]
@@ -275,7 +276,7 @@ pImport = do reserved "import"; f <- identifier; option ';' (lchar ';')
275276parseProg :: SyntaxInfo -> FilePath -> String -> SourcePos ->
276277 Idris [PDecl]
277278parseProg syn fname input pos
278− = do i <- get
279+ = do i <- getIState
279280 case runParser (do setPosition pos
280281 whiteSpace
281282 ps <- many (pDecl syn)
@@ -284,7 +285,7 @@ parseProg syn fname input pos
284285 return (concat ps, i')) i fname input of
285286 Left err -> do iputStrLn (show err)
286287 return []
287− Right (x, i) -> do put i
288+ Right (x, i) -> do putIState i
288289 return (collect x)
289290
290291-- Collect PClauses with the same function name
src/Idris/Prover.hs+30−13
@@ -13,8 +13,10 @@ import Idris.ElabTerm
1313import Idris.Parser
1414import Idris.Error
1515import Idris.DataOpts
16+import Idris.Completion
1617
1718import System.Console.Haskeline
19+import System.Console.Haskeline.History
1820import Control.Monad.State
1921
2022import Util.Pretty
@@ -22,7 +24,7 @@ import Util.Pretty
2224prover :: Bool -> Name -> Idris ()
2325prover lit x =
2426 do ctxt <- getContext
25− i <- get
27+ i <- getIState
2628 case lookupTy Nothing x ctxt of
2729 [t] -> if elem x (idris_metavars i)
2830 then prove ctxt lit x t
@@ -37,15 +39,23 @@ showProof lit n ps
3739 where bird = if lit then "> " else ""
3840 break = "\n" ++ bird
3941
42+proverSettings :: ElabState [PDecl] -> Settings Idris
43+proverSettings e = setComplete (proverCompletion assumptionNames) defaultSettings
44+ where assumptionNames = case envAtFocus (proof e) of
45+ OK env -> names env
46+ names [] = []
47+ names ((MN _ _, _) : bs) = names bs
48+ names ((n, _) : bs) = show n : names bs
49+
4050prove :: Context -> Bool -> Name -> Type -> Idris ()
4151prove ctxt lit n ty
42− = do let ps = initElaborator n ctxt ty
43− (tm, prf) <- ploop True ("-" ++ show n) [] (ES (ps, []) "" Nothing)
52+ = do let ps = initElaborator n ctxt ty
53+ (tm, prf) <- ploop True ("-" ++ show n) [] (ES (ps, []) "" Nothing) Nothing
4454 iLOG $ "Adding " ++ show tm
4555 iputStrLn $ showProof lit n prf
46− i <- get
56+ i <- getIState
4757 let proofs = proof_list i
48− put (i { proof_list = (n, prf) : proofs })
58+ putIState (i { proof_list = (n, prf) : proofs })
4959 let tree = simpleCase False True CompileTime (FC "proof" 0) [([], P Ref n ty, tm)]
5060 logLvl 3 (show tree)
5161 (ptm, pty) <- recheckC (FC "proof" 0) [] tm
@@ -58,7 +68,7 @@ prove ctxt lit n ty
5868elabStep :: ElabState [PDecl] -> ElabD a -> Idris (a, ElabState [PDecl])
5969elabStep st e = do case runStateT e st of
6070 OK (a, st') -> return (a, st')
61− Error a -> do i <- get
71+ Error a -> do i <- getIState
6272 fail (pshow i a)
6373
6474dumpState :: IState -> ProofState -> IO ()
@@ -108,18 +118,25 @@ lifte :: ElabState [PDecl] -> ElabD a -> Idris a
108118lifte st e = do (v, _) <- elabStep st e
109119 return v
110120
111−ploop :: Bool -> String -> [String] -> ElabState [PDecl] -> Idris (Term, [String])
112−ploop d prompt prf e
113− = do i <- get
121+ploop :: Bool -> String -> [String] -> ElabState [PDecl] -> Maybe History -> Idris (Term, [String])
122+ploop d prompt prf e h
123+ = do i <- getIState
114124 when d $ liftIO $ dumpState i (proof e)
115− x <- lift $ getInputLine (prompt ++ "> ")
125+ (x, h') <- runInputT (proverSettings e) $
126+ -- Manually track the history so that we can use the proof state
127+ do _ <- case h of
128+ Just history -> putHistory history
129+ Nothing -> return ()
130+ l <- getInputLine (prompt ++ "> ")
131+ h' <- getHistory
132+ return (l, Just h')
116133 (cmd, step) <- case x of
117134 Nothing -> fail "Abandoned"
118135 Just input -> do return (parseTac i input, input)
119136 case cmd of
120137 Right Abandon -> fail "Abandoned"
121138 _ -> return ()
122− (d, st, done, prf') <- idrisCatch
139+ (d, st, done, prf') <- idrisCatch
123140 (case cmd of
124141 Left err -> do iputStrLn (show err)
125142 return (False, e, False, prf)
@@ -140,7 +157,7 @@ ploop d prompt prf e
140157 return (True, st, False, prf ++ [step]))
141158 (\err -> do iputStrLn (show err)
142159 return (False, e, False, prf))
143− if done then do (tm, _) <- elabStep st get_term
160+ if done then do (tm, _) <- elabStep st get_term
144161 return (tm, prf')
145− else ploop d prompt prf' st
162+ else ploop d prompt prf' st h'
146163
src/Idris/REPL.hs+53−46
@@ -16,6 +16,7 @@ import Idris.Primitives
1616import Idris.Coverage
1717import Idris.UnusedArgs
1818import Idris.Docs
19+import Idris.Completion
1920
2021import Paths_idris
2122import Util.System
@@ -49,23 +50,23 @@ import Data.List
4950import Data.Char
5051import Data.Version
5152
52−repl :: IState -> [FilePath] -> Idris ()
53+repl :: IState -> [FilePath] -> InputT Idris ()
5354repl orig mods
5455 = H.catch
5556 (do let prompt = mkPrompt mods
56− x <- lift $ getInputLine (prompt ++ "> ")
57+ x <- getInputLine (prompt ++ "> ")
5758 case x of
58− Nothing -> do iputStrLn "Bye bye"
59+ Nothing -> do lift $ iputStrLn "Bye bye"
5960 return ()
6061 Just input -> H.catch
61− (do ms <- processInput input orig mods
62+ (do ms <- lift $ processInput input orig mods
6263 case ms of
6364 Just mods -> repl orig mods
6465 Nothing -> return ())
6566 ctrlC)
6667 ctrlC
67− where ctrlC :: SomeException -> Idris ()
68− ctrlC e = do iputStrLn (show e)
68+ where ctrlC :: SomeException -> InputT Idris ()
69+ ctrlC e = do lift $ iputStrLn (show e)
6970 repl orig mods
7071
7172mkPrompt [] = "Idris"
@@ -78,7 +79,7 @@ lit f = case splitExtension f of
7879
7980processInput :: String -> IState -> [FilePath] -> Idris (Maybe [FilePath])
8081processInput cmd orig inputs
81− = do i <- get
82+ = do i <- getIState
8283 let fn = case inputs of
8384 (f:_) -> f
8485 _ -> ""
@@ -86,12 +87,12 @@ processInput cmd orig inputs
8687 Left err -> do liftIO $ print err
8788 return (Just inputs)
8889 Right Reload ->
89− do put (orig { idris_options = idris_options i })
90+ do putIState (orig { idris_options = idris_options i })
9091 clearErr
9192 mods <- mapM loadModule inputs
9293 return (Just inputs)
9394 Right (Load f) ->
94− do put (orig { idris_options = idris_options i })
95+ do putIState (orig { idris_options = idris_options i })
9596 clearErr
9697 mod <- loadModule f
9798 return (Just [f])
@@ -111,7 +112,7 @@ processInput cmd orig inputs
111112
112113resolveProof :: Name -> Idris Name
113114resolveProof n'
114− = do i <- get
115+ = do i <- getIState
115116 ctxt <- getContext
116117 n <- case lookupNames Nothing n' ctxt of
117118 [x] -> return x
@@ -121,15 +122,15 @@ resolveProof n'
121122
122123removeProof :: Name -> Idris ()
123124removeProof n =
124− do i <- get
125+ do i <- getIState
125126 let proofs = proof_list i
126127 let ps = filter ((/= n) . fst) proofs
127− put $ i { proof_list = ps }
128+ putIState $ i { proof_list = ps }
128129
129130edit :: FilePath -> IState -> Idris ()
130131edit "" orig = iputStrLn "Nothing to edit"
131132edit f orig
132− = do i <- get
133+ = do i <- getIState
133134 env <- liftIO $ getEnvironment
134135 let editor = getEditor env
135136 let line = case errLine i of
@@ -138,7 +139,7 @@ edit f orig
138139 let cmd = editor ++ line ++ f
139140 liftIO $ system cmd
140141 clearErr
141− put (orig { idris_options = idris_options i })
142+ putIState (orig { idris_options = idris_options i })
142143 loadModule f
143144 iucheck
144145 return ()
@@ -149,7 +150,7 @@ edit f orig
149150
150151proofs :: IState -> Idris ()
151152proofs orig
152− = do i <- get
153+ = do i <- getIState
153154 let ps = proof_list i
154155 case ps of
155156 [] -> iputStrLn "No proofs available"
@@ -166,7 +167,7 @@ process fn Help = iputStrLn displayHelp
166167process fn (Eval t)
167168 = do (tm, ty) <- elabVal toplevel False t
168169 ctxt <- getContext
169− ist <- get
170+ ist <- getIState
170171 let tm' = normaliseAll ctxt [] tm
171172 let ty' = normaliseAll ctxt [] ty
172173 logLvl 3 $ "Raw: " ++ show (tm', ty')
@@ -186,7 +187,7 @@ process fn (ExecVal t)
186187 where fc = FC "(input)" 0
187188process fn (Check (PRef _ n))
188189 = do ctxt <- getContext
189− ist <- get
190+ ist <- getIState
190191 imp <- impShow
191192 case lookupTy Nothing n ctxt of
192193 ts@(_:_) -> mapM_ (\t -> iputStrLn $ show n ++ " : " ++
@@ -194,20 +195,20 @@ process fn (Check (PRef _ n))
194195 [] -> iputStrLn $ "No such variable " ++ show n
195196process fn (Check t) = do (tm, ty) <- elabVal toplevel False t
196197 ctxt <- getContext
197− ist <- get
198+ ist <- getIState
198199 imp <- impShow
199200 let ty' = normaliseC ctxt [] ty
200201 iputStrLn (showImp imp (delab ist tm) ++ " : " ++
201202 showImp imp (delab ist ty))
202203
203−process fn (DocStr n) = do i <- get
204+process fn (DocStr n) = do i <- getIState
204205 case lookupCtxtName Nothing n (idris_docstrings i) of
205206 [] -> iputStrLn $ "No documentation for " ++ show n
206207 ns -> mapM_ showDoc ns
207208 where showDoc (n, d)
208209 = do doc <- getDocs n
209210 iputStrLn $ show doc
210−process fn Universes = do i <- get
211+process fn Universes = do i <- getIState
211212 let cs = idris_constraints i
212213-- iputStrLn $ showSep "\n" (map show cs)
213214 liftIO $ print (map fst cs)
@@ -216,7 +217,7 @@ process fn Universes = do i <- get
216217 case ucheck cs of
217218 Error e -> iputStrLn $ pshow i e
218219 OK _ -> iputStrLn "Universes OK"
219−process fn (Defn n) = do i <- get
220+process fn (Defn n) = do i <- getIState
220221 iputStrLn "Compiled patterns:\n"
221222 liftIO $ print (lookupDef Nothing n (tt_ctxt i))
222223 case lookupCtxt Nothing n (idris_patdefs i) of
@@ -230,40 +231,42 @@ process fn (Defn n) = do i <- get
230231 = do liftIO $ putStr $ showImp True (delab i lhs)
231232 liftIO $ putStr " = "
232233 liftIO $ putStrLn $ showImp True (delab i rhs)
233−process fn (TotCheck n) = do i <- get
234+process fn (TotCheck n) = do i <- getIState
234235 case lookupTotal n (tt_ctxt i) of
235236 [t] -> iputStrLn (showTotal t i)
236237 _ -> return ()
237238process fn (DebugInfo n)
238− = do i <- get
239+ = do i <- getIState
239240 let oi = lookupCtxtName Nothing n (idris_optimisation i)
240241 when (not (null oi)) $ iputStrLn (show oi)
241242 let si = lookupCtxt Nothing n (idris_statics i)
242243 when (not (null si)) $ iputStrLn (show si)
244+ let di = lookupCtxt Nothing n (idris_datatypes i)
245+ when (not (null di)) $ iputStrLn (show di)
243246 let d = lookupDef Nothing n (tt_ctxt i)
244247 when (not (null d)) $ liftIO $
245248 do print (head d)
246249 let cg = lookupCtxtName Nothing n (idris_callgraph i)
247250 findUnusedArgs (map fst cg)
248− i <- get
251+ i <- getIState
249252 let cg' = lookupCtxtName Nothing n (idris_callgraph i)
250253 sc <- checkSizeChange n
251254 iputStrLn $ "Size change: " ++ show sc
252255 when (not (null cg')) $ do iputStrLn "Call graph:\n"
253256 iputStrLn (show cg')
254−process fn (Info n) = do i <- get
257+process fn (Info n) = do i <- getIState
255258 case lookupCtxt Nothing n (idris_classes i) of
256259 [c] -> classInfo c
257260 _ -> iputStrLn "Not a class"
258261process fn (Search t) = iputStrLn "Not implemented"
259262process fn (Spec t) = do (tm, ty) <- elabVal toplevel False t
260263 ctxt <- getContext
261− ist <- get
264+ ist <- getIState
262265 let tm' = simplify ctxt True [] {- (idris_statics ist) -} tm
263266 iputStrLn (show (delab ist tm'))
264267
265268process fn (RmProof n')
266− = do i <- get
269+ = do i <- getIState
267270 n <- resolveProof n'
268271 let proofs = proof_list i
269272 case lookup n proofs of
@@ -274,15 +277,15 @@ process fn (RmProof n')
274277 where
275278 insertMetavar :: Name -> Idris ()
276279 insertMetavar n =
277− do i <- get
280+ do i <- getIState
278281 let ms = idris_metavars i
279− put $ i { idris_metavars = n : ms }
282+ putIState $ i { idris_metavars = n : ms }
280283
281284process fn (AddProof prf)
282285 = do let fb = fn ++ "~"
283286 liftIO $ copyFile fn fb -- make a backup in case something goes wrong!
284287 prog <- liftIO $ readFile fb
285− i <- get
288+ i <- getIState
286289 let proofs = proof_list i
287290 n' <- case prf of
288291 Nothing -> case proofs of
@@ -299,7 +302,7 @@ process fn (AddProof prf)
299302 where ls = (lines prog)
300303
301304process fn (ShowProof n')
302− = do i <- get
305+ = do i <- getIState
303306 n <- resolveProof n'
304307 let proofs = proof_list i
305308 case lookup n proofs of
@@ -308,26 +311,26 @@ process fn (ShowProof n')
308311
309312process fn (Prove n')
310313 = do ctxt <- getContext
311− ist <- get
314+ ist <- getIState
312315 n <- case lookupNames Nothing n' ctxt of
313316 [x] -> return x
314317 [] -> return n'
315318 ns -> fail $ pshow ist (CantResolveAlts (map show ns))
316319 prover (lit fn) n
317320 -- recheck totality
318− i <- get
321+ i <- getIState
319322 totcheck (FC "(input)" 0, n)
320323 mapM_ (\ (f,n) -> setTotality n Unchecked) (idris_totcheck i)
321324 mapM_ checkDeclTotality (idris_totcheck i)
322325
323326process fn (HNF t) = do (tm, ty) <- elabVal toplevel False t
324327 ctxt <- getContext
325− ist <- get
328+ ist <- getIState
326329 let tm' = hnf ctxt [] tm
327330 iputStrLn (show (delab ist tm'))
328−process fn TTShell = do ist <- get
331+process fn TTShell = do ist <- getIState
329332 let shst = initState (tt_ctxt ist)
330− shst' <- lift $ runShell shst
333+ runShell shst
331334 return ()
332335process fn Execute = do (m, _) <- elabVal toplevel False
333336 (PApp fc
@@ -359,7 +362,7 @@ process fn (Pattelab t)
359362 = do (tm, ty) <- elabVal toplevel True t
360363 iputStrLn $ show tm ++ "\n\n : " ++ show ty
361364
362−process fn (Missing n) = do i <- get
365+process fn (Missing n) = do i <- getIState
363366 case lookupDef Nothing n (tt_ctxt i) of
364367 [CaseOp _ _ _ _ _ args t _ _]
365368 -> do tms <- genMissing n args t
@@ -367,7 +370,7 @@ process fn (Missing n) = do i <- get
367370 [] -> iputStrLn $ show n ++ " undefined"
368371 _ -> iputStrLn $ "Ambiguous name"
369372process fn Metavars
370− = do ist <- get
373+ = do ist <- getIState
371374 let mvs = idris_metavars ist \\ primDefs
372375 case mvs of
373376 [] -> iputStrLn "No global metavariables to solve"
@@ -394,7 +397,7 @@ dumpMethod :: (Name, (FnOpts, PTerm)) -> Idris ()
394397dumpMethod (n, (_, t)) = iputStrLn $ show n ++ " : " ++ show t
395398
396399dumpInstance :: Name -> Idris ()
397−dumpInstance n = do i <- get
400+dumpInstance n = do i <- getIState
398401 ctxt <- getContext
399402 imp <- impShow
400403 case lookupTy Nothing n ctxt of
@@ -487,12 +490,16 @@ help =
487490 ([":q",":quit"], "", "Exit the Idris system")
488491 ]
489492
493+
494+replSettings :: Settings Idris
495+replSettings = setComplete replCompletion defaultSettings
496+
490497-- invoke as if from command line
491498idris :: [Opt] -> IO IState
492−idris opts = runInputT defaultSettings $ execStateT (idrisMain opts) idrisInit
499+idris opts = execStateT (idrisMain opts) idrisInit
493500
494501idrisMain :: [Opt] -> Idris ()
495−idrisMain opts =
502+idrisMain opts =
496503 do let inputs = opt getFile opts
497504 let runrepl = not (NoREPL `elem` opts)
498505 let output = opt getOutput opts
@@ -508,8 +515,8 @@ idrisMain opts =
508515 let tgt = case opt getTarget opts of
509516 [] -> ViaC
510517 xs -> last xs
511− when (DefaultTotal `elem` opts) $ do i <- get
512− put (i { default_total = True })
518+ when (DefaultTotal `elem` opts) $ do i <- getIState
519+ putIState (i { default_total = True })
513520 setREPL runrepl
514521 setVerbose runrepl
515522 setCmdLine opts
@@ -534,8 +541,8 @@ idrisMain opts =
534541 elabPrims
535542 when (not (NoPrelude `elem` opts)) $ do x <- loadModule "Prelude"
536543 return ()
537− when runrepl $ iputStrLn banner
538− ist <- get
544+ when runrepl $ iputStrLn banner
545+ ist <- getIState
539546 mods <- mapM loadModule inputs
540547 ok <- noErrors
541548 when ok $ case output of
@@ -544,7 +551,7 @@ idrisMain opts =
544551 when ok $ case newoutput of
545552 [] -> return ()
546553 (o:_) -> process "" (NewCompile o)
547− when runrepl $ repl ist inputs
554+ when runrepl $ runInputT replSettings $ repl ist inputs
548555 ok <- noErrors
549556 when (not ok) $ liftIO (exitWith (ExitFailure 1))
550557 where
src/Idris/UnusedArgs.hs+2−2
@@ -14,7 +14,7 @@ findUnusedArgs ns = mapM_ traceUnused ns
1414
1515traceUnused :: Name -> Idris ()
1616traceUnused n
17− = do i <- get
17+ = do i <- getIState
1818 case lookupCtxt Nothing n (idris_callgraph i) of
1919 [CGInfo args calls scg usedns _] ->
2020 do let argpos = zip args [0..]
@@ -38,7 +38,7 @@ used path g j
3838 | (g, j) `elem` path = return False -- cycle, never used on the way
3939 | otherwise
4040 = do logLvl 5 $ (show ((g, j) : path))
41− i <- get
41+ i <- getIState
4242 case lookupCtxt Nothing g (idris_callgraph i) of
4343 [CGInfo args calls scg usedns unused] ->
4444 if (j >= length args)
src/Main.hs+1−1
@@ -39,7 +39,7 @@ import Paths_idris
3939
4040main = do xs <- getArgs
4141 let opts = parseArgs xs
42− runInputT defaultSettings $ execStateT (runIdris opts) idrisInit
42+ execStateT (runIdris opts) idrisInit
4343
4444runIdris :: [Opt] -> Idris ()
4545runIdris opts = do
test/reg002/reg002.idr+2−2
@@ -13,10 +13,10 @@ S Infinity = Infinity
1313Sn_notzero : Main.S n = Co 0 -> _|_
1414Sn_notzero = believe_me
1515
16−S_Co_not_Inf : S (Co n) = Infinity -> _|_
16+S_Co_not_Inf : Main.S (Co n) = Infinity -> _|_
1717S_Co_not_Inf = believe_me
1818
19−S_inj : (n : CoNat) -> (m : CoNat) -> S n = S m -> n = m
19+S_inj : (n : CoNat) -> (m : CoNat) -> Main.S n = Main.S m -> n = m
2020S_inj (Co n) (Co _) refl = refl
2121S_inj (Co n) Infinity p = FalseElim (S_Co_not_Inf p)
2222S_inj Infinity (Co m) p = FalseElim (S_Co_not_Inf (sym p))
test/reg005/reg005.idr+1−1
@@ -18,7 +18,7 @@ eq x y = if x == y then Just ?eqCharOK else Nothing
1818rle : (xs : Vect Char n) -> RLE xs
1919rle [] = REnd
2020rle (x :: xs) with (rle xs)
21− rle (x :: []) | REnd = RChar O x REnd
21+ rle (x :: Vect.Nil) | REnd = RChar O x REnd
2222 rle (x :: rep (S n) yvar ++ ys) | RChar n yvar rs with (eq x yvar)
2323 rle (x :: rep (S n) x ++ ys) | RChar n x rs | Just p
2424 = RChar (S n) x rs
test/reg008/reg008.idr+1−1
@@ -8,7 +8,7 @@ data Cmp : Nat -> Nat -> Type where
88total cmp : (x, y : Nat) -> Cmp x y
99cmp O O = cmpEQ
1010cmp O (S k) = cmpLT _
11−cmp (S k) O = cmpGT _
11+cmp (S k) O = cmpGT _
1212cmp (S x) (S y) with (cmp x y)
1313 cmp (S x) (S (x + (S k))) | cmpLT k = cmpLT k
1414 cmp (S x) (S x) | cmpEQ = cmpEQ
test/reg009/reg009.lidr+1−1
@@ -7,7 +7,7 @@
77> (as : Vect alpha n) ->
88> so (isAnyBy p (n ** as)) ->
99> (m : Nat ** (Vect (a : alpha ** so (p a)) m, so (m > O)))
10−> filterTagP p (a :: as) q with (p a)
10+> filterTagP {n = S m} p (a :: as) q with (p a)
1111> | True = (_
1212> **
1313> ((a ** believe_me oh)
test/test005/test005.idr+6−7
@@ -7,10 +7,9 @@ tlist : List Int
77tlist = [1, 2, 3, 4, 5]
88
99main : IO ()
10−main = do { print (abs (-8))
11− print (abs (S O))
12− print (span isAlpha tstr)
13− print (break isDigit tstr)
14− print (span (\x => x < 3) tlist)
15− print (break (\x => x > 2) tlist)
16− }
10+main = do print (abs (-8))
11+ print (abs (S O))
12+ print (span isAlpha tstr)
13+ print (break isDigit tstr)
14+ print (span (\x => x < 3) tlist)
15+ print (break (\x => x > 2) tlist)
test/test006/test006.idr+4−4
@@ -8,14 +8,14 @@ parity : (n:Nat) -> Parity n
88parity O = even {n=O}
99parity (S O) = odd {n=O}
1010parity (S (S k)) with (parity k)
11− parity (S (S (j + j))) | even ?= even {n=S j}
12− parity (S (S (S (j + j)))) | odd ?= odd {n=S j}
11+ parity (S (S (j + j))) | (even {n = j}) ?= even {n=S j}
12+ parity (S (S (S (j + j)))) | (odd {n = j}) ?= odd {n=S j}
1313
1414natToBin : Nat -> List Bool
1515natToBin O = Nil
1616natToBin k with (parity k)
17− natToBin (j + j) | even = False :: natToBin j
18− natToBin (S (j + j)) | odd = True :: natToBin j
17+ natToBin (j + j) | even {n = j} = False :: natToBin j
18+ natToBin (S (j + j)) | odd {n = j} = True :: natToBin j
1919
2020main : IO ()
2121main = do print (natToBin 42)
test/test007/test007.idr+1−2
@@ -35,8 +35,7 @@ runEval env e with (eval e) {
3535}
3636
3737main : IO ()
38−main = do print [| (*2) (Just 4) |]
38+main = do print [| (\x => x *2) (Just 4) |]
3939 print [| plus (Just 4) (Just 5) |]
4040 print (runEval [("x",21), ("y", 20)] (Add (Val 1) (Add (Var "x") (Var "y"))))
4141 print (runEval [("x",21)] (Add (Val 1) (Add (Var "x") (Var "y"))))
42−
test/test014/Resimp.idr+2
@@ -109,6 +109,8 @@ using (i: Fin n, gam : Vect Ty n, gam' : Vect Ty n, gam'' : Vect Ty n)
109109 (>>=) : Res gam gam' (R a) -> (a -> Res gam' gam'' (R t)) ->
110110 Res gam gam'' (R t)
111111
112+ ioret : a -> IO a
113+ ioret = return
112114
113115 interp : Env gam -> {static} Res gam gam' t ->
114116 (Env gam' -> interpTy t -> IO u) -> IO u
test/test015/test015.idr+2−4
@@ -20,10 +20,8 @@ data Binary : (width : Nat) -> (value : Nat) -> Type where
2020 (#) : Binary w v -> Bit bit -> Binary (S w) (bit + 2 * v)
2121
2222instance Show (Binary w k) where
23− show = show' where
24− show' : Binary w' k' -> String
25− show' zero = ""
26− show' (bin # bit) = show bin ++ show bit
23+ show zero = ""
24+ show (bin # bit) = show bin ++ show bit
2725
2826pad : Binary w n -> Binary (S w) n
2927pad zero = zero # b0
test/test018/test018a.idr+2−2
@@ -13,8 +13,8 @@ ping main proc
1313
1414pong : Process String ()
1515pong = do -- lift (putStrLn "Waiting for message")
16− (sender, msg) <- recvWithSender
17− lift $ putStrLn ("Received " ++ msg)
16+ (sender, m) <- recvWithSender
17+ lift $ putStrLn ("Received " ++ m)
1818 send sender ("Hello back!")
1919
2020mainProc : Process String ()
tutorial/classes.tex+25−18
@@ -63,7 +63,7 @@ to a \texttt{String}:
6363
6464instance Show a => Show (Vect a n) where
6565 show xs = "[" ++ show' xs ++ "]" where
66− show' : Vect a n' -> String
66+ show' : Vect a n -> String
6767 show' Nil = ""
6868 show' (x :: Nil) = show x
6969 show' (x :: xs) = show x ++ ", " ++ show' xs
@@ -71,14 +71,14 @@ instance Show a => Show (Vect a n) where
7171\end{SaveVerbatim}
7272\useverb{showvec}
7373
74−\noindent
75−\textbf{Remark: } The type of the auxiliary function \texttt{show'} is
76−important. The type variables \texttt{a} and \texttt{n} which are part of the
77−instance declaration for \texttt{Show (Vect a n)} are fixed across the entire
78−instance declaration. As a result, we do not have to constrain \texttt{a}
79−again. Furthermore, it means that if we use \texttt{n} in the type, it refers
80−to the (fixed) length of the outermost list \texttt{xs}. Therefore,
81−we use a different name for the length \texttt{n'} in \texttt{show'}.
74+%\noindent
75+%\textbf{Remark: } The type of the auxiliary function \texttt{show'} is
76+%important. The type variables \texttt{a} and \texttt{n} which are part of the
77+%instance declaration for \texttt{Show (Vect a n)} are fixed across the entire
78+%instance declaration. As a result, we do not have to constrain \texttt{a}
79+%again. Furthermore, it means that if we use \texttt{n} in the type, it refers
80+%to the (fixed) length of the outermost list \texttt{xs}. Therefore,
81+%we use a different name for the length \texttt{n'} in \texttt{show'}.
8282
8383\subsection{Default Definitions}
8484
@@ -355,9 +355,10 @@ m_add' x y = m_app (m_app (Just (+)) x) y
355355\useverb{maddb}
356356
357357\noindent
358−Rather than having to insert \texttt{m\_app} everywhere there is an application, we can
359−use \remph{idiom brackets} to do the job for us. To do this, we use the \texttt{Applicative}
360−class, which captures the notion of application for a data type:
358+Rather than having to insert \texttt{m\_app} everywhere there is an
359+application, we can use \remph{idiom brackets} to do the job for us. To do
360+this, we use the \texttt{Applicative} class, which captures the notion of
361+application for a data type:
361362
362363\begin{SaveVerbatim}{applicative}
363364
@@ -371,8 +372,8 @@ class Applicative (f : Type -> Type) where
371372\useverb{applicative}
372373
373374\noindent
374−\texttt{Maybe} is made an instance of \texttt{Applicative} as follows, where \texttt{<\$>}
375−is defined in the same way as \texttt{m\_app} above:
375+\texttt{Maybe} is made an instance of \texttt{Applicative} as follows, where
376+\texttt{<\$>} is defined in the same way as \texttt{m\_app} above:
376377
377378\begin{SaveVerbatim}{maybeapp}
378379
@@ -443,15 +444,21 @@ fetch x = MkEval (\e => fetchVal e) where
443444\useverb{fetch}
444445
445446\noindent
446−When defining an evaluator for the language, we will be applying functions in the
447−context of an \texttt{Eval}, so it is natural to make \texttt{Eval} an instance
448−of \texttt{Applicative}:
447+When defining an evaluator for the language, we will be applying functions in
448+the context of an \texttt{Eval}, so it is natural to make \texttt{Eval} an
449+instance of \texttt{Applicative}.
450+Before \texttt{Eval} can be an instance of
451+\texttt{Applicative} it is necessary to make \texttt{Eval} an instance of
452+\texttt{Functor}:
449453
450454\begin{SaveVerbatim}{}
451455
456+instance Functor Eval where
457+ fmap f (MkEval g) = MkEval (\e => fmap f (g e))
458+
452459instance Applicative Eval where
453460 pure x = MkEval (\e => Just x)
454−
461+
455462 (<$>) (MkEval f) (MkEval g) = MkEval (\x => app (f x) (g x)) where
456463 app : Maybe (a -> b) -> Maybe a -> Maybe b
457464 app (Just fx) (Just gx) = Just (fx gx)
tutorial/examples/binary.idr+3−5
@@ -6,11 +6,9 @@ data Binary : Nat -> Type where
66 bI : Binary n -> Binary (S (n + n))
77
88instance Show (Binary n) where
9− show = show' where
10− show' : Binary n' -> String
11− show' (bO x) = show x ++ "0"
12− show' (bI x) = show x ++ "1"
13− show' bEnd = ""
9+ show (bO x) = show x ++ "0"
10+ show (bI x) = show x ++ "1"
11+ show bEnd = ""
1412
1513data Parity : Nat -> Type where
1614 even : Parity (n + n)
tutorial/examples/interp.idr+3
@@ -44,6 +44,9 @@ using (G : Vect Ty n)
4444
4545 eAdd : Expr G (TyFun TyInt (TyFun TyInt TyInt))
4646 eAdd = Lam (Lam (Op (+) (Var stop) (Var (pop stop))))
47+
48+ eEq : Expr G (TyFun TyInt (TyFun TyInt TyBool))
49+ eEq = Lam (Lam (Op (==) (Var stop) (Var (pop stop))))
4750
4851 eDouble : Expr G (TyFun TyInt TyInt)
4952 eDouble = Lam (App (App eAdd (Var stop)) (Var stop))
tutorial/idris-tutorial.pdf

Binary file not shown.

tutorial/interp.tex+1−1
@@ -344,7 +344,7 @@ at the \Idris{} interactive environment is shown in Figure \ref{factrun}.
344344$ idris interp.idr
345345 ____ __ _
346346 / _/___/ /____(_)____
347− / // __ / ___/ / ___/ Version 0.9.5
347+ / // __ / ___/ / ___/ Version 0.9.6
348348 _/ // /_/ / / / (__ ) http://www.idris-lang.org/
349349 /___/\__,_/_/ /_/____/ Type :? for help
350350
tutorial/intro.tex+1−1
@@ -62,7 +62,7 @@ verifying systems software.
6262\subsection{Example Code}
6363
6464This tutorial includes some example code, which has been tested with \Idris{} version
65−0.9.5. The files are available in the \Idris{} distribution,
65+0.9.6. The files are available in the \Idris{} distribution,
6666so that you can try them out easily,
6767under \texttt{tutorial/examples}. However, it is strongly recommended that you
6868type them in yourself, rather than simply loading and reading them.
tutorial/starting.tex+3−3
@@ -79,7 +79,7 @@ environment. You should see something like the following:
7979$ idris
8080 ____ __ _
8181 / _/___/ /____(_)____
82− / // __ / ___/ / ___/ Version 0.9.5
82+ / // __ / ___/ / ___/ Version 0.9.6
8383 _/ // /_/ / / / (__ ) http://www.idris-lang.org/
8484 /___/\__,_/_/ /_/____/ Type :? for help
8585
@@ -99,7 +99,7 @@ as shown in Figure \ref{cmds}. Figure \ref{run1} shows an example run in which
9999the program is compiled to the executable \texttt{hello}.
100100
101101\begin{SaveVerbatim}{cmds}
102−Idris version 0.9.5
102+Idris version 0.9.6
103103-------------------
104104
105105 Command Arguments Purpose
@@ -134,7 +134,7 @@ Idris version 0.9.5
134134$ idris hello.idr
135135 ____ __ _
136136 / _/___/ /____(_)____
137− / // __ / ___/ / ___/ Version 0.9.5
137+ / // __ / ___/ / ___/ Version 0.9.6
138138 _/ // /_/ / / / (__ ) http://www.idris-lang.org/
139139 /___/\__,_/_/ /_/____/ Type :? for help
140140
tutorial/typesfuns.tex+6−18
@@ -210,24 +210,12 @@ Indentation is significant --- functions in the \texttt{where} block must be ind
210210further than the outer function.
211211
212212\textbf{Scope:}
213−Any names which are visible in the outer scope are also visible in the \texttt{where}
214−clause (unless they have been redefined, such as \texttt{xs} here).
215−\emph{However}, names which appear in the type are \emph{not} in scope. In particular,
216−in the above example, the \texttt{a} in the top level type and the \texttt{a} in the
217−auxiliary definifion \texttt{revAcc} are \emph{not} the same. If this is the required
218−behaviour, the \texttt{a} can be brought into scope as follows:
213+Any names which are visible in the outer scope are also visible in the
214+\texttt{where} clause (unless they have been redefined, such as \texttt{xs}
215+here). A name which appears only in the type will be in scope in the
216+\texttt{where} clause if it is a \remph{parameter} to one of the types,
217+i.e. it is fixed across the entire structure.
219218
220−\begin{SaveVerbatim}{revwhereb}
221−
222−reverse : List a -> List a
223−reverse {a} xs = revAcc [] xs where
224− revAcc : List a -> List a -> List a
225− ...
226−
227−\end{SaveVerbatim}
228−\useverb{revwhereb}
229−
230−\noindent
231219As well as functions, \texttt{where} blocks can include local data
232220declarations, such as the following where \texttt{MyLT} is not accessible outside
233221the definition of \texttt{foo}:
@@ -922,7 +910,7 @@ If the \texttt{Vect} is empty, the result is easy:
922910
923911\begin{SaveVerbatim}{vfilternil}
924912
925−filter p Nil = (_ , [])
913+filter p Nil = (_ ** [])
926914
927915\end{SaveVerbatim}
928916\useverb{vfilternil}