on master help sign in
Merge branch 'master' into bitstring
4c5b1bdBenjamin Saunders
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+
1New in 0.9.6:
12New in 0.9.6:
2-------------
13-------------
3
14
idris.cabal+2
@@ -47,6 +47,7 @@ Build-type: Custom
47Data-files: rts/libidris_rts.a rts/idris_rts.h rts/idris_gc.h
47Data-files: rts/libidris_rts.a rts/idris_rts.h rts/idris_gc.h
48 rts/idris_stdfgn.h rts/idris_main.c rts/idris_gmp.h
48 rts/idris_stdfgn.h rts/idris_main.c rts/idris_gmp.h
49 rts/libtest.c
49 rts/libtest.c
50+ js/Runtime.js
50Extra-source-files: lib/Makefile lib/*.idr lib/Prelude/*.idr
51Extra-source-files: lib/Makefile lib/*.idr lib/Prelude/*.idr
51 lib/Network/*.idr lib/Control/*.idr
52 lib/Network/*.idr lib/Control/*.idr
52 lib/Control/Monad/*.idr lib/Language/*.idr
53 lib/Control/Monad/*.idr lib/Language/*.idr
@@ -55,6 +56,7 @@ Extra-source-files: lib/Makefile lib/*.idr lib/Prelude/*.idr
55 tutorial/examples/*.idr lib/base.ipkg
56 tutorial/examples/*.idr lib/base.ipkg
56 config.mk
57 config.mk
57 rts/*.c rts/*.h rts/Makefile
58 rts/*.c rts/*.h rts/Makefile
59+ js/*.js
58
60
59source-repository head
61source-repository head
60 type: git
62 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
38believe_me : a -> b -- compiled specially as id, use with care!
38believe_me : a -> b -- compiled specially as id, use with care!
39believe_me x = prim__believe_me _ _ x
39believe_me x = prim__believe_me _ _ x
40
40
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+
41namespace Builtins {
45namespace Builtins {
42
46
43id : a -> a
47id : a -> a
lib/Control/Arrow.idr+5−4
@@ -24,16 +24,17 @@ instance Arrow Homomorphism where
24
24
25instance Monad m => Arrow (Kleislimorphism m) where
25instance Monad m => Arrow (Kleislimorphism m) where
26 arrow f = Kleisli (return . f)
26 arrow f = Kleisli (return . f)
27− first (Kleisli f) = Kleisli $ \(a, b) => do x <- f a
27+ first (Kleisli f) = Kleisli $ \(a, b) => do x <- f a
28− return (x, b)
28+ return (x, b)
29
29
30 second (Kleisli f) = Kleisli $ \(a, b) => do x <- f b
30 second (Kleisli f) = Kleisli $ \(a, b) => do x <- f b
31 return (a, x)
31 return (a, x)
32
32
33− (Kleisli f) *** (Kleisli g) = Kleisli $ \(a, b) => do x <- f a
33+ (Kleisli f) *** (Kleisli g) = Kleisli $ \(a, b) => do x <- f a
34 y <- g b
34 y <- g b
35 return (x, y)
35 return (x, y)
36
36
37− (Kleisli f) &&& (Kleisli g) = Kleisli $ \a => do x <- f a
37+ (Kleisli f) &&& (Kleisli g) = Kleisli $ \a => do x <- f a
38 y <- g a
38 y <- g a
39 return (x, y)
39 return (x, y)
40+
lib/Prelude.idr+2−3
@@ -59,14 +59,13 @@ instance (Show a, Show b) => Show (a, b) where
59
59
60instance Show a => Show (List a) where
60instance Show a => Show (List a) where
61 show xs = "[" ++ show' "" xs ++ "]" where
61 show xs = "[" ++ show' "" xs ++ "]" where
62− show' : String -> List a -> String
63 show' acc [] = acc
62 show' acc [] = acc
64 show' acc [x] = acc ++ show x
63 show' acc [x] = acc ++ show x
65 show' acc (x :: xs) = show' (acc ++ show x ++ ", ") xs
64 show' acc (x :: xs) = show' (acc ++ show x ++ ", ") xs
66
65
67instance Show a => Show (Vect a n) where
66instance Show a => Show (Vect a n) where
68 show xs = "[" ++ show' xs ++ "]" where
67 show xs = "[" ++ show' xs ++ "]" where
69− show' : Vect a m -> String
68+ show' : Vect a n -> String
70 show' [] = ""
69 show' [] = ""
71 show' [x] = show x
70 show' [x] = show x
72 show' (x :: xs) = show x ++ ", " ++ show' xs
71 show' (x :: xs) = show x ++ ", " ++ show' xs
@@ -335,7 +334,7 @@ readFile fn = do h <- openFile fn Read
335 c <- readFile' h ""
334 c <- readFile' h ""
336 closeFile h
335 closeFile h
337 return c
336 return c
338− where
337+ where
339 partial
338 partial
340 readFile' : File -> String -> IO String
339 readFile' : File -> String -> IO String
341 readFile' h contents =
340 readFile' h contents =
lib/Prelude/Fin.idr+3−5
@@ -8,11 +8,9 @@ data Fin : Nat -> Type where
8 fS : Fin k -> Fin (S k)
8 fS : Fin k -> Fin (S k)
9
9
10instance Eq (Fin n) where
10instance Eq (Fin n) where
11− (==) = eq where
12− eq : Fin m -> Fin m -> Bool
13− eq fO fO = True
11+ (==) fO fO = True
14− eq (fS k) (fS k') = eq k k'
12+ (==) (fS k) (fS k') = k == k'
15− eq _ _ = False
13+ (==) _ _ = False
16
14
17finToNat : Fin n -> Nat -> Nat
15finToNat : Fin n -> Nat -> Nat
18finToNat fO a = a
16finToNat 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
106 where
106 where
107 %assert_total -- relies on deleteMinimum making heap smaller
107 %assert_total -- relies on deleteMinimum making heap smaller
108 toList' : Ord a => (h : MaxiphobicHeap a) -> (isEmpty h = False) -> List a
108 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))
110
110
111fromList : Ord a => List a -> MaxiphobicHeap a
111fromList : Ord a => List a -> MaxiphobicHeap a
112fromList = foldr insert empty
112fromList = foldr insert empty
lib/Prelude/Strings.idr+2−2
@@ -25,8 +25,8 @@ strTail' x p = prim__strTail x
25%assert_total
25%assert_total
26strM : (x : String) -> StrM x
26strM : (x : String) -> StrM x
27strM x with (choose (not (x == "")))
27strM x with (choose (not (x == "")))
28− strM x | (Left p) = believe_me $ StrCons (strHead' x p) (strTail' x p)
28+ strM x | (Left p) = really_believe_me $ StrCons (strHead' x p) (strTail' x p)
29− strM x | (Right p) = believe_me StrNil
29+ strM x | (Right p) = really_believe_me StrNil
30
30
31-- annoyingly, we need these assert_totals because StrCons doesn't have
31-- annoyingly, we need these assert_totals because StrCons doesn't have
32-- a recursive argument, therefore the termination checker doesn't believe
32-- 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
129or = foldr (||) False
129or = foldr (||) False
130
130
131total any : (a -> Bool) -> Vect a m -> Bool
131total any : (a -> Bool) -> Vect a m -> Bool
132−any p = or . map p
132+any p = Vect.or . map p
133
133
134total all : (a -> Bool) -> Vect a m -> Bool
134total all : (a -> Bool) -> Vect a m -> Bool
135−all p = and . map p
135+all p = Vect.and . map p
136
136
137--------------------------------------------------------------------------------
137--------------------------------------------------------------------------------
138-- Transformations
138-- Transformations
papers/impl-paper/conclusions.tex+72−49
@@ -4,27 +4,58 @@
4
4
5Dependently typed programming languages have becoming more prominent in recent
5Dependently typed programming languages have becoming more prominent in recent
6years as tools for verifying software correctness, and several experimental
6years as tools for verifying software correctness, and several experimental
7−languages are being developed, in particular Agda \cite{norell2007thesis}, Epigram
7+languages are being developed, in particular Agda \cite{norell2007thesis},
8−\cite{McBride2004a,Levitation2010} and Trellys \cite{Kimmell2012}.
8+Epigram \cite{McBride2004a,Levitation2010} and Trellys \cite{Kimmell2012}.
9−
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+
10−An earlier implementation of \Idris{} was built on the \Ivor{} proof engine
32+An earlier implementation of \Idris{} was built on the \Ivor{} proof engine
11\cite{Brady2006b}. This implementation differed in one important way --- unlike
33\cite{Brady2006b}. This implementation differed in one important way --- unlike
12−the present implementation, there was limited separation between the type theory
34+the present implementation, there was limited separation between the type
13−and the high level language. The type theory itself supported implicit syntax and
35+theory and the high level language. The type theory itself supported implicit
14−unification, with high level constructs such as the \texttt{with} rule implemented
36+syntax and unification, with high level constructs such as the \texttt{with}
15−directly. Two important disadvantages were found with this approach, however:
37+rule implemented directly. Two important disadvantages were found with this
16−firstly, the type checker is much more complicated when combined with
38+approach, however: firstly, the type checker is much more complicated when
17−unification, making it harder to maintain; secondly, adding new high level features
39+combined with unification, making it harder to maintain; secondly, adding new
18−requires the type checker to support those features directly. In contrast, elaboration
40+high level features requires the type checker to support those features
41+directly. In contrast, elaboration by tactics gives a clean separation between
19−by tactics gives a clean separation between the low level and high level languages.
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.
20
51
21The Agda implementation is based on a type theory with
52The Agda implementation is based on a type theory with
22implicit syntax and pattern matching --- Norell gives an algorithm for type checking
53implicit syntax and pattern matching --- Norell gives an algorithm for type checking
23a dependently typed language with pattern matching and metavariables
54a dependently typed language with pattern matching and metavariables
24\cite{norell2007thesis}. Unlike the present \Idris{} implementation, metavariables
55\cite{norell2007thesis}. Unlike the present \Idris{} implementation, metavariables
25and implicit arguments are part of the type theory. This has the advantage that
56and 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
57+implicit arguments can be used more freely (for example, in higher order
27−system.
58+function arguments) at the expense of complicating the type system.
28
59
29Epigram \cite{McBride2004a} and Oleg \cite{McBride1999}
60Epigram \cite{McBride2004a} and Oleg \cite{McBride1999}
30have provided much of the inspiration for the \Idris{} elaborator. Indeed,
61have provided much of the inspiration for the \Idris{} elaborator. Indeed,
@@ -38,7 +69,7 @@ optimisation opportunities \cite{Brady2003}. However, it requires the
38implementation of extra machinery for constructor manipulation
69implementation of extra machinery for constructor manipulation
39\cite{McBride2006} and so we have avoided it in the present implementation.
70\cite{McBride2006} and so we have avoided it in the present implementation.
40
71
41−%Comparison with GHC's type system and type checker. \cite{Vytiniotis2011}
72+
42
73
43%[Observation: separate elaboration and type checking, sort of like in GHC which
74%[Observation: separate elaboration and type checking, sort of like in GHC which
44%type checks the high level language and produces a type correct core language.
75%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
61the correctness of the underlying type system, and keeping the implementation small
92the correctness of the underlying type system, and keeping the implementation small
62reduces the possibility of errors.
93reduces the possibility of errors.
63
94
64−The approach we have taken to implementing the high level language, implementing
95+The approach we have taken to implementing the high level language,
65−a tactic language as an embedded DSL, allows us to
96+implementing an elaboration monad with tactics for program construction, allows
66−build programs on top of a small and unchanging kernel, rather than extending
97+us to build programs on top of a small and unchanging kernel, rather than
67−the core language to deal with implicit syntax, unification and type classes.
98+extending the core language to deal with implicit syntax, unification and type
68−High level \Idris{} features are implemented by describing the corresponding
99+classes. High level \Idris{} features are implemented by describing the
69−sequence of tactics to build an equivalent program in \TT{}, via a development
100+corresponding sequence of tactics to build an equivalent program in \TT{}, via
70−calculus of incomplete terms, \TTdev{}. A significant advantage we have found with
101+a development calculus of incomplete terms, \TTdev{}. A significant advantage
71−this approach is that higher level features can easily be implemented in terms
102+we have found with this approach is that higher level features can easily be
72−of existing elaborator components. For example, once we have implemented elaboration
103+implemented in terms of existing elaborator components. For example, once we
73−for data types and functions, it is easy to add several features:
104+have implemented elaboration for data types and functions, it is easy to add
105+several features:
74
106
75\begin{itemize}
107\begin{itemize}
76\item \textbf{Type classes}: A dictionary is merely a record containing the
108\item \textbf{Type classes}: A dictionary is merely a record containing the
@@ -89,19 +121,19 @@ implement these high level features.
89Other high level features such as dependent records, tuples and monad comprehensions
121Other high level features such as dependent records, tuples and monad comprehensions
90can be added equally easily --- and indeed have been added in the full implementation.
122can be added equally easily --- and indeed have been added in the full implementation.
91Furthermore,
123Furthermore,
92−since we have used a tactic-based EDSL to elaborate \Idris{} to \TT{}, it is
124+since we have taken a tactic-based approach to elaborating \Idris{} to \TT{},
93−possible to expose the tactic language to the programmer. This opens up the
125+it is possible to expose tactics to the programmer. This opens up
94−possibility of implementing domain specific decision procedures, or implementing
126+the possibility of implementing domain specific decision procedures, or
95−user defined tactics in a style similar to Coq's \texttt{Ltac} language \cite{Delahaye2000}.
127+implementing user defined tactics in a style similar to Coq's \texttt{Ltac}
96−Although \TT{} is primarily intended as a core language for \Idris{},
128+language \cite{Delahaye2000}. Although \TT{} is primarily intended as a core
97−its rich type system also allows it to capture a number of high level languages, especially
129+language for \Idris{}, its rich type system also allows it to capture a number
98−when augmented with primitive operators.
130+of high level languages, especially when augmented with primitive operators.
99
131
100We have not discussed the performance of the elaboration
132We have not discussed the performance of the elaboration
101algorithm, or described how \Idris{} compiles to executable code. In practice,
133algorithm, or described how \Idris{} compiles to executable code. In practice,
102we have found performance to be acceptable --- for example, the \Idris{}
134we 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)
135+library (31 files, 3718 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
136+elaborates in around 12 seconds\footnote{On a MacBook Pro, 2.8GHz Intel Core 2
105Duo, 4Gb RAM}. Profiling suggests that the main bottleneck is locating holes
137Duo, 4Gb RAM}. Profiling suggests that the main bottleneck is locating holes
106in a proof term, which can be improved by choosing a better representation
138in a proof term, which can be improved by choosing a better representation
107for proof terms, perhaps based on a zipper \cite{Huet1997}. Compilation is made
139for proof terms, perhaps based on a zipper \cite{Huet1997}. Compilation is made
@@ -118,19 +150,10 @@ theory.
118However, a programming language implementation is not an end in itself.
150However, a programming language implementation is not an end in itself.
119Programming languages exist to support research and practice in many different
151Programming languages exist to support research and practice in many different
120domains. In future work, therefore, I plan to apply domain specific
152domains. In future work, therefore, I plan to apply domain specific
121−language based techniques to realistic problems
153+language based techniques to realistic problems in important safety critical
122−in important safety critical domains such as security and network protocol
154+domains such as security and network protocol design and implementation. In
123−design and implementation. In order to be successful, this will require a language which
155+order to be successful, this will require a language which is expressive enough
124−is expressive enough to describe protocol specifications at a high level, and robust
156+to describe protocol specifications at a high level, and robust enough to
125−enough to guarantee correct implementation of those protocols. \Idris{}, I believe,
157+guarantee correct implementation of those protocols. \Idris{}, I believe, is
126−is the right tool for this work.
158+the right tool for this work.
127−
128−
129−
130−%\subsection{Further Work}
131
159
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 @@
1\newcommand{\ttinterp}[1]{\mathcal{E}\interp{#1}}
1\newcommand{\ttinterp}[1]{\mathcal{E}\interp{#1}}
2+\newcommand{\ttpinterp}[1]{\mathcal{P}\interp{#1}}
2\newcommand{\uninterp}[1]{\mathcal{T}\interp{#1}}
3\newcommand{\uninterp}[1]{\mathcal{T}\interp{#1}}
3
4
4\section{Elaborating \Idris{}}
5\section{Elaborating \Idris{}}
@@ -41,33 +42,42 @@ similar to a $\LET$ binding, but without any computational force,
41i.e. there are no reduction rules for guess bindings.
42i.e. there are no reduction rules for guess bindings.
42Using binders to represent holes is useful in a dependently typed setting since
43Using binders to represent holes is useful in a dependently typed setting since
43one value may determine another. Attaching a guess to a binder ensures that
44one 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+instantiating one such variable also instantiates all of its dependencies.
46+%The
45−typing rules for binders ensure that no $?$ bindings leak into types.
47+%typing rules for binders ensure that no $?$ bindings leak into types.
46
48
47\FFIG{
49\FFIG{
48−\AR{
50+\begin{array}{c}
49\vb ::= \ldots
51\vb ::= \ldots
50− \:\mid\: \hole{\vx}{\vt} \:\:(\mbox{hole binding}) \:\:
52+ \;\mid\; \hole{\vx}{\vt} \;\;(\mbox{hole binding}) \;\;
51− \:\mid\: \guess{\vx}{\vt}{\vt} \:\:(\mbox{guess})
53+ \;\mid\; \guess{\vx}{\vt}{\vt} \;\;(\mbox{guess})
52\medskip\\
54\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}\;
53\Rule{
64\Rule{
54\Gamma;\hole{\vx}{\vS}\proves\ve\Hab\vT
65\Gamma;\hole{\vx}{\vS}\proves\ve\Hab\vT
55}
66}
56{
67{
57\Gamma\proves\hole{\vx}{\vS}\SC\ve\Hab\vT
68\Gamma\proves\hole{\vx}{\vS}\SC\ve\Hab\vT
58}
69}
59−\hspace*{0.1cm}\vx\not\in\vT
70+%\hspace*{0.1cm}\vx\not\in\vT
60−\hspace*{0.1in}\mathsf{Hole}
61\hg
71\hg
72+\mathsf{Guess}\;
62\Rule{
73\Rule{
63\Gamma;\guess{\vx}{\vS}{\ve_1}\proves\ve_2\Hab\vT
74\Gamma;\guess{\vx}{\vS}{\ve_1}\proves\ve_2\Hab\vT
64}
75}
65{
76{
66\Gamma\proves\guess{\vx}{\vS}{\ve_1}\SC\ve_2\Hab\vT
77\Gamma\proves\guess{\vx}{\vS}{\ve_1}\SC\ve_2\Hab\vT
67}
78}
68−\hspace*{0.1cm}\vx\not\in\vT
79+%\hspace*{0.1cm}\vx\not\in\vT
69−\hspace*{0.1in}\mathsf{Guess}
80+\end{array}
70−}
71}
81}
72{\TTdev{} extensions}
82{\TTdev{} extensions}
73{ttdev}
83{ttdev}
@@ -77,12 +87,23 @@ typing rules for binders ensure that no $?$ bindings leak into types.
77
87
78\label{sect:prfstate}
88\label{sect:prfstate}
79
89
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}.
80−A proof state is a tuple, $(\vC, \Delta, \ve, \vQ)$, containing:
96+A proof state is a tuple, $(\vC, \Delta, \ve, \vP, \vQ)$, containing:
81
97
82\begin{itemize}
98\begin{itemize}
83\item A global context, $\vC$, containing pattern matching definitions and their types
99\item A global context, $\vC$, containing pattern matching definitions and their types
84\item A local context, $\Delta$, containing pattern bindings
100\item A local context, $\Delta$, containing pattern bindings
85\item A proof term, $\ve$, in \TTdev{}
101\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}
86\item A hole queue, $\vQ$
107\item A hole queue, $\vQ$
87%\item \remph{Deferred} definitions, $\vD$, for introducing global metavariables
108%\item \remph{Deferred} definitions, $\vD$, for introducing global metavariables
88\end{itemize}
109\end{itemize}
@@ -91,29 +112,49 @@ The \remph{hole queue} is a priority queue of names of hole and guess binders
91$\langle\vx_1,\vx_2,\ldots,\vx_n\rangle$
112$\langle\vx_1,\vx_2,\ldots,\vx_n\rangle$
92in the proof term ---
113in the proof term ---
93ensuring that each bound name is unique. Holes refer to \remph{sub goals}
114ensuring that each bound name is unique. Holes refer to \remph{sub goals}
94−in the proof.
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
95−When this queue is empty, the proof term is complete.
118+problems, the proof term is complete.
119+
96Creating a \TT{} expression from an \Idris{} expression involves creating
120Creating a \TT{} expression from an \Idris{} expression involves creating
97a new proof state, with an empty proof term, and using the high level definition
121a new proof state, with an empty proof term, and using the high level definition
98to direct the building of a final proof state, with a complete proof term.
122to direct the building of a final proof state, with a complete proof term.
99
123
100In the implementation, the proof state is captured in an elaboration monad,
124In the implementation, the proof state is captured in an elaboration monad,
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+
101−\texttt{Elab}, which includes various operations for querying and updating
138+The \texttt{Elab} monad supports various operations for querying and updating
102−the proof state, manipulating terms, generating fresh names, etc. However, we will
139+the proof state, manipulating terms, generating fresh names, etc. However, we
103−describe \Idris{} elaboration in terms of meta-operations on the proof state,
140+will describe \Idris{} elaboration in terms of meta-operations on the proof
104−in order to capture the essence of the elaboration process without being distracted
141+state, in order to capture the essence of the elaboration process without being
105−by implementation details. These meta-operations include:
142+distracted by implementation details. These meta-operations include:
106
143
107\begin{itemize}
144\begin{itemize}
108\item \demph{Queries} which retrieve values from the proof state, without modifying
145\item \demph{Queries} which retrieve values from the proof state, without modifying
109the state. For example, we can:
146the state. For example, we can:
110\begin{itemize}
147\begin{itemize}
111−\item Get the type of the current sub goal ($\MO{Type}$)
148+\item Get the type of the current sub goal ($\MO{Type}$).
149+\item Get the current proof term ($\MO{Term}$).
112−\item Retrieve the local context $\Gamma$ at the current sub goal ($\MO{Context}$)
150+\item Retrieve the local context $\Gamma$ at the current sub goal
151+($\MO{Context}$).
113−\item Type check ($\MO{Check}$) or normalise ($\MO{Normalise}$) a term relative to $\Gamma$
152+\item Type check ($\MO{Check}$) or normalise ($\MO{Normalise}$) a term relative
153+to $\Gamma$.
114\end{itemize}
154\end{itemize}
115−\item \demph{Unification}, which unifies two terms (potentially solving sub goals)
155+\item \demph{Unification}, which unifies two terms (potentially solving sub
116−relative to $\Gamma$
156+goals) relative to $\Gamma$. This may introduce new unification problems
157+to the proof state.
117\item \demph{Tactics} which update the proof term. Tactics operate on the sub term
158\item \demph{Tactics} which update the proof term. Tactics operate on the sub term
118at the binder specified by the head of the hole queue $\vQ$.
159at the binder specified by the head of the hole queue $\vQ$.
119\item \demph{Focussing} on a specific sub goal, which brings a different sub goal to the
160\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.
122%$\vC$ which solves the sub goal.
163%$\vC$ which solves the sub goal.
123\end{itemize}
164\end{itemize}
124
165
125−Elaboration of an \Idris{} expression involves creating a new proof state, running
166+Elaboration of an \Idris{} expression involves creating a new proof state,
126−a series of tactics to build a complete proof term, then retrieving and \remph{rechecking}
167+running a series of tactics to build a complete proof term, then retrieving and
127−the final proof term, which must be a \TT{} program (i.e. does not contain any of the
168+\remph{rechecking} the final proof term, which must be a \TT{} program (i.e.
128−\TTdev{} extensions). We call a sub-term which contains no hole or guess bindings
169+does not contain any of the \TTdev{} extensions). We call a sub-term which
129−\demph{pure}. Although a pure term does not contain hole or guess bindings, it may
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
130−nevertheless \remph{refer} to hole- or guess-bound variables.
172+guess-bound variables.
131
173
132−The proof state is initialised with the $\MO{NewProof}$ operation. Given a global
174+The proof state is initialised with the $\MO{NewProof}$ operation. Given a
133−context $\vC$, $\MO{NewProof}\:\vt$ sets up the proof state as:
175+global context $\vC$, $\MO{NewProof}\;\vt$ sets up the proof state as:
134
176
135\DM{
177\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)
137}
179}
138
180
139The local context is initially empty, and the initial hole queue is the $\vx$ standing for
181The local context is initially empty, and the initial hole queue is the $\vx$ standing for
140the entire expression. The proof term is reset with the $\MO{NewTerm}$ operation.
182the entire expression. The proof term is reset with the $\MO{NewTerm}$ operation.
141In an existing proof state $(\vC, \Delta, \ve, \vQ)$,
183In 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
143updates the proof state to:
185updates the proof state to:
144
186
145\DM{
187\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)
147}
189}
148
190
149−
191+Resetting the term and queue but retaining pattern bindings
150−This allows the elaborator to use pattern bindings from the left
192+allows the elaborator to use pattern bindings from the left
151hand side of a pattern matching definition in the term on the right hand side.
193hand side of a pattern matching definition in the term on the right hand side.
152
194
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.
200
195
201\newcommand{\Check}{\MO{Check}_\Gamma}
196\newcommand{\Check}{\MO{Check}_\Gamma}
202\newcommand{\Eval}{\MO{Normalise}_\Gamma}
197\newcommand{\Eval}{\MO{Normalise}_\Gamma}
203\newcommand{\Unify}{\MO{Unify}_\Gamma}
198\newcommand{\Unify}{\MO{Unify}_\Gamma}
199+\newcommand{\PrimUnify}{\MO{PrimUnify}_\Gamma}
200+\newcommand{\Subst}{\MO{Subst}}
204
201
205\subsection{Tactics}
202\subsection{Tactics}
206
203
207% Meta-operations Check, Normalise, Unify
204% Meta-operations Check, Normalise, Unify
208In order to build \TT{} expressions from \Idris{} programs, we define a collection
205In order to build \TT{} expressions from \Idris{} programs, we define a collection
209of meta-operations for querying and modifying the proof state. Meta-operations
206of 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
207+may have side-effects including failure, or updating the proof state, and
211−primitive meta-operations:
208+may fail. We have the following primitive meta-operations:
212
209
213\begin{itemize}
210\begin{itemize}
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.
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.
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
216+\item $\Check\;\ve$, which type checks an expression $\ve$ relative to a context
217$\Gamma$, returning its type.
217$\Gamma$, returning its type.
218$\MO{Check}$ will fail
218$\MO{Check}$ will fail
219if the expression is not well-typed.
219if the expression is not well-typed.
220−\item $\Eval\:\ve$, which evaluates a well-typed expression $\ve$ relative to a context
220+\item $\Eval\;\ve$, which evaluates a well-typed expression $\ve$ relative to a context
221−$\Gamma$, returning its normal form.
221+$\Gamma$, returning its normal form. $\MO{Normalise}$ reduces under binders,
222+but does not reduce definitions which are not total.
222\item
223\item
223−$\Unify\:\ve_1\:\ve_2$,
224+$\PrimUnify\;\ve_1\;\ve_2$,
224−which unifies $\ve_1$ and $\ve_2$ by finding the values with which holes must be instantiated
225+which attempts to unify $\ve_1$ and $\ve_2$ by finding the values with which
225−for $\ve_1$ and $\ve_2$ to be convertible relative to $\Gamma$
226+holes must be instantiated for $\ve_1$ and $\ve_2$ to be convertible relative
226−(i.e. for $\Gamma\proves\ve_1\converts\ve_2$ to hold). $\MO{Unify}$ will fail
227+to $\Gamma$ (i.e. for $\Gamma\proves\ve_1\converts\ve_2$ to hold).
227−if it cannot find such values. If successful, $\MO{Unify}$ will update the proof state.
228+\item $\Subst\;\vx\;\ve$, which instantiates a hole $\vx$ directly with a term
229+$\ve$, typically arising from unification.
228\end{itemize}
230\end{itemize}
229
231
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
230−\demph{Tactics} are meta-operations which operate on the sub-term given
275+\demph{Tactics} are meta-operations which operate on the sub-term given by the
231−by the hole at the head of the hole queue in the proof state. They take the following form:
276+hole at the head of the hole queue in the proof state. They take the following
277+form:
232
278
233\DM{
279\DM{
234\PA{\A\A}{
280\PA{\A\A}{
235−\MO{Tactic}_\Gamma & \:\vec{\VV{args}} & \:\vt & \MoRet{\vt'}
281+\MO{Tactic}_\Gamma & \;\vec{\VV{args}} & \;\vt & \MoRet{\vt'}
236}
282}
237}
283}
238
284
@@ -246,9 +292,117 @@ well-typed, with a type convertible to the type of $\vt$.
246Tactics may also have the side effect of updating the proof state,
292Tactics may also have the side effect of updating the proof state,
247therefore we will describe tactics in a pseudo-code with $\RW{do}$ notation.
293therefore we will describe tactics in a pseudo-code with $\RW{do}$ notation.
248
294
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+
249−We define a set of primitive tactics: $\MO{Claim}$, $\MO{Fill}$ and $\MO{Solve}$
347+In the remainder of this section, we will define a set of primitive tactics:
250−which are used to create and destroy holes; and $\MO{Lambda}$, $\MO{Pi}$, $\MO{Let}$
348+$\MO{Claim}$, $\MO{Fill}$ and $\MO{Solve}$ which are used to create and destroy
251−and $\MO{Attack}$ which are used to create binders.
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+
252
406
253\subsubsection{Creating and destroying holes}
407\subsubsection{Creating and destroying holes}
254
408
@@ -259,7 +413,7 @@ keeping $\vx$ at the head:
259\DM{
413\DM{
260\PA{\A\A}{
414\PA{\A\A}{
261\MO{Claim}_\Gamma & (\vy \Hab\vS) & (\hole{\vx}{\vT}\SC\ve) &
415\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} \\
263}
417}
264}
418}
265
419
@@ -275,10 +429,10 @@ solve other holes by unifying the expected type of $\vx$ with the type of $\vv$:
275\DM{
429\DM{
276\PA{\A\A}{
430\PA{\A\A}{
277\MO{Fill}_\Gamma & \vv & (\hole{\vx}{\vT}\SC\ve) &
431\MO{Fill}_\Gamma & \vv & (\hole{\vx}{\vT}\SC\ve) &
278− \MoRet{\RW{do}\:\AR{
432+ \MoRet{\RW{do}\;\AR{
279− \vT' \leftarrow \Check\:\vv\\
433+ \vT' \leftarrow \Check\;\vv\\
280− \Unify\:\vT\:\vT'\\
434+ \Unify\;\vT\;\vT'\\
281− \RW{return}\:\guess{\vx}{\vT}{\vv'}\SC\ve}
435+ \RW{return}\;\guess{\vx}{\vT}{\vv}\SC\ve}
282 } \\
436 } \\
283}
437}
284}
438}
@@ -288,10 +442,10 @@ For example, consider the following proof term:
288
442
289\DM{
443\DM{
290\AR{
444\AR{
291−\hole{\vA}{\Set}\SC\hole{\vk}{\Nat}\SC
445+\hole{\vA}{\Type}\SC\hole{\vk}{\Nat}\SC
292−\hole{\vx}{\vA}\SC\hole{\vxs}{\Vect\:\vA\:\vk}\SC
446+\hole{\vx}{\vA}\SC\hole{\vxs}{\Vect\;\vA\;\vk}\SC
293\\
447\\
294−\hole{\vys}{\Vect\:\vA\:(\suc\:\vk)}\SC\vys
448+\hole{\vys}{\Vect\;\vA\;(\suc\;\vk)}\SC\vys
295}
449}
296}
450}
297
451
@@ -301,9 +455,9 @@ attempts to
301$\MO{Fill}$ it with an $\TC{Int}$ value $42$, we have:
455$\MO{Fill}$ it with an $\TC{Int}$ value $42$, we have:
302
456
303\begin{itemize}
457\begin{itemize}
304−\item $\Check\:42\:\mq\:\TC{Int}$
458+\item $\Check\;42\;\mq\;\TC{Int}$
305\item Unifying $\TC{Int}$ with $\vA$ (the type of $\vx$) is only possible if
459\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$.
307\end{itemize}
461\end{itemize}
308
462
309\noindent
463\noindent
@@ -312,9 +466,9 @@ Therefore the resulting proof term is:
312\DM{
466\DM{
313\AR{
467\AR{
314\hole{\vk}{\Nat}\SC
468\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
316\\
470\\
317−\hole{\vys}{\Vect\:\TC{Int}\:(\suc\:\vk)}\SC\vys
471+\hole{\vys}{\Vect\;\TC{Int}\;(\suc\;\vk)}\SC\vys
318}
472}
319}
473}
320
474
@@ -325,7 +479,7 @@ the guess is substituted into its scope:
325\DM{
479\DM{
326\PA{\A}{
480\PA{\A}{
327\MO{Solve}_\Gamma & (\guess{\vx}{\vT}{\vv}\SC\ve) &
481\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$)}}
329}
483}
330}
484}
331
485
@@ -335,14 +489,16 @@ computational force. Once a term is complete in a guess binding, it may be subst
335scope of the binding safely.
489scope of the binding safely.
336In each of these tactics, if any step fails, or the term in focus does not take
490In each of these tactics, if any step fails, or the term in focus does not take
337the correct form (e.g. is not a guess in the case of $\MO{Solve}$ or not a hole
491the 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
339handle failure using the $\MO{Try}$ tactic combinator:
493handle failure using the $\MO{Try}$ tactic combinator:
340
494
341\DM{
495\DM{
342\PA{\A\A\A}{
496\PA{\A\A\A}{
343\MO{Try}_\Gamma & \VV{t1} & \VV{t2} & \vt &
497\MO{Try}_\Gamma & \VV{t1} & \VV{t2} & \vt &
344− \MoRet{\AR{\VV{t1}_\Gamma\:\vt\hg\mbox{(if $\VV{t1}$ succeeds)} \\
498+ \MoRet{\RW{case}\;\AR{\VV{t1}_\Gamma\;\vt\;\RW{of}\\
499+ \MO{Success}\;\vt'\cq\MO{Success}\;\vt'\\
345− \VV{t2}_\Gamma\:\vt\hg\mbox{(otherwise)}}}
500+ \MO{Failure}\;\_\cq\VV{t2}_\Gamma\;\vt\\
501+ }}
346}
502}
347}
503}
348
504
@@ -358,23 +514,23 @@ binding requires that the goal normalises to a function type:
358\DM{
514\DM{
359\PA{\A\A}{
515\PA{\A\A}{
360\MO{Lambda}_\Gamma & \vn & (\hole{\vx}{\vT}\SC\vx) &
516\MO{Lambda}_\Gamma & \vn & (\hole{\vx}{\vT}\SC\vx) &
361− \MoRet{\RW{do}\:\AR{
517+ \MoRet{\RW{do}\;\AR{
362− \all{\vy}{\vS}\SC\vT'\:\leftarrow\:\Eval\:\vT \\
518+ \all{\vy}{\vS}\SC\vT'\;\leftarrow\;\Eval\;\vT \\
363− \RW{return}\:\lam{\vn}{\vS}\SC\hole{\vx}{\vT'[\vn/\vy]}\SC\vx
519+ \RW{return}\;\lam{\vn}{\vS}\SC\hole{\vx}{\vT'[\vn/\vy]}\SC\vx
364 }
520 }
365 }
521 }
366}
522}
367}
523}
368
524
369\noindent
525\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}$:
371
527
372\DM{
528\DM{
373\PA{\A\A}{
529\PA{\A\A}{
374−\MO{Pi}_\Gamma & (\vn\Hab\vS) & (\hole{\vx}{\Set}\SC\vx) &
530+\MO{Pi}_\Gamma & (\vn\Hab\vS) & (\hole{\vx}{\Type}\SC\vx) &
375− \MoRet{\RW{do}\:\AR{
531+ \MoRet{\RW{do}\;\AR{
376− \Set\:\leftarrow\:\Check\:\vS\\
532+ \Type\;\leftarrow\;\Check\;\vS\\
377− \RW{return}\:\all{\vn}{\vS}\SC\hole{\vx}{\Set}\SC\vx
533+ \RW{return}\;\all{\vn}{\vS}\SC\hole{\vx}{\Type}\SC\vx
378 }
534 }
379 }
535 }
380}
536}
@@ -386,11 +542,11 @@ Creating a $\LET$ binding requires a type and a value.
386\DM{
542\DM{
387\PA{\A\A}{
543\PA{\A\A}{
388\MO{Let}_\Gamma & (\vn\Hab\vS\defq\vv) & (\hole{\vx}{\vT}\SC\vx) &
544\MO{Let}_\Gamma & (\vn\Hab\vS\defq\vv) & (\hole{\vx}{\vT}\SC\vx) &
389− \MoRet{\RW{do}\:\AR{
545+ \MoRet{\RW{do}\;\AR{
390− \Set\:\leftarrow\:\Check\:\vS\\
546+ \Type\;\leftarrow\;\Check\;\vS\\
391− \vS'\:\leftarrow\:\Check\:\vv\\
547+ \vS'\;\leftarrow\;\Check\;\vv\\
392− \Unify\:\vS\:\vS'\\
548+ \Unify\;\vS\;\vS'\\
393− \RW{return}\:\LET\:\vn\Hab\vS\defq\vv\SC\hole{\vx}{\vT}\SC\vx
549+ \RW{return}\;\LET\;\vn\Hab\vS\defq\vv\SC\hole{\vx}{\vT}\SC\vx
394 }
550 }
395 }
551 }
396}
552}
@@ -400,17 +556,56 @@ Each of these tactics require the term in focus to be of the form $\hole{\vx}{\v
400This is important, because if the scope of the binding were an arbitrary expression $\ve$,
556This is important, because if the scope of the binding were an arbitrary expression $\ve$,
401the binder would be scoped across this \emph{whole} expression rather than the subexpression
557the binder would be scoped across this \emph{whole} expression rather than the subexpression
402$\vx$ as intended.
558$\vx$ as intended.
403−The $\MO{attack}$ tactic ensures that a hole
559+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
560+is in the appropriate form, creating a new hole $\vx'$ which is placed at the
405−of the queue:
561+head of the queue:
406
562
407\DM{
563\DM{
408\PA{\A}{
564\PA{\A}{
409\MO{Attack}_\Gamma & (\hole{\vx}{\vT}\SC\ve) &
565\MO{Attack}_\Gamma & (\hole{\vx}{\vT}\SC\ve) &
566+ \MoRet{\RW{do}\;\AR{
567+ \MO{NewHole}\;\vx'\\
410− \MoRet{\RW{return}\:\guess{\vx}{\vT}{(\hole{\vh}{\vT}\SC\vh)}\SC\ve}
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
411}
577}
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}
412}
601}
413
602
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+
414Finally, we can convert a hole binding to a pattern binding by giving the
609Finally, we can convert a hole binding to a pattern binding by giving the
415pattern variable a name. This solves a hole
610pattern variable a name. This solves a hole
416by adding the pattern binding to the proof state, and updating the proof term
611by adding the pattern binding to the proof state, and updating the proof term
@@ -419,9 +614,9 @@ with the pattern variable directly:
419\DM{
614\DM{
420\PA{\A\A}{
615\PA{\A\A}{
421\MO{Pat}_\Gamma & \vn & (\hole{\vx}{\vT}\SC\ve) &
616\MO{Pat}_\Gamma & \vn & (\hole{\vx}{\vT}\SC\ve) &
422− \MoRet{\RW{do}\:\AR{
617+ \MoRet{\RW{do}\;\AR{
423− \MO{PatBind}\:(\vx\Hab\vT)\\
618+ \MO{PatBind}\;(\vn\Hab\vT)\\
424− \RW{return}\:\ve[\vn/\vx]
619+ \RW{return}\;\ve[\vn/\vx]
425 }}
620 }}
426}
621}
427}
622}
@@ -433,54 +628,174 @@ building the right hand side.
433
628
434\subsubsection{Example}
629\subsubsection{Example}
435
630
436−Tactics are executed by a higher level meta-operation $\MO{RunTac}$, which
631+To illustrate how tactics are applied, using $\MO{Tactic}$, to build a
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
632+complete term by refining a proof state, let us consider the following
444\TT{} definition for the identify function:
633\TT{} definition for the identify function:
445
634
446\DM{
635\DM{
447\AR{
636\AR{
448−\FN{id}\Hab\all{\vA}{\Set}\SC\all{\va}{\vA}\SC\vA \\
637+\FN{id}\Hab\all{\vA}{\Type}\SC\all{\va}{\vA}\SC\vA \\
449−\FN{id}\:=\:\lam{\vA}{\Set}\SC\lam{\va}{\vA}\SC\va
638+\FN{id}\;=\;\lam{\vA}{\Type}\SC\lam{\va}{\vA}\SC\va
450}
639}
451}
640}
452
641
453−We can build $\FN{id}$ either as a complete term, or by applying a sequence of tactics.
642+We can build $\FN{id}$ either as a complete term, or by applying a sequence of
454−To achieve this, we create a proof state initialised with the type of $\FN{id}$ and
643+tactics. To achieve this, we create a proof state initialised with the type of
455−apply a series of $\MO{Lambda}$ and $\MO{Fill}$ operations using $\MO{RunTac}$.
644+$\FN{id}$ and apply a series of $\MO{Lambda}$ and $\MO{Fill}$ operations using
456−Note that the types on each $\MO{Lambda}$ are solved by unification:
645+$\MO{Tactic}$. Note that the types on each $\MO{Lambda}$ are taken from
646+the goal type.
457
647
458\DM{
648\DM{
459\AR{
649\AR{
460−\MO{MkId}\:\mq\:\RW{do}\:
650+\MO{MkId}\;\mq\;\RW{do}\;
461 \AR{
651 \AR{
462− \MO{NewProof}\:\all{\vA}{\Set}\SC\all{\va}{\vA}\SC\vA \\
652+ \MO{NewProof}\;\all{\vA}{\Type}\SC\all{\va}{\vA}\SC\vA \\
463− \MO{RunTac}\;\MO{Attack} \\
653+ \MO{Tactic}\;\MO{Attack} \\
464− \MO{RunTac}\;(\MO{Lambda}\;\vA) \\
654+ \MO{Tactic}\;(\MO{Lambda}\;\vA) \\
465− \MO{RunTac}\;\MO{Attack} \\
655+ \MO{Tactic}\;\MO{Attack} \\
466− \MO{RunTac}\;(\MO{Lambda}\;\va) \\
656+ \MO{Tactic}\;(\MO{Lambda}\;\va) \\
467− \MO{RunTac}\;(\MO{Fill}\;\va)\\
657+ \MO{Tactic}\;(\MO{Fill}\;\va)\\
468− \MO{RunTac}\;\MO{Solve}\\
658+ \MO{Tactic}\;\MO{Solve}\\
469− \MO{RunTac}\;\MO{Solve}\\
659+ \MO{Tactic}\;\MO{Solve}\\
470− \MO{RunTac}\;\MO{Solve}\\
660+ \MO{Tactic}\;\MO{Solve}\\
471 \MO{Term}
661 \MO{Term}
472 }
662 }
473}
663}
474}
664}
475
665
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+
476−To aid readability, we will elide $\MO{RunTac}$, and use a semi-colon to indicate
791+To aid readability, we will elide $\MO{Tactic}$, and use a semi-colon to indicate
477sequencing --- in the implementation we use wrapper functions for each tactic to
792sequencing --- in the implementation we use wrapper functions for each tactic to
478−apply $\MO{RunTac}$.
793+apply $\MO{Tactic}$.
479Using this convention, we can build $\FN{id}$'s type and definition as shown
794Using this convention, we can build $\FN{id}$'s type and definition as shown
480in Figure \ref{idelab}. Note that $\MO{Term}$ retrieves the proof term from the current proof
795in Figure \ref{idelab}. Note that $\MO{Term}$ retrieves the proof term from the current proof
481state. Both $\MO{MkIdType}$ and $\MO{MkId}$ finish by returning a completed \TT{} term.
796state. 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,
797+Note in particular that each tactic which introduces a guess ($\MO{Fill}$
483−are closed with a $\MO{Solve}$.
798+and $\MO{Solve}$ is closed with a $\MO{Solve}$).
484
799
485Setting up elaboration in this way, with a proof state captured in a monad,
800Setting up elaboration in this way, with a proof state captured in a monad,
486and a primitive collection of tactics,
801and a primitive collection of tactics,
@@ -492,19 +807,19 @@ a Coq proof script.
492
807
493\FFIG{
808\FFIG{
494\AR{
809\AR{
495−\MO{MkIdType}\:\mq\:\RW{do}\;
810+\MO{MkIdType}\;\mq\;\RW{do}\;
496 \AR{
811 \AR{
497− \MO{NewProof}\:\Set\\
812+ \MO{NewProof}\;\Type\\
498− \MO{Attack} ; \MO{Pi}\:(\vA\Hab\Set) ;
813+ \MO{Attack} ; \MO{Pi}\;(\vA\Hab\Type) ;
499− \MO{Attack} ; \MO{Pi}\:(\va\Hab\vA) \\
814+ \MO{Attack} ; \MO{Pi}\;(\va\Hab\vA) \\
500 \MO{Fill}\;\vA \\
815 \MO{Fill}\;\vA \\
501 \MO{Solve} ; \MO{Solve} ; \MO{Solve} \\
816 \MO{Solve} ; \MO{Solve} ; \MO{Solve} \\
502 \MO{Term}
817 \MO{Term}
503 }
818 }
504 \medskip\\
819 \medskip\\
505−\MO{MkId}\:\mq\:\RW{do}\;
820+\MO{MkId}\;\mq\;\RW{do}\;
506 \AR{
821 \AR{
507− \vt\:\leftarrow\:\MO{MkIdType}; \MO{NewProof}\:\vt\\
822+ \vt\;\leftarrow\;\MO{MkIdType}; \MO{NewProof}\;\vt\\
508 \MO{Attack} ; \MO{Lambda}\;\vA ;
823 \MO{Attack} ; \MO{Lambda}\;\vA ;
509 \MO{Attack} ; \MO{Lambda}\;\va \\
824 \MO{Attack} ; \MO{Lambda}\;\va \\
510 \MO{Fill}\;\va \\
825 \MO{Fill}\;\va \\
@@ -535,11 +850,61 @@ a Coq proof script.
535%\DM{
850%\DM{
536%}
851%}
537
852
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+
538\subsection{Elaborating Expressions}
903\subsection{Elaborating Expressions}
539
904
540−\newcommand{\piimp}[2]{\mbox{\texttt{\{ $#1$ : $#2$ \} -> }}}
905+\newcommand{\piimp}[2]{\mbox{\texttt{\{$#1$ : $#2$\} -> }}}
541%\mathtt{\{}#1\mathtt{:}#2\mbox{\texttt{\} -> }}}
906%\mathtt{\{}#1\mathtt{:}#2\mbox{\texttt{\} -> }}}
542−\newcommand{\piexp}[2]{\mbox{\texttt{( $#1$ : $#2$ ) -> }}}
907+\newcommand{\piexp}[2]{\mbox{\texttt{($#1$ : $#2$) -> }}}
543%\newcommand{\piexp}[2]{\mathtt{(}#1\mathtt{:}#2\mbox{\texttt{) -> }}}
908%\newcommand{\piexp}[2]{\mathtt{(}#1\mathtt{:}#2\mbox{\texttt{) -> }}}
544\newcommand{\piconst}[1]{\mbox{\texttt{$#1$ => }}}
909\newcommand{\piconst}[1]{\mbox{\texttt{$#1$ => }}}
545\newcommand{\icase}{\mathtt{case}}
910\newcommand{\icase}{\mathtt{case}}
@@ -563,11 +928,11 @@ a Coq proof script.
563\begin{array}{rll@{\hg}rll}
928\begin{array}{rll@{\hg}rll}
564\ve ::= & \vc & (\mbox{constant}) &
929\ve ::= & \vc & (\mbox{constant}) &
565\mid & \vx & (\mbox{variable}) \\
930\mid & \vx & (\mbox{variable}) \\
566−\mid & \vt & (\mbox{type}) &
567−\mid & \ve\:\ta & (\mbox{function application}) \\
568−\mid & \ilam{\vx}\:\ve & (\mbox{lambda abstraction}) &
931+\mid & \ilam{\vx}\;\ve & (\mbox{lambda abstraction}) &
932+\mid & \ve\;\ta & (\mbox{function application}) \\
569−\mid & \ilet{\vx}{\ve}\:\ve & (\mbox{let binding}) \\
933+\mid & \ilet{\vx}{\ve}\;\ve & (\mbox{let binding}) &
934+\mid & \piexp{\vx}{\vt}\vt & (\mbox{explicit function space}) \\
570−%\mid & \icase\:\ve\:\iof\:\vec{\VV{alt}} & (\mbox{case expression}) &
935+%\mid & \icase\;\ve\;\iof\;\vec{\VV{alt}} & (\mbox{case expression}) &
571%\mid & \mvar{\vx} & (\mbox{metavariable}) \\
936%\mid & \mvar{\vx} & (\mbox{metavariable}) \\
572\mid & \_ & (\mbox{placeholder})
937\mid & \_ & (\mbox{placeholder})
573\end{array}
938\end{array}
@@ -579,11 +944,6 @@ a Coq proof script.
579\end{array}
944\end{array}
580\medskip\\
945\medskip\\
581\begin{array}{rll}
946\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}
587\VV{declty} ::= & \ve & (\mbox{expression}) \\
947\VV{declty} ::= & \ve & (\mbox{expression}) \\
588\mid & \piexp{\vx}{\vt}\VV{declty} & (\mbox{explicit function space}) \\
948\mid & \piexp{\vx}{\vt}\VV{declty} & (\mbox{explicit function space}) \\
589\mid & \piimp{\vx}{\vt}\VV{declty} & (\mbox{implicit function space}) \\
949\mid & \piimp{\vx}{\vt}\VV{declty} & (\mbox{implicit function space}) \\
@@ -611,9 +971,9 @@ a Coq proof script.
611\begin{array}{ll}
971\begin{array}{ll}
612\begin{array}{rll}
972\begin{array}{rll}
613\VV{pclause} ::= &
973\VV{pclause} ::= &
614−\vx\:\ttt\:[\ibar\;\te]\mbox{\texttt{ = }}\ve \hg[\iwhere\;\td]\\
974+\vx\;\ttt\;[\ibar\;\te]\mbox{\texttt{ = }}\ve \hg[\iwhere\;\td]\\
615\mid & \AR{
975\mid & \AR{
616−\vx\:\ttt\:[\ibar\;\te]\;\iwith\;\ve\\
976+\vx\;\ttt\;[\ibar\;\te]\;\iwith\;\ve\\
617\hg\vec{\VV{pclause}}
977\hg\vec{\VV{pclause}}
618}
978}
619\end{array}
979\end{array}
@@ -624,7 +984,7 @@ a Coq proof script.
624\medskip\\
984\medskip\\
625\VV{cdecl} ::= & \iclass\;[\VV{constr}]\;\vx\;(\ihab{\tx}{\ttt})\;\iwhere\;\td
985\VV{cdecl} ::= & \iclass\;[\VV{constr}]\;\vx\;(\ihab{\tx}{\ttt})\;\iwhere\;\td
626\\
986\\
627−\VV{idecl} ::= & \iinstance\:[\VV{constr}]\;\vx\;\ttt\;\iwhere\;\td
987+\VV{idecl} ::= & \iinstance\;[\VV{constr}]\;\vx\;\ttt\;\iwhere\;\td
628\end{array}
988\end{array}
629\end{array}
989\end{array}
630}
990}
@@ -632,13 +992,14 @@ a Coq proof script.
632{\IdrisM{} declarations}
992{\IdrisM{} declarations}
633{idrismd}
993{idrismd}
634
994
995+We will use a subset of full \Idris{}, which we call \IdrisM{}, to explain
635−We define a language \IdrisM{}, with expression syntax given in Figure \ref{idrism}
996+elaboration of expressions. \IdrisM{} expression syntax is given in Figure
636−and declaration syntax given in Figure \ref{idrismd}.
997+\ref{idrism} and declaration syntax given in Figure \ref{idrismd}.
637\IdrisM{} is a subset of \Idris{} without syntactic sugar --- that is, without
998\IdrisM{} is a subset of \Idris{} without syntactic sugar --- that is, without
638tuple syntax, \texttt{do}-notation or infix operators --- and with implicit
999tuple syntax, \texttt{do}-notation or infix operators --- and with implicit
639arguments in types bound explicitly
1000arguments in types bound explicitly
640−(e.g. $\piimp{\va}{\_}\piimp{\vn}{\_}\TC{Vect}\:\va\:\vn$
1001+(e.g. $\piimp{\va}{\_}\piimp{\vn}{\_}\TC{Vect}\;\va\;\vn$
641−instead of simply $\Vect\:\va\:\vn$).
1002+instead of simply $\Vect\;\va\;\vn$).
642Note that we separate implicit and type constraint bindings, to ensure that they
1003Note that we separate implicit and type constraint bindings, to ensure that they
643only appear in top level declarations.
1004only appear in top level declarations.
644It is in general straightforward to
1005It is in general straightforward to
@@ -659,14 +1020,21 @@ than one at a time.
659%Implicit and type class arguments? Expanded at the application site (we need to know
1020%Implicit and type class arguments? Expanded at the application site (we need to know
660%it's the global name after all and we do that by type).
1021%it's the global name after all and we do that by type).
661
1022
662−To elaborate expressions, we define a meta-operation $\ttinterp{\cdot}$ which
1023+To elaborate expressions, we define meta-operations $\ttinterp{\cdot}$ and
663−runs relative to a proof state (see Section \ref{sect:prfstate}). Its effect is
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
664to update the proof state so that the hole in focus contains a representation
1029to update the proof state so that the hole in focus contains a representation
665of the given expression, by applying tactics. We assume that the proof state
1030of the given expression, by applying tactics. We assume that the proof state
666has already been set up, which means that elaboration can always be
1031has already been set up, which means that elaboration can always be
667\remph{type-directed} since the proof state contains the type of the expression we
1032\remph{type-directed} since the proof state contains the type of the expression we
668are building.
1033are building.
669
1034
1035+In all cases except the elaboration of variables and constantes,
1036+$\ttpinterp{\vx}\;=\;\ttinterp{\vx}$.
1037+
670\subsubsection{Elaborating variables and constants}
1038\subsubsection{Elaborating variables and constants}
671
1039
672In the simplest cases, there is a direct translation from an \IdrisM{} expression to
1040In the simplest cases, there is a direct translation from an \IdrisM{} expression to
@@ -675,24 +1043,27 @@ the \MO{Fill} tactic:
675
1043
676\DM{
1044\DM{
677\AR{
1045\AR{
678−\ttinterp{\vx}\:\mq\:\RW{do}\:\MO{Fill}\:\vx;\:\MO{Solve}\\
1046+\ttinterp{\vx}\;\mq\;\RW{do}\;\MO{Fill}\;\vx;\;\MO{Solve}\\
679−\ttinterp{\vc}\:\mq\:\RW{do}\:\MO{Fill}\:\vc;\:\MO{Solve}\\
1047+\ttinterp{\vc}\;\mq\;\RW{do}\;\MO{Fill}\;\vc;\;\MO{Solve}\\
680}
1048}
681}
1049}
682
1050
1051+Since $\MO{Fill}$ creates a guess binding, we use $\MO{Solve}$ to instantiate
683−We need not concern ourselves with type checking variables or constants here --- $\MO{Fill}$
1052+the guess. We need not concern ourselves with type checking variables or
684−will handle this, type checking $\vx$ or $\vc$ and unifying the result with the
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,
685−hole type. If there are any errors, elaboration will fail.
1055+elaboration will fail.
686
1056
687−If we are building the left hand side of a pattern clause, however, there is a problem,
1057+If we are building the left hand side of a pattern clause, however, there is a
688−as it is the left hand side which \remph{defines} variables. In this context, we assume
1058+problem, as it is the left hand side which \remph{defines} variables. In this
689−that attempting to elaborate a variable which does not type check means that the variable
1059+context, we assume that attempting to elaborate a variable which does not type
690−is a pattern variable:
1060+check means that the variable is a pattern variable:
691
1061
692\DM{
1062\DM{
693−\ttinterp{\vx}\:\mq\:
1063+\ttpinterp{\vx}\;\mq\;
694−\MO{Try}\:\AR{(\RW{do}\:\MO{Fill}\:\vx;\:\MO{Solve})\\
1064+\MO{Try}\;\AR{(\RW{do}\;\MO{Fill}\;\vx;\;\MO{Solve})\\
695−(\MO{Pat}\:\vx)\hg\hg\mbox{(If elaborating a left hand side)}}
1065+(\MO{Pat}\;\vx)
1066+}
696}
1067}
697
1068
698We also need to elaborate \remph{placeholders}, which are subexpressions we expect to
1069We 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
700the current hole to the end of the queue with $\MO{Unfocus}$:
1071the current hole to the end of the queue with $\MO{Unfocus}$:
701
1072
702\DM{
1073\DM{
703−\ttinterp{\_}\:\mq\:\MO{Unfocus}
1074+\ttinterp{\_}\;\mq\;\MO{Unfocus}
704}
1075}
705
1076
706−On encountering a placeholder, our assumption is that unification will eventually solve
1077+On encountering a placeholder, our assumption is that unification will
707−the hole. At the end of elaboration, any holes remaining unsolved on the left hand side
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
708−become pattern variables. If there are any unsolved on the right hand side, elaboration
1080+unsolved on the right hand side, elaboration is incomplete and an error will
709−fails.
1081+be reported when the resulting term is type checked.
710
1082
711\subsubsection{Elaborating bindings}
1083\subsubsection{Elaborating bindings}
712
1084
713−To elaborate a $\lambda$-binding, we $\MO{Attack}$ the hole, which must be a function type,
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
714−apply the $\MO{Lambda}$ tactic, elaborate the scope, then $\MO{Solve}$, which discharges
1087+then elaborate the scope and $\MO{Solve}$, which discharges the $\MO{Attack}$:
715−the $\MO{Attack}$:
716
1088
717\DM{
1089\DM{
718−\ttinterp{\ilam{\vx}\ve}\:\mq\:
1090+\ttinterp{\ilam{\vx}\ve}\;\mq\;
719−\RW{do}\:
1091+\RW{do}\;
720\AR{
1092\AR{
721−\MO{Attack};\;\MO{Lambda}\:\vx\\
1093+\MO{Attack};\;\MO{Lambda}\;\vx\\
722\ttinterp{\ve}\\
1094\ttinterp{\ve}\\
723\MO{Solve}
1095\MO{Solve}
724}
1096}
@@ -738,12 +1110,12 @@ scope of the binding.
738
1110
739\DM{
1111\DM{
740\AR{
1112\AR{
741−\ttinterp{\piexp{\vx}{\vt}\ve}\:\mq\:
1113+\ttinterp{\piexp{\vx}{\vt}\ve}\;\mq\;
742−\RW{do}\:
1114+\RW{do}\;
743\AR{
1115\AR{
744−\MO{Attack};\;\MO{Claim}\:(\vX\Hab\Set)\\
1116+\MO{Attack};\;\MO{Claim}\;(\vX\Hab\Type)\\
745−\MO{Pi}\:(\vx\Hab\vX)\\
1117+\MO{Pi}\;(\vx\Hab\vX)\\
746−\MO{Focus}\:\vX\\
1118+\MO{Focus}\;\vX\\
747\ttinterp{\vt};\;
1119\ttinterp{\vt};\;
748\ttinterp{\ve}\\
1120\ttinterp{\ve}\\
749\MO{Solve}
1121\MO{Solve}
@@ -764,13 +1136,13 @@ if elaborating the scope is successful, unification will solve the claimed varia
764$\vV$ and $\vX$.
1136$\vV$ and $\vX$.
765
1137
766\DM{
1138\DM{
767−\ttinterp{\ilet{\vx}{\vv}\:{\ve}}\:\mq\:\RW{do}\:
1139+\ttinterp{\ilet{\vx}{\vv}\;{\ve}}\;\mq\;\RW{do}\;
768\AR{
1140\AR{
769\MO{Attack};\;
1141\MO{Attack};\;
770−\MO{Claim}\:(\vX\Hab\Set);\;
1142+\MO{Claim}\;(\vX\Hab\Type);\;
771−\MO{Claim}\:(\vV\Hab\vX)\\
1143+\MO{Claim}\;(\vV\Hab\vX)\\
772−\MO{Let}\:(\vx\Hab\vX\defq\vV)\\
1144+\MO{Let}\;(\vx\Hab\vX\defq\vV)\\
773−\MO{Focus}\:\vV\\
1145+\MO{Focus}\;\vV\\
774\ttinterp{\vv};\;
1146\ttinterp{\vv};\;
775\ttinterp{\ve}
1147\ttinterp{\ve}
776}
1148}
@@ -788,7 +1160,7 @@ In the first case, the elaborator must expand the application to include implici
788For example \texttt{vAdd xs ys} is expanded to
1160For example \texttt{vAdd xs ys} is expanded to
789\texttt{vAdd \{a=\_\} \{n=\_\} \{\{\_\}\} xs ys}, adding the implicit arguments
1161\texttt{vAdd \{a=\_\} \{n=\_\} \{\{\_\}\} xs ys}, adding the implicit arguments
790\texttt{a} and \texttt{n} and a type class instance argument. The meta-operation
1162\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
792arguments supplied by the programmer $\ta$, returns a new argument list
1164arguments supplied by the programmer $\ta$, returns a new argument list
793$\ta'$ with implicit and type class arguments added. Each value in
1165$\ta'$ with implicit and type class arguments added. Each value in
794$\ta'$ is paired with an explicit name for the argument.
1166$\ta'$ is paired with an explicit name for the argument.
@@ -802,57 +1174,42 @@ forms:
802
1174
803\DM{
1175\DM{
804\AR{
1176\AR{
805−\MO{Unify}_\Gamma\;\vf\:\TC{Int}\\
1177+\MO{Unify}_\Gamma\;\vf\;\TC{Int}\\
806−\MO{Unify}_\Gamma\;(\vf\:\vx)\:\TC{Int}\\
1178+\MO{Unify}_\Gamma\;(\vf\;\vx)\;\TC{Int}\\
807−\MO{Unify}_\Gamma\;(\vf\:\vx)\:(\vg\:\vx)\\
1179+\MO{Unify}_\Gamma\;(\vf\;\vx)\;(\vg\;\vx)\\
808−}
1180+}
809−}
1181+}
810−
1182+
811−The first problem has a solution: $\vf=\TC{Int}$. The second and third problems have
1183+The first problem has a solution: $\vf=\TC{Int}$. The second and third problems
812−no solution without further information. In the second case, we cannot conclude
1184+have no solution without further information. In the second case, we cannot
813−anything about $\vf$ or $\vx$ just from knowing that $\vf\:\vx\:=\:\TC{Int}$.
1185+conclude anything about $\vf$ or $\vx$ just from knowing that
814−In the third case, although we have $\vx\:=\:\vx$ in argument position, we cannot
1186+$\vf\;\vx\;=\;\TC{Int}$. In the third case, although we have $\vx\;=\;\vx$ in
815−conclude that $\vf\:=\:\vg$ unless we know that the function which solves $\vf$ or
1187+argument position, we cannot conclude that $\vf\;=\;\vg$ in general as a
816−$\vg$ is injective.
1188+result.
817−
1189+
818−Once $\vf$ or $\vg$ is solved in some other way, perhaps by being given explicitly
1190+Once $\vf$ or $\vg$ is solved in some other way, perhaps by being given
819−in another argument, these unification problems can make progress. Otherwise, unification
1191+explicitly in another argument, these unification problems can make progress.
820−fails. As a result, the order in which functions and arguments are
1192+Otherwise, unification blocks. In such a case, the elaborator stores the
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
1193+problem (i.e. the expressions to be unified with their local context) and
825−unified with their local context) and refine it with further information when it becomes
1194+refines it with further information when it becomes available.
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
1195+Elaborating a global function application makes a $\MO{Claim}$ for each
831−in turn. Then the function is elaborated, applied to each of the claimed arguments.
1196+argument in turn. Then the function is elaborated, applied to each of the
832−Finally, each argument which has been given explicitly is elaborated. If this fails,
1197+claimed arguments. Each argument which has been given explicitly is
833−elaboration tries again in the opposite order. Finally, any type
1198+elaborated.
834−class instance arguments are resolved with the built-in $\MO{Instance}$ tactic.
1199+Finally, any type class instance arguments are resolved with the
1200+built-in $\MO{Instance}$ tactic.
835
1201
836\DM{
1202\DM{
837−\ttinterp{\vx\:\ta}\:\mq\:
1203+\ttinterp{\vx\;\ta}\;\mq\;
838\AR{
1204\AR{
839−\RW{do}\:
1205+\RW{do}\;
840\AR{
1206\AR{
841−(\tn,\tv)\:\gets\:\MO{Expand}\:\vx\:\ta\\
1207+(\tn,\tv)\;\gets\;\MO{Expand}\;\vx\;\ta\\
842−\vec{\MO{Claim}}\:(\tn\Hab\tT)\\
1208+\vec{\MO{Claim}}\;(\tn\Hab\tT)\\
843−\MO{Try}\:\AR{
844−(\RW{do}\:\AR{
845−\MO{Fill}\:\vx\:\tn\\
1209+\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$)}\\
1210+\vec{\MO{Focus}}\;\tn;\;\ttinterp{\tv}\hg\mbox{(for non-placeholder $\vv$)}\\
851−\MO{Fill}\:\vx\:\tn\\
852−\MO{Solve})
1211+\MO{Solve} \\
853−}}
854−\\
855−\vec{\MO{Instance}}\:\tn\hg\mbox{(for type class constraint argument $\vn$)}
1212+\vec{\MO{Instance}}\;\tn\hg\mbox{(for type class constraint argument $\vn$)}
856}
1213}
857}
1214}
858}
1215}
@@ -862,27 +1219,19 @@ a type class instance which would solve the goal directly. First, it examines th
862context, then recursively searches the global context. $\MO{Instance}$ is covered
1219context, then recursively searches the global context. $\MO{Instance}$ is covered
863in detail in Section \ref{sect:instance}.
1220in detail in Section \ref{sect:instance}.
864
1221
865−To elaborate a simple function application, of an arbitrary expression to an arbitrary
1222+To elaborate a simple function application, of an arbitrary expression to an
866−argument, we need not worry about implicit arguments or class constraints. Instead,
1223+arbitrary argument, we need not worry about implicit arguments or class
867−the function and argument are elaborated, and the results applied. Since elaboration
1224+constraints. Instead, the function and argument are elaborated, and the results
1225+applied. Since elaboration is type directed, however, there must be an
868−is type directed, however, there must be an appropriate type for the function.
1226+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:
871
1227
872\DM{
1228\DM{
873−\ttinterp{\ve\:\va}\:\mq\:\RW{do}\:
1229+\ttinterp{\ve\;\va}\;\mq\;\RW{do}\;
874\AR{
1230\AR{
875−\MO{Claim}\:(\vA\Hab\Set);\;\MO{Claim}\:(\vB\Hab\Set)\\
1231+\MO{Claim}\;(\vA\Hab\Type);\;\MO{Claim}\;(\vB\Hab\Type)\\
876−\MO{Claim}\:(\vf\Hab\vA\to\vB);\;\MO{Claim}\:(\vs\Hab\vA)\\
1232+\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}\\
1233+\MO{Focus}\;\vf;\;\ttinterp{\ve}\\
881−\MO{Focus}\:\vs;\;\ttinterp{\va})}\\
882−(\RW{do}\:\AR{
883−\MO{Focus}\:\vs;\;\ttinterp{\va}\\
1234+\MO{Focus}\;\vs;\;\ttinterp{\va}\\
884−\MO{Focus}\:\vf;\;\ttinterp{\ve})}\\
885−}
886}
1235}
887}
1236}
888
1237
@@ -897,7 +1246,7 @@ relative to the system state (see Section \ref{sect:sysstate}) and has access to
897current proof state. $\MO{Elab}$ uses $\ttinterp{\cdot}$ to help translate
1246current proof state. $\MO{Elab}$ uses $\ttinterp{\cdot}$ to help translate
898\IdrisM{} type, function and class declarations into \TT{} declarations.
1247\IdrisM{} type, function and class declarations into \TT{} declarations.
899
1248
900−\newcommand{\edo}[1]{\RW{do}\:\AR{#1}}
1249+\newcommand{\edo}[1]{\RW{do}\;\AR{#1}}
901
1250
902\subsubsection{Elaborating Type Declarations}
1251\subsubsection{Elaborating Type Declarations}
903
1252
@@ -906,11 +1255,11 @@ translating the \IdrisM{} type to a \TT{} type, then adding the resulting type
906as a \TT{} declaration:
1255as a \TT{} declaration:
907
1256
908\DM{
1257\DM{
909−\MO{Elab}\:(\vx\Hab\vt)\:\mq
1258+\MO{Elab}\;(\vx\Hab\vt)\;\mq
910−\:\edo{\MO{NewProof}\:\Set\\
1259+\;\edo{\MO{NewProof}\;\Type\\
911 \ttinterp{\vt}\\
1260 \ttinterp{\vt}\\
912 \vt'\gets\MO{Term}\\
1261 \vt'\gets\MO{Term}\\
913− \MO{TTDecl}\:(\vx\Hab\vt')
1262+ \MO{TTDecl}\;(\vx\Hab\vt')
914}}
1263}}
915
1264
916The final $\MO{TTDecl}$ takes the result of elaboration, type checks it,
1265The final $\MO{TTDecl}$ takes the result of elaboration, type checks it,
@@ -927,20 +1276,20 @@ adds a \TT{} data declaration.
927
1276
928\DM{
1277\DM{
929\AR{
1278\AR{
930−\MO{Elab}\:(\idata\;\ihab{\vx}{\vt}\;\iwhere\;\tc)\\
1279+\MO{Elab}\;(\idata\;\ihab{\vx}{\vt}\;\iwhere\;\tc)\\
931−\hg\hg\mq\:\edo{\MO{NewProof}\:\Set\\
1280+\hg\hg\mq\;\edo{\MO{NewProof}\;\Type\\
932 \ttinterp{\vt}\\
1281 \ttinterp{\vt}\\
933 \vt'\gets\MO{Term}\\
1282 \vt'\gets\MO{Term}\\
934− \MO{TTDecl}\:(\vx\Hab\vt')\\
1283+ \MO{TTDecl}\;(\vx\Hab\vt')\\
935− \tc'\gets\vec{\MO{ElabCon}}\:\tc\\
1284+ \tc'\gets\vec{\MO{ElabCon}}\;\tc\\
936− \MO{TTDecl}\:(\Data\:\vx\Hab\vt'\:\Where\:\tc')
1285+ \MO{TTDecl}\;(\Data\;\vx\Hab\vt'\;\Where\;\tc')
937}
1286}
938\AR{
1287\AR{
939−\MO{ElabCon}\:(\vx\Hab\vt)\\
1288+\MO{ElabCon}\;(\vx\Hab\vt)\\
940−\hg\hg\mq\: \edo{\MO{NewProof}\:\Set\\
1289+\hg\hg\mq\; \edo{\MO{NewProof}\;\Type\\
941 \ttinterp{\vt}\\
1290 \ttinterp{\vt}\\
942 \vt'\gets\MO{Term}\\
1291 \vt'\gets\MO{Term}\\
943− \RW{return}\:(\vx\Hab\vt')
1292+ \RW{return}\;(\vx\Hab\vt')
944}
1293}
945}}}
1294}}}
946
1295
@@ -953,7 +1302,7 @@ to the global context, such as definitions in $\iwhere$ clauses.
953First, let us consider the simplest case, with no $\iwhere$ clause:
1302First, let us consider the simplest case, with no $\iwhere$ clause:
954
1303
955\DM{
1304\DM{
956−\MO{ElabClause}\:(\vx\:\ttt\:=\:\ve)\:\mq\:?
1305+\MO{ElabClause}\;(\vx\;\ttt\;=\;\ve)\;\mq\;?
957}
1306}
958
1307
959How does the left hand side get elaborated, given that elaboration is type directed, and
1308How 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
962a type $\TC{Infer}$:
1311a type $\TC{Infer}$:
963
1312
964\DM{
1313\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}
966}
1315}
967
1316
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
969extracting the value and unified type when complete.
1318extracting the value and unified type when complete.
970
1319
971\DM{
1320\DM{
972\AR{
1321\AR{
973−\MO{ElabClause}\:(\vx\:\ttt\:=\:\ve)\:\mq\:\\
1322+\MO{ElabClause}\;(\vx\;\ttt\;=\;\ve)\;\mq\;\\
974\hg\hg\edo{
1323\hg\hg\edo{
975−\MO{NewProof}\:\TC{Infer};\;
1324+\MO{NewProof}\;\TC{Infer};\;
976−\ttinterp{\DC{MkInfer}\:\_\:(\vx\:\ttt)}\\
1325+\ttpinterp{\DC{MkInfer}\;\_\;(\vx\;\ttt)}\\
977−\DC{MkInfer}\:\vT\:\VV{lhs}\gets\MO{Term}\\
1326+\DC{MkInfer}\;\vT\;\VV{lhs}\gets\MO{Term}\\
978\tp\gets\MO{Patterns}\\
1327\tp\gets\MO{Patterns}\\
979−\MO{NewTerm}\:\vT;\;
1328+\MO{NewTerm}\;\vT;\;
980\ttinterp{\ve}\\
1329\ttinterp{\ve}\\
981\VV{rhs}\gets\MO{Term}\\
1330\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})
983}
1332}
984}
1333}
985}
1334}
@@ -993,10 +1342,10 @@ the clauses and adding the resulting collection to \TT{}.
993
1342
994\DM{
1343\DM{
995\AR{
1344\AR{
996−\MO{Elab}\:\vec{\VV{pclause}}\:\mq\:
1345+\MO{Elab}\;\vec{\VV{pclause}}\;\mq\;
997\edo{
1346\edo{
998−\tc\gets\vec{\MO{ElabClause}}\:\vec{\VV{pclause}}\\
1347+\tc\gets\vec{\MO{ElabClause}}\;\vec{\VV{pclause}}\\
999−\vec{\MO{TTDecl}}\:\tc
1348+\vec{\MO{TTDecl}}\;\tc
1000}
1349}
1001}
1350}
1002}
1351}
@@ -1008,18 +1357,18 @@ which are then recursively elaborated before the right hand side.
1008
1357
1009\DM{
1358\DM{
1010\AR{
1359\AR{
1011−\MO{ElabClause}\:(\vx\:\ttt\:=\:\ve\:\iwhere\:\td)\:\mq\:\\
1360+\MO{ElabClause}\;(\vx\;\ttt\;=\;\ve\;\iwhere\;\td)\;\mq\;\\
1012\hg\hg\edo{
1361\hg\hg\edo{
1013−\MO{NewProof}\:\TC{Infer};\;
1362+\MO{NewProof}\;\TC{Infer};\;
1014−\ttinterp{\DC{MkInfer}\:\_\:(\vx\:\ttt)}\\
1363+\ttpinterp{\DC{MkInfer}\;\_\;(\vx\;\ttt)}\\
1015−\DC{MkInfer}\:\vT\:\VV{lhs}\gets\MO{Term}\\
1364+\DC{MkInfer}\;\vT\;\VV{lhs}\gets\MO{Term}\\
1016\tp\gets\MO{Patterns}\\
1365\tp\gets\MO{Patterns}\\
1017−(\td', \ve') \gets\MO{Lift}\:\tp\:\td\:\ve\\
1366+(\td', \ve') \gets\MO{Lift}\;\tp\;\td\;\ve\\
1018−\vec{\MO{Elab}}\:\td'\\
1367+\vec{\MO{Elab}}\;\td'\\
1019−\MO{NewTerm}\:\vT;\;
1368+\MO{NewTerm}\;\vT;\;
1020\ttinterp{\ve'}\\
1369\ttinterp{\ve'}\\
1021\VV{rhs}\gets\MO{Term}\\
1370\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})
1023}
1372}
1024}
1373}
1025}
1374}
@@ -1060,32 +1409,74 @@ natToBin' (S (j + j)) odd = True :: natToBin j
1060\useverb{natToBinwp}
1409\useverb{natToBinwp}
1061
1410
1062\noindent
1411\noindent
1063−Elaboration of \texttt{with} builds the type declaration and auxiliary function
1412+Additionally, the elaborator abstracts over the term being analysed in the type
1064−automatically:
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}
1065
1428
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$.
1066
1456
1067\DM{
1457\DM{
1068\AR{
1458\AR{
1069−\MO{ElabClause}\:(\vx\:\ttt\:\iwith\:\ve\:\vec{\VV{pclause}})\:\mq\\
1459+\MO{ElabClause}\;(\vx\;\ttt\;\iwith\;\ve\;\vec{\VV{pclause}})\;\mq\\
1070\hg\hg\edo{
1460\hg\hg\edo{
1071−\MO{NewProof}\:\TC{Infer};\;
1461+\MO{NewProof}\;\TC{Infer};\;
1072−\ttinterp{\DC{MkInfer}\:\_\:(\vx\:\ttt)}\\
1462+\ttinterp{\DC{MkInfer}\;\_\;(\vx\;\ttt)}\\
1073−\DC{MkInfer}\:\vT\:\VV{lhs}\gets\MO{Term}\\
1463+\DC{MkInfer}\;\vT\;\VV{lhs}\gets\MO{Term}\\
1074\tp\gets\MO{Patterns}\\
1464\tp\gets\MO{Patterns}\\
1075−\MO{NewTerm}\:\TC{Infer};\;
1465+\MO{NewTerm}\;\TC{Infer};\;
1076−\ttinterp{\DC{MkInfer}\:\_\:\ve}\\
1466+\ttinterp{\DC{MkInfer}\;\_\;\ve}\\
1077−\DC{MkInfer}\:\vW\:\vw'\gets\MO{Term}\\
1467+\DC{MkInfer}\;\vW\;\vw'\gets\MO{Term}\\
1468+(\tp_w,\tp_n)\;\gets\;\MO{SplitContext}\;\vW\;\tp\\
1078−\MO{TTDecl}\:(\vx'\Hab\tp\to\vW\to\vT)\\
1469+\MO{TTDecl}\;(\vx'\Hab\tp_{w}\to(\ve\Hab\vW)\to\vec{\MO{Abstract}}\;\ve\;\vw'\;\tp_{n}\to\vT)\\
1079−\tc'\gets\vec{\MO{MatchWith}}\:\tp\:(\vx\:\ttt)\:\vec{\VV{pclause}}\\
1470+\tc'\gets\vec{\MO{MatchWith}}\;\tp\;\ttt\;\vec{\VV{pclause}}\\
1080−\vec{\MO{Elab}}\:\tc'\\
1471+\vec{\MO{Elab}}\;\tc'\\
1081−\RW{return}\:(\RW{var}\:\tp\SC\VV{lhs}\:=\:\vx'\:\tp\:\vw')
1472+\RW{return}\;(\RW{var}\;\tp\SC\VV{lhs}\;=\;\vx'\;\tp_{w}\;\vw'\;\tp_{n})
1082}
1473}
1083\medskip\\
1474\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\\
1085\hg\hg\edo{
1476\hg\hg\edo{
1086−\tp'\gets\vec{\MO{Match}}\:\tw\:\ttt\\
1477+\tp'\gets\vec{\MO{Match}}\;\tw\;\ttt\\
1087−\MO{CheckComplete}\:\tp\:\tp'\\
1478+(\tp'_w,\tp'_n)\;\gets\;\MO{SplitPats}\;\tp_w\;\tp_n\;\tp'\\
1088−\RW{return}\:(\vx'\:\tp'\:\ve\:\VV{rhs})
1479+\RW{return}\;(\vx'\;\tp'_w\;\ve\;\tp'_{n}\;\VV{rhs})
1089}
1480}
1090}
1481}
1091}
1482}
@@ -1104,26 +1495,24 @@ $\ve$ which is the same type as the scrutinee of the \texttt{with}, $\vW$.
1104The right hand side, $\VV{rhs}$, may either return a value directly, containing
1495The right hand side, $\VV{rhs}$, may either return a value directly, containing
1105\texttt{where} clauses, or be a nested \texttt{with} block. In any case, it
1496\texttt{where} clauses, or be a nested \texttt{with} block. In any case, it
1106remains unchanged.
1497remains 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
1108the variables in $\vt$ and their matches in $\vw$.
1499the variables in $\vt$ and their matches in $\vw$.
1109−If the \texttt{with} block is well-formed, then
1500+The resulting matches are split, using $\MO{SplitPats}$, into matches for those
1110−the resulting set of patterns $\tp'$ contains exactly the same pattern variables
1501+variables necessary to type $\vW$ and the rest, as before.
1111−as $\tp$, which is verified by $\MO{CheckComplete}$.
1112−
1113
1502
1114\subsubsection{Elaborating Class and Instance Declarations}
1503\subsubsection{Elaborating Class and Instance Declarations}
1115
1504
1116−Type classes are implemented as dictionaries of functions for each instance. Therefore,
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}.
1117−a type class declaration elaborates to a record type containing all of the functions
1507+Therefore, a type class declaration elaborates to a record type containing all
1118−in the class, and an instance is simply an instance of the record. The methods
1508+of the functions in the class, and an instance is simply an instance of the
1119−are translated to top level functions which extract the relevant function from the
1509+record. The methods are translated to top level functions which extract the
1120−dictionary.
1121−For example, for the \texttt{Show} type class, the \texttt{class}
1510+relevant function from the dictionary. For example, for the \texttt{Show} type
1122−declaration is translated to:
1511+class, the \texttt{class} declaration is translated to:
1123
1512
1124\begin{SaveVerbatim}{showdata}
1513\begin{SaveVerbatim}{showdata}
1125
1514
1126−data Show : Set -> Set where
1515+data Show : Type -> Type where
1127 instanceShow : (show : a -> String) -> Show a
1516 instanceShow : (show : a -> String) -> Show a
1128
1517
1129show : Show a -> a -> String
1518show : 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
1137
1526
1138\begin{SaveVerbatim}{shownatf}
1527\begin{SaveVerbatim}{shownatf}
1139
1528
1140−showNat : Show Nat;
1529+showNat : Show Nat
1141showNat = instanceShow show' where
1530showNat = instanceShow show' where
1142 show' : Nat -> String
1531 show' : Nat -> String
1143 show' O = "O"
1532 show' O = "O"
@@ -1182,7 +1571,7 @@ This translates to:
1182
1571
1183\begin{SaveVerbatim}{orddata}
1572\begin{SaveVerbatim}{orddata}
1184
1573
1185−data Ord : Set -> Set where
1574+data Ord : Type -> Type where
1186 instanceOrd : Eq a => (compare : a -> a -> Ordering) ->
1575 instanceOrd : Eq a => (compare : a -> a -> Ordering) ->
1187 (max : a -> a -> a) -> Ord a
1576 (max : a -> a -> a) -> Ord a
1188
1577
@@ -1217,51 +1606,47 @@ In general, \texttt{class} declarations are elaborated as follows:
1217
1606
1218\DM{
1607\DM{
1219\AR{
1608\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)
1221\\
1610\\
1222\hg\hg
1611\hg\hg
1223−\mq\:\RW{do}\:\AR{
1612+\mq\;\RW{do}\;\AR{
1224(\vec{\VV{meth}}\Hab\ttt)\gets\td\\
1613(\vec{\VV{meth}}\Hab\ttt)\gets\td\\
1225−\MO{Elab}\:
1614+\MO{Elab}\;
1226−\AR{(\RW{data}\:\TC{C}\Hab(\ta\Hab\ttt)\to\Set\:\iwhere\\
1615+\AR{(\RW{data}\;\TC{C}\Hab(\ta\Hab\ttt)\to\Type\;\iwhere\\
1227−\hg\DC{InstanceC}\Hab\piconst{\tc}\td\to\TC{C}\:\ta)}
1616+\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\\
1617+\vec{\MO{ElabMeth}}\;(\vec{\VV{meth}}\Hab\ttt)\\
1236−\vec{\MO{ElabParent}}\:\tc
1618+\vec{\MO{ElabParent}}\;\tc
1237}
1619}
1238\medskip\\
1620\medskip\\
1239−\MO{ElabMeth}\:(\vf\Hab\vt)\\
1621+\MO{ElabMeth}\;(\vf\Hab\vt)\\
1240−\hg\hg\mq\:\RW{do}\:\AR{
1622+\hg\hg\mq\;\RW{do}\;\AR{
1241−\MO{Elab}\:(\vf\Hab\TC{C}\:\ta\to\vt)\\
1623+\MO{Elab}\;(\vf\Hab\TC{C}\;\ta\to\vt)\\
1242−\MO{Elab}\:(\vf\:(\DC{InstanceC}\:\vec{\VV{meth}})\:=\:\vec{\VV{meth}[\vf]})
1624+\MO{Elab}\;(\vf\;(\DC{InstanceC}\;\vec{\VV{meth}})\;=\;\vec{\VV{meth}[\vf]})
1243}
1625}
1244\medskip\\
1626\medskip\\
1245−\MO{ElabParent}\:\vc\\
1627+\MO{ElabParent}\;\vc\\
1246−\hg\hg\mq\:\RW{do}\:\AR{
1628+\hg\hg\mq\;\RW{do}\;\AR{
1247−\MO{Elab}\:(\VV{cC}\Hab\TC{C}\:\ta\to\vc)\\
1629+\MO{Elab}\;(\VV{cC}\Hab\TC{C}\;\ta\to\vc)\\
1248−\MO{Elab}\:(\VV{cC}\:(\DC{InstanceC}\:\carg{\vc'}\:\vec{\VV{meth}})\:=\:\vc')
1630+\MO{Elab}\;(\VV{cC}\;(\DC{InstanceC}\;\carg{\vc'}\;\vec{\VV{meth}})\;=\;\vc')
1249}
1631}
1250}
1632}
1251}
1633}
1252
1634
1253\noindent
1635\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}$:
1255
1640
1256\DM{
1641\DM{
1257\AR{
1642\AR{
1258−\MO{Elab}\:(\iinstance\;\piconst{\tc}\TC{C}\:\ttt\:\iwhere\:\td)\\
1643+\MO{Elab}\;(\iinstance\;\piconst{\tc}\TC{C}\;\ttt\;\iwhere\;\td)\\
1259−\hg\hg\mq\:\RW{do}\:\AR{
1644+\hg\hg\mq\;\RW{do}\;\AR{
1260−(\vec{\VV{meth}}, \vec{\VV{ty}})\gets\td\\
1645+(\vec{\VV{meth}}, \vec{\VV{ty}})\gets\MO{ExpandTypes}\;\td\\
1261−\vec{\VV{ty'}}\:=\:\vec{\VV{ty}}[\ttt/\ta]\\
1646+\vec{\VV{ty'}}\;=\;\vec{\VV{ty}}[\ttt/\ta]\\
1262−\MO{Elab}\:(\FN{instanceC}\Hab\piconst{\tc}\TC{C}\:\ttt)\\
1647+\MO{Elab}\;(\FN{instanceC}\Hab\piconst{\tc}\TC{C}\;\ttt)\\
1263−\MO{Elab}\:\AR{
1648+\MO{Elab}\;\AR{
1264−(\FN{instanceC}\:=\:\DC{InstanceC}\;\vec{\VV{meth'}}\;\iwhere
1649+(\FN{instanceC}\;=\;\DC{InstanceC}\;\vec{\VV{meth'}}\;\iwhere
1265\\
1650\\
1266\hg\vec{\VV{meth'}}\Hab\vec{\VV{ty'}}\\
1651\hg\vec{\VV{meth'}}\Hab\vec{\VV{ty'}}\\
1267\hg\td
1652\hg\td
@@ -1295,15 +1680,15 @@ basic primitive for proof search, and is defined as follows:
1295
1680
1296\DM{
1681\DM{
1297\AR{
1682\AR{
1298−\MO{Trivial}\:\mq\:
1683+\MO{Trivial}\;\mq\;
1299−\RW{do}\:\AR{
1684+\RW{do}\;\AR{
1300 (\tv\Hab\ttt)\gets\MO{Context}\\
1685 (\tv\Hab\ttt)\gets\MO{Context}\\
1301− \MO{TryAll}\:\tv
1686+ \MO{TryAll}\;\tv
1302 }
1687 }
1303\medskip\\
1688\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)
1305\\
1690\\
1306−\MO{TryAll}\:\langle\rangle\:\mq\:\MO{Fail}
1691+\MO{TryAll}\;\langle\rangle\;\mq\;\MO{Fail}
1307}
1692}
1308}
1693}
1309
1694
@@ -1324,11 +1709,11 @@ applying every type class instance, and attempting to resolve the instance's par
1324recursively. Given an instance $\vI$ with parameters $\ta$:
1709recursively. Given an instance $\vI$ with parameters $\ta$:
1325
1710
1326\DM{
1711\DM{
1327−\MO{TryInstance}\:(\vI\:\ta)\:\mq\:\RW{do}\;
1712+\MO{TryInstance}\;(\vI\;\ta)\;\mq\;\RW{do}\;
1328\AR{
1713\AR{
1329−\vec{\MO{Claim}}\:(\tx\Hab\ta)\\
1714+\vec{\MO{Claim}}\;(\tx\Hab\ta)\\
1330−\ttinterp{\vI\:\tx}\\
1715+\ttinterp{\vI\;\tx}\\
1331−\vec{\MO{Focus}}\:\tx;\;\vec{\MO{Instance}}
1716+\vec{\MO{Focus}}\;\tx;\;\vec{\MO{Instance}}
1332}
1717}
1333}
1718}
1334
1719
@@ -1336,13 +1721,13 @@ We define $\MO{Instance}$ as follows, using $\MO{AllInstances}$ to retrieve
1336all possible type class instances in the form required by $\MO{TryInstance}$:
1721all possible type class instances in the form required by $\MO{TryInstance}$:
1337
1722
1338\DM{
1723\DM{
1339−\MO{Instance}\:\mq\:
1724+\MO{Instance}\;\mq\;
1340−\MO{Try}\:
1725+\MO{Try}\;
1341\AR{
1726\AR{
1342\MO{Trivial}\\
1727\MO{Trivial}\\
1343−(\RW{do}\:\AR{
1728+(\RW{do}\;\AR{
1344\ti\gets\MO{AllInstances}\\
1729\ti\gets\MO{AllInstances}\\
1345−\vec{\MO{TryInstance}}\:\ti
1730+\vec{\MO{TryInstance}}\;\ti
1346)
1731)
1347}
1732}
1348}
1733}
@@ -1386,9 +1771,9 @@ and $\icase$ expressions:
1386\begin{array}{rll@{\hg}rll}
1771\begin{array}{rll@{\hg}rll}
1387\ve ::= & \ldots \\
1772\ve ::= & \ldots \\
1388\mid & \mvar{\vx} & (\mbox{metavariable}) &
1773\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}) \\
1390\medskip\\
1775\medskip\\
1391−\VV{alt} ::= & \ve\:\fatarrow\:\ve & (\mbox{case alternative})\\
1776+\VV{alt} ::= & \ve\;\fatarrow\;\ve & (\mbox{case alternative})\\
1392\end{array}
1777\end{array}
1393}
1778}
1394}
1779}
@@ -1418,7 +1803,7 @@ We can inspect the type of \texttt{append\_rec} at the \Idris{} prompt:
1418\begin{SaveVerbatim}{appendrec}
1803\begin{SaveVerbatim}{appendrec}
1419
1804
1420*vec> :t append_rec
1805*vec> :t append_rec
1421−append_rec : (a : Set) -> (m : Nat) -> (n : Nat) -> a ->
1806+append_rec : (a : Type) -> (m : Nat) -> (n : Nat) -> a ->
1422 Vect a n -> Vect a m -> Vect a (n + m)
1807 Vect a n -> Vect a m -> Vect a (n + m)
1423
1808
1424\end{SaveVerbatim}
1809\end{SaveVerbatim}
@@ -1441,12 +1826,12 @@ Elaborating a metavariable involves adding a new top level definition which is a
1441to all of the variables in local scope.
1826to all of the variables in local scope.
1442
1827
1443\DM{
1828\DM{
1444−\ttinterp{\mvar{\vx}}\:\mq\:
1829+\ttinterp{\mvar{\vx}}\;\mq\;
1445\edo{
1830\edo{
1446(\tv\Hab\ttt)\gets\MO{Context}\\
1831(\tv\Hab\ttt)\gets\MO{Context}\\
1447\vT\gets\MO{Type}\\
1832\vT\gets\MO{Type}\\
1448−\MO{TTDecl}\:(\vx\Hab(\tv\Hab\ttt)\to\vT)\\
1833+\MO{TTDecl}\;(\vx\Hab(\tv\Hab\ttt)\to\vT)\\
1449−\ttinterp{\vx\:\tv}
1834+\ttinterp{\vx\;\tv}
1450}
1835}
1451}
1836}
1452
1837
@@ -1484,14 +1869,14 @@ and elaborate it:
1484
1869
1485\DM{
1870\DM{
1486\AR{
1871\AR{
1487−\ttinterp{\icase\:\ve\:\iof\:\vec{\VV{alt}}}\:\mq\:
1872+\ttinterp{\icase\;\ve\;\iof\;\vec{\VV{alt}}}\;\mq\;
1488\edo{
1873\edo{
1489−\ttinterp{\ilet{\VV{scrutinee}}{\ve}\:\mvar{\VV{xcase}}}\\
1874+\ttinterp{\ilet{\VV{scrutinee}}{\ve}\;\mvar{\VV{xcase}}}\\
1490(\tv\Hab\ttt)\gets\MO{Context}\\
1875(\tv\Hab\ttt)\gets\MO{Context}\\
1491−\vec{\MO{MkCase}}\:\tv\:\VV{alt}\\
1876+\vec{\MO{MkCase}}\;\tv\;\VV{alt}\\
1492}
1877}
1493\medskip\\
1878\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)
1495}
1880}
1496}
1881}
1497
1882
papers/impl-paper/hll.tex+131−109
@@ -12,7 +12,8 @@ covering the most important features. A full tutorial is available elsewhere
12
12
13\subsection{Preliminaries}
13\subsection{Preliminaries}
14
14
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
16\tTC{Float} for numeric operations, \tTC{Char} and \tTC{String} for
17\tTC{Float} for numeric operations, \tTC{Char} and \tTC{String} for
17text manipulation, and \tTC{Ptr} which represents foreign pointers.
18text manipulation, and \tTC{Ptr} which represents foreign pointers.
18There are also several data types declared in the library, including
19There 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:
25
26
26\begin{SaveVerbatim}{constprims}
27\begin{SaveVerbatim}{constprims}
27
28
28−module main
29+module Main
29
30
30x : Int
31x : Int
31x = 42
32x = 42
@@ -40,14 +41,14 @@ main = putStrLn ("The answer is " ++ show x)
40Like Haskell, the main function
41Like Haskell, the main function
41is called \texttt{main}, and input and output is managed with an \texttt{IO}
42is called \texttt{main}, and input and output is managed with an \texttt{IO}
42monad. Unlike Haskell, however, a single colon indicates \texttt{:} a type
43monad. Unlike Haskell, however, a single colon indicates \texttt{:} a type
43−declaration, emphasising the importance of types,
44+signature, emphasising the importance of types,
44−and \remph{all} functions must have a top level type
45+and \remph{all} top level functions must have a type
45−declaration. This is due to type inference being, in general,
46+signature. This is due to type inference being, in general,
46undecidable for languages with
47undecidable for languages with
47dependent types.
48dependent types.
48
49
49A module declaration also opens a \remph{namespace}. The fully qualified names
50A 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}.
51
52
52
53
53\subsection{Types and Functions}
54\subsection{Types and Functions}
@@ -66,8 +67,7 @@ data List a = Nil | (::) a (List a) -- Polymorphic lists
66\useverb{natlist}
67\useverb{natlist}
67
68
68\noindent
69\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
71the successor of another natural number (\texttt{S k}).
71the successor of another natural number (\texttt{S k}).
72Lists can either be empty (\texttt{Nil})
72Lists can either be empty (\texttt{Nil})
73or a value added to the front of another list (\texttt{x :: xs}).
73or a value added to the front of another list (\texttt{x :: xs}).
@@ -166,24 +166,15 @@ reverse xs = revAcc [] xs where
166Indentation is significant --- functions in the \texttt{where} block must be indented
166Indentation is significant --- functions in the \texttt{where} block must be indented
167further than the outer function.
167further than the outer function.
168
168
169−\textbf{Scope:}
169+\textbf{Remark (scope):}
170−Any names which are visible in the outer scope are also visible in the \texttt{where}
170+Any names which are visible in the outer scope are also visible in the
171−clause (unless they have been redefined, such as \texttt{xs} here).
171+\texttt{where} clause (unless they are redefined in the \texttt{where} clause,
172−\emph{However}, names which appear in the type are \emph{not} automatically
172+such as \texttt{xs} here). A name which appears only in the type will be in
173−in scope. In particular,
173+scope in the \texttt{where} clause if it is a \remph{parameter} to one of the
174−in the above example, the \texttt{a} in the top level type and the \texttt{a} in the
174+types, i.e. it is fixed across the entire structure. In particular, this means
175−auxiliary definition \texttt{revAcc} are \emph{not} the same. If this is the required
175+that the \texttt{a} in the definition of \texttt{reverse} above is the
176−behaviour, the \texttt{a} can be brought into scope as follows:
176+\remph{same} \texttt{a} as in the definition of \texttt{revAcc}, as \texttt{a}
177−
177+is a parameter of \texttt{List}.
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}
187
178
188\subsubsection{Dependent Types}
179\subsubsection{Dependent Types}
189
180
@@ -193,7 +184,7 @@ literature. In \Idris{}, vectors are declared as follows:
193
184
194\begin{SaveVerbatim}{vect}
185\begin{SaveVerbatim}{vect}
195
186
196−data Vect : Set -> Nat -> Set where
187+data Vect : Type -> Nat -> Type where
197 Nil : Vect a O
188 Nil : Vect a O
198 (::) : a -> Vect a k -> Vect a (S k)
189 (::) : a -> Vect a k -> Vect a (S k)
199
190
@@ -201,19 +192,23 @@ data Vect : Set -> Nat -> Set where
201\useverb{vect}
192\useverb{vect}
202
193
203\noindent
194\noindent
204−Note that this uses the same constructor names as for \tTC{List}. Ad-hoc
195+Note that this uses the same constructor names as for \tTC{List}. Ad-hoc name
205−name overloading such as this is accepted by \Idris{}, provided that the names
196+overloading such as this is accepted by \Idris{}, provided that the names are
206−are declared in different namespaces (in practice, normally in different modules).
197+declared in different namespaces (in practice, normally in different modules)
207−Ambiguous constructor names are resolved by type.
198+so that the names are different internally. Namespace resolution can be made
208−
199+explicitly (e.g. \texttt{List.Nil} or \texttt{Vect.Nil}) or more commonly
200+by type.
201+
209−This declares a family of types, which requires a different form of declaration
202+The above declaration creates a family of types, and requires a different form
210−from the simple type declarations above. It resembles a Haskell GADT
203+of declaration from the simple type declarations above. It resembles a Haskell
211−declaration: it explicitly states the type
204+GADT declaration: it explicitly states the type
212of the type constructor \tTC{Vect} --- it takes a type and a \tTC{Nat} as an
205of 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}
206+argument, where \tTC{Type} 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
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.
215−constructor targets a different part of the family of types. \tDC{Nil} can only
210+Each constructor targets a different part of the family of types. \tDC{Nil} can
216−be used to construct vectors with zero length, and \tDC{::} to construct
211+only be used to construct vectors with zero length, and \tDC{::} to construct
217vectors with non-zero length. The type of \tDC{::} states explicitly that an element
212vectors with non-zero length. The type of \tDC{::} states explicitly that an element
218of type \texttt{a} and a tail of type \texttt{Vect a k} (i.e., a vector of length \texttt{k})
213of type \texttt{a} and a tail of type \texttt{Vect a k} (i.e., a vector of length \texttt{k})
219combine to make a vector of length \texttt{S k}.
214combine to make a vector of length \texttt{S k}.
@@ -227,20 +222,20 @@ library, appends two \tTC{Vect}s:
227\begin{SaveVerbatim}{vapp}
222\begin{SaveVerbatim}{vapp}
228
223
229(++) : Vect A n -> Vect A m -> Vect A (n + m)
224(++) : Vect A n -> Vect A m -> Vect A (n + m)
230−(++) Nil ys = ys
225+Nil ++ ys = ys
231−(++) (x :: xs) ys = x :: xs ++ ys
226+(x :: xs) ++ ys = x :: xs ++ ys
232
227
233\end{SaveVerbatim}
228\end{SaveVerbatim}
234\useverb{vapp}
229\useverb{vapp}
235
230
236−\subsubsection{The Finite Sets}
231+\subsubsection*{Example: The Finite Sets}
237
232
238Finite sets, as the name suggests, are sets with a finite number of elements.
233Finite sets, as the name suggests, are sets with a finite number of elements.
239They are declared as follows in the library:
234They are declared as follows in the library:
240
235
241\begin{SaveVerbatim}{findecl}
236\begin{SaveVerbatim}{findecl}
242
237
243−data Fin : Nat -> Set where
238+data Fin : Nat -> Type where
244 fO : Fin (S k)
239 fO : Fin (S k)
245 fS : Fin k -> Fin (S k)
240 fS : Fin k -> Fin (S k)
246
241
@@ -281,11 +276,10 @@ need for a run-time bounds check. The type checker guarantees that the location
281is no larger than the length of the vector.
276is no larger than the length of the vector.
282
277
283Note also that there is no case for \texttt{Nil} here. It would be impossible
278Note 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
279+to apply such a case --- since there is no element of \texttt{Fin O}, and the
286−\texttt{Fin n}, then \texttt{n} can not be \tDC{O}. As a result, attempting to
280+location is a \texttt{Fin n}, then \texttt{n} can not be \tDC{O}. As a result,
287−look up an element in an empty vector would give a compile time type error,
281+attempting to look up an element in an empty vector would give a compile time
288−since it would force \texttt{n} to be \tDC{O}.
282+type error.
289
283
290\subsubsection{Implicit Arguments}
284\subsubsection{Implicit Arguments}
291
285
@@ -317,19 +311,18 @@ their types, to be inferred by the machine. These types could also be given expl
317
311
318\begin{SaveVerbatim}{vindeximpty}
312\begin{SaveVerbatim}{vindeximpty}
319
313
320−index : {a:Set} -> {n:Nat} -> Fin n -> Vect a n -> a
314+index : {a:Type} -> {n:Nat} -> Fin n -> Vect a n -> a
321
315
322\end{SaveVerbatim}
316\end{SaveVerbatim}
323\useverb{vindeximpty}
317\useverb{vindeximpty}
324
318
325\noindent
319\noindent
326−Implicit arguments, given in braces \texttt{\{\}} in the type declaration, are not given in
320+Implicit arguments, given in braces \texttt{\{\}} in the type signature, are
327−applications of \texttt{index}; their values can be inferred from the types of
321+not given in applications of \texttt{index}; their values can be inferred from
328−the \texttt{Fin n} and \texttt{Vect a n} arguments. Any name which appears as a parameter
322+the types of the \texttt{Fin n} and \texttt{Vect a n} arguments. Any name which
329−or index in a type declaration, but which is otherwise free, will be automatically
323+appears as a parameter or index in a type signature, but which is otherwise
330−bound as an implicit argument. Indeed, binding arguments in this way is the essence
324+free, will be automatically bound as an implicit argument. Implicit arguments
331−of dependent types.
332−Implicit arguments can still be given explicitly in applications, using the syntax
325+can still be given explicitly in applications, using the syntax
333\texttt{\{a=value\}} and \texttt{\{n=value\}}, for example:
326\texttt{\{a=value\}} and \texttt{\{n=value\}}, for example:
334
327
335\begin{SaveVerbatim}{vindexexp}
328\begin{SaveVerbatim}{vindexexp}
@@ -354,6 +347,41 @@ index : (i:Fin n) -> (xs:Vect a n) -> a
354This can be useful for improving the readability of type signatures, particularly
347This can be useful for improving the readability of type signatures, particularly
355where the name suggests the argument's purpose.
348where the name suggests the argument's purpose.
356
349
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+
357\subsection{Type Classes}
385\subsection{Type Classes}
358
386
359\Idris{} supports overloading in two ways. Firstly, as we have already seen with
387\Idris{} supports overloading in two ways. Firstly, as we have already seen with
@@ -427,7 +455,7 @@ to a \texttt{String}:
427
455
428instance Show a => Show (Vect a n) where
456instance Show a => Show (Vect a n) where
429 show xs = "[" ++ show' xs ++ "]" where
457 show xs = "[" ++ show' xs ++ "]" where
430− show' : Vect a n' -> String
458+ show' : Vect a n -> String
431 show' Nil = ""
459 show' Nil = ""
432 show' (x :: Nil) = show x
460 show' (x :: Nil) = show x
433 show' (x :: xs) = show x ++ ", " ++ show' xs
461 show' (x :: xs) = show x ++ ", " ++ show' xs
@@ -435,15 +463,16 @@ instance Show a => Show (Vect a n) where
435\end{SaveVerbatim}
463\end{SaveVerbatim}
436\useverb{showvec}
464\useverb{showvec}
437
465
438−\noindent
466+%\noindent
439−\textbf{Remark: } The type of the auxiliary function \texttt{show'} is
467+%\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
468+%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
469+%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
470+%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
471+%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,
472+%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'}.
473+%there is a different name for the length \texttt{n'} in \texttt{show'}.
446
474
475+\noindent
447Like Haskell type classes, default definitions can be given in the class declaration.
476Like Haskell type classes, default definitions can be given in the class declaration.
448Otherwise, all methods must be given in an instance. For example, there is an
477Otherwise, all methods must be given in an instance. For example, there is an
449\texttt{Eq} class:
478\texttt{Eq} class:
@@ -484,41 +513,41 @@ class Eq a => Ord a where
484
513
485\subsection{Matching on intermediate values}
514\subsection{Matching on intermediate values}
486
515
487−\subsubsection{\texttt{let} bindings}
516+%\subsubsection{\texttt{let} bindings}
488−
517+%
489−Intermediate values can be calculated using \texttt{let} bindings:
518+%Intermediate values can be calculated using \texttt{let} bindings:
490−
519+%
491−\begin{SaveVerbatim}{letb}
520+%\begin{SaveVerbatim}{letb}
492−
521+%
493−mirror : List a -> List a
522+%mirror : List a -> List a
494−mirror xs = let xs' = rev xs in
523+%mirror xs = let xs' = rev xs in
495− app xs xs'
524+% app xs xs'
496−
525+%
497−\end{SaveVerbatim}
526+%\end{SaveVerbatim}
498−\useverb{letb}
527+%\useverb{letb}
499−
528+%
500−\noindent
529+%\noindent
501−Pattern matching is also supported in \texttt{let} bindings. For example, extracting
530+%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:
531+%fields from a record can be achieved as follows, as well as by pattern matching at the top level:
503−
532+%
504−\begin{SaveVerbatim}{letp}
533+%\begin{SaveVerbatim}{letp}
505−
534+%
506−data Person = MkPerson String Int
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}
507
543
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}
514\subsubsection{\texttt{case} expressions}
544\subsubsection{\texttt{case} expressions}
515
545
516−Another way of inspecting intermediate values of \emph{simple} types
546+Intermediate values of \emph{non-dependent} types can be inspected using a
517−is to use a \texttt{case} expression.
518−For example, \texttt{list\_lookup}
547+\texttt{case} expression. For example, \texttt{list\_lookup} looks up an index
519−looks up an index in a list, returning \texttt{Nothing} if the index is out
548+in a list, returning \texttt{Nothing} if the index is out of bounds. This can
520−of bounds. This can be used this to write \texttt{lookup\_default}, which
549+be used this to write \texttt{lookup\_default}, which looks up an index and
521−looks up an index and returns a default value if the index is out of bounds:
550+returns a default value if the index is out of bounds:
522
551
523\begin{SaveVerbatim}{listlookup}
552\begin{SaveVerbatim}{listlookup}
524
553
@@ -530,17 +559,10 @@ lookup_default i xs def = case list_lookup i xs of
530\end{SaveVerbatim}
559\end{SaveVerbatim}
531\useverb{listlookup}
560\useverb{listlookup}
532
561
533−The \texttt{case} construct is intended for simple analysis
562+The \texttt{case} construct is intended for simple analysis of intermediate
534−of intermediate expressions to avoid the need to write auxiliary functions, and is
563+expressions to avoid the need to write auxiliary functions. It will
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
564+\emph{only} work if each branch \emph{matches} a value of the same type, and
540−value of the same type.
565+\emph{returns} a 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}
544
566
545\subsubsection{The \texttt{with} rule}
567\subsubsection{The \texttt{with} rule}
546
568
@@ -578,7 +600,7 @@ plus one:
578
600
579\begin{SaveVerbatim}{parity}
601\begin{SaveVerbatim}{parity}
580
602
581−data Parity : Nat -> Set where
603+data Parity : Nat -> Type where
582 even : Parity (n + n)
604 even : Parity (n + n)
583 odd : Parity (S (n + n))
605 odd : Parity (S (n + n))
584
606
papers/impl-paper/impldtp.tex+7−6
@@ -10,13 +10,13 @@
10\usepackage{epsfig}
10\usepackage{epsfig}
11%\usepackage{path}
11%\usepackage{path}
12\usepackage{url}
12\usepackage{url}
13−%\usepackage{amsmath,amssymb}
13+%\usepackage{amsmath}
14\usepackage{fancyvrb}
14\usepackage{fancyvrb}
15\usepackage{todonotes}
15\usepackage{todonotes}
16
16
17\newenvironment{template}{\sffamily}
17\newenvironment{template}{\sffamily}
18
18
19−\usepackage{graphics,epsfig}
19+%\usepackage{graphics,epsfig}
20\usepackage{stmaryrd}
20\usepackage{stmaryrd}
21
21
22\input{./macros.ltx}
22\input{./macros.ltx}
@@ -131,10 +131,11 @@ implementation of new high level language constructs.
131
131
132\section*{Acknowledgements}
132\section*{Acknowledgements}
133
133
134−This work was funded by the Scottish Informatics and Computer Science
134+This work was funded by the Scottish Informatics and Computer Science Alliance
135−Alliance (SICSA) and by EU Framework 7 Project No. 248828 (ADVANCE).
135+(SICSA) and by EU Framework 7 Project No. 248828 (ADVANCE). My thanks to
136−My thanks to Kevin Hammond and Vilhelm Sj\"{o}berg for their comments
136+Philip H\"{o}lzenspies, Kevin Hammond and Vilhelm Sj\"{o}berg for their
137−on an earlier draft of this paper.
137+comments on an earlier draft of this paper, and to the anonymous referees for
138+their many insightful and constructive comments.
138
139
139\bibliographystyle{jfp}
140\bibliographystyle{jfp}
140\bibliography{library.bib}
141\bibliography{library.bib}
papers/impl-paper/intro.tex+35−41
@@ -39,12 +39,12 @@ How can we achieve both of these goals?
39
39
40This paper describes a method for elaborating a high level dependently typed
40This paper describes a method for elaborating a high level dependently typed
41functional programming language to a low level core language based on dependent
41functional programming language to a low level core language based on dependent
42−type theory. The method involves building an Embedded Domain Specific Language
42+type theory. The method involves building an elaboration monad which captures
43−(EDSL) for constructing programs in the core language, using \emph{tactics}
43+the state of incomplete programs and a collection of \emph{tactics} for
44−directed by high level program syntax.
44+refining programs, directed by high level program syntax. As we shall see,
45−As we shall see, this method allows higher level language constructs to be
45+this method allows higher level language constructs to be constructed in a
46−constructed in a straightforward manner, without compromising the simplicity
46+straightforward manner, without compromising the simplicity of the underlying
47−of the underlying type theory.
47+type theory.
48
48
49\subsection{Contributions}
49\subsection{Contributions}
50
50
@@ -55,18 +55,18 @@ unification algorithm \cite{Miller1992} and an evaluator. However, it is less
55well understood how to combine these components effectively into a practical
55well understood how to combine these components effectively into a practical
56programming language.
56programming language.
57
57
58−The primary contribution of this paper is
58+The primary contribution of this paper is a tactic based method for translating
59−an EDSL based method for translating programs in a
60−high level dependently typed programming language to a small core type theory,
59+programs in a high level dependently typed programming language to a small core
61−\TT{}, based on UTT \cite{luo1994}. The paper describes the structure of the
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−EDSL including proof and system state, and introduces a collection of \remph{tactics}
62+introduces a collection of \remph{tactics} for manipulating incomplete
63−for manipulating incomplete programs.
64−Secondly, the paper gives a detailed description of the core type theory used
63+programs. Secondly, the paper gives a detailed description of the core type
65−by \Idris{}, including a full description of the typing rules. Finally, through
64+theory used by \Idris{}, including a full description of the typing rules.
66−describing the EDSL and the specific tactics, the paper shows how to extend
65+Finally, through describing the specific tactics, the paper shows how to extend
67−\Idris{} with higher level features.
66+\Idris{} with higher level features. While we apply these ideas to \Idris{}
68−While we apply these ideas to \Idris{} specifically, the method for term construction
67+specifically, the method for term construction is equally applicable to other
69−is equally applicable to other typed programming languages.
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{}.
70
70
71The paper is structured as follows: Section \ref{sect:hll} gives an overview of
71The paper is structured as follows: Section \ref{sect:hll} gives an overview of
72programming in \Idris{}, introducing the high level constructs which will be
72programming in \Idris{}, introducing the high level constructs which will be
@@ -120,10 +120,10 @@ vAdd (x :: xs) (y :: ys) = x + y :: vAdd xs ys
120This illustrates some basic features of \Idris{}:
120This illustrates some basic features of \Idris{}:
121
121
122\begin{itemize}
122\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
124cons operator.
124cons operator.
125−\item Functions are defined by pattern matching, with a top level type declaration.
125+\item Functions are defined by pattern matching, with a top level type signature.
126−Names which are free in the type declaration (\texttt{a} and \texttt{n}) here
126+Names which are free in the type signature (\texttt{a} and \texttt{n}) here
127are implicitly bound.
127are implicitly bound.
128\item The type system ensures that both input vectors are the same length (\texttt{n})
128\item The type system ensures that both input vectors are the same length (\texttt{n})
129and have the same element type (\texttt{a}), and that the element type and length
129and 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
136\Idris{} programs elaborate into a small core language, \TT{}, which is a $\lambda$-calculus
136\Idris{} programs elaborate into a small core language, \TT{}, which is a $\lambda$-calculus
137with dependent types, augmented with algebraic data types and pattern matching.
137with dependent types, augmented with algebraic data types and pattern matching.
138\TT{} programs are fully explicitly typed, including the names \texttt{a} and \texttt{n}
138\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.
140Type classes are also made explicit.
140Type classes are also made explicit.
141The \TT{} translation of \texttt{vAdd} is:
141The \TT{} translation of \texttt{vAdd} is:
142
142
143\DM{
143\DM{
144\AR{
144\AR{
145−\begin{array}{ll}
146−\FN{vAdd} & \Hab(\va\Hab\Set)\to(\vn\Hab\Nat)\to\TC{Num}\:\va\to
145+\FN{vAdd} \Hab(\va\Hab\Type)\to(\vn\Hab\Nat)\to\TC{Num}\;\va\to
147− \Vect\:\va\:\vn\to\Vect\:\va\:\vn\to\Vect\:\va\:\vn\\
146+ \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}\\
147+\RW{var}\;\va\Hab\Type,\;\vc\Hab\TC{Num}\;\va\SC\\
153−\hg\FN{vAdd} & \va & \Z & \vc & (\DC{Nil}\;\va) & (\DC{Nil}\;\va) & \Ret{\DC{Nil}\;\va} \\
148+\hg\FN{vAdd} \; \va \; \Z \; \vc \; (\DC{Nil}\;\va) \; (\DC{Nil}\;\va) \;
154−\multicolumn{5}{l}{
149+\cq\;\DC{Nil}\;\va \\
155−\RW{var}\:\AR{
150+\RW{var}\;\AR{
156−\va\Hab\Set,\:\vk\Hab\Nat,\;\vc\Hab\TC{Num}\;\va,\\
151+\va\Hab\Type,\;\vk\Hab\Nat,\;\vc\Hab\TC{Num}\;\va,\\
157\vx\Hab\va,\;\vxs\Hab\Vect\;\va\;\vk,\;
152\vx\Hab\va,\;\vxs\Hab\Vect\;\va\;\vk,\;
158\vy\Hab\va,\;\vys\Hab\Vect\;\va\;\vk
153\vy\Hab\va,\;\vys\Hab\Vect\;\va\;\vk
159\SC
154\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))
160}
161}
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}
168}
162}
169}
163}
170
164
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
2Any changes to this file will be lost if it is regenerated by Mendeley.
2Any changes to this file will be lost if it is regenerated by Mendeley.
3
3
4−@book{Chlipala2012,
4+@techreport{Haskell98,
5−author = {Chlipala, Adam},
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−file = {:Users/edwin/Documents/Mendeley Desktop/Chlipala/Unknown/Chlipala - 2012 - Certified Programming with Dependent Types.pdf:pdf},
6+author = {{Peyton Jones}, Simon},
7−title = {{Certified Programming with Dependent Types}},
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},
8−year = {2012}
15+year = {2002}
9}
16}
10−@inproceedings{czarnecki2004dsl,
17+@inproceedings{McBride2006,
11−author = {Czarnecki, K. and O’Donnell, J. and Striegnitz, J. and Taha, W.},
18+author = {McBride, C and Goguen, H and McKinna, J},
12−booktitle = {Domain-Specific Program Generation},
19+booktitle = {Types for Proofs and Programs {(TYPES 2006)}},
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},
20+title = {{A few constructions on constructors}},
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},
21+url = {http://www.springerlink.com/index/P4863U0M41396254.pdf},
18−year = {2004}
22+year = {2006}
19}
23}
20−@phdthesis{Brady2005,
24+@article{McBride2005,
21−author = {Brady, Edwin},
25+author = {McBride, Conor},
22−file = {:Users/edwin/Documents/Mendeley Desktop/Brady/Unknown/Brady - 2005 - Practical Implementation of a Dependently Typed Functional Programming Language.pdf:pdf},
26+editor = {Vene, Varmo and Uustalu, Tarmo},
27+isbn = {3540285407},
28+journal = {Advanced Functional Programming},
23keywords = {Dependent Types},
29keywords = {Dependent Types},
24mendeley-tags = {Dependent Types},
30mendeley-tags = {Dependent Types},
25−school = {University of Durham},
31+pages = {130--170},
26−title = {{Practical Implementation of a Dependently Typed Functional Programming Language}},
32+publisher = {Springer},
27−url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.150.8284&rep=rep1&type=pdf},
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},
28year = {2005}
37year = {2005}
29}
38}
30−@inproceedings{Kimmell2012,
39+@article{Okasaki1993,
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},
40+author = {Okasaki, Chris},
32−booktitle = {Programming Languages meets Program Verification},
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},
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},
42+journal = {Journal of functional programming},
62−number = {2},
43+title = {{Red-Black Trees in A Functional Setting}},
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}
44+year = {1993}
69}
45}
70−@misc{The2012b,
46+@inproceedings{Hancock2000,
71−author = {Brooks, Fred},
47+author = {Hancock, Peter and Setzer, Anton},
72−doi = {10.1093/epirev/mxr031},
48+booktitle = {{Proceedings of the 14th Annual Conference of the EACSL on Computer Science Logic}},
73−file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/Unknown/Brooks - Unknown - The Design of Design Chapter 1.pdf:pdf},
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},
74−isbn = {9780321702081},
50+isbn = {3-540-67895-6},
75−issn = {1478-6729},
51+month = aug,
76−pmid = {22215642},
52+pages = {317--331},
77−title = {{The Design of Design Chapter 1}}
53+title = {{Interactive Programs in Dependent Type Theory}},
54+url = {http://dl.acm.org/citation.cfm?id=647850.737221},
55+year = {2000}
78}
56}
79−@article{Chapman2005epigram,
57+@article{Turner2004,
80−author = {Chapman, James and Altenkirch, Thorsten and McBride, Conor},
58+author = {Turner, D A},
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},
59+file = {:Users/edwin/Documents/Mendeley Desktop/Turner/Total Functional Programming/Turner - Total Functional Programming - 2004.pdf:pdf},
82−journal = {Trends in Functional Programming},
60+journal = {Journal of Universal Computer Science},
83−publisher = {Intellect Books},
61+keywords = {functional programming},
84−title = {{Epigram Reloaded: A Standalone Typechecker for {ETT}}},
62+number = {7},
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},
63+pages = {751----768},
64+title = {{Total Functional Programming}},
65+volume = {10},
86−year = {2005}
66+year = {2004}
87}
67}
88−@misc{TheMendeleySupportTeam2011,
68+@phdthesis{norell2007thesis,
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.},
69+author = {Norell, Ulf},
90−address = {London},
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},
91−author = {{The Mendeley Support Team}},
71+keywords = {Dependent Types},
92−booktitle = {Mendeley Desktop},
72+mendeley-tags = {Dependent Types},
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.},
73+publisher = {Citeseer},
97−title = {{Getting Started with Mendeley}},
74+school = {Chalmers University of Technology},
98−url = {http://www.mendeley.com},
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},
99−year = {2011}
77+year = {2007}
100}
78}
101−@phdthesis{Okasaki1996,
79+@article{Wu,
102−author = {Okasaki, Chris},
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},
103−file = {:Users/edwin/Documents/Mendeley Desktop/Okasaki/Unknown/Okasaki - 1996 - Purely Functional Data Structures.pdf:pdf},
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},
104−school = {Carnegie Mellon University},
91+title = {{Pure and Lazy Lambda Mining}}
105−title = {{Purely Functional Data Structures}},
106−year = {1996}
107}
92}
108−@article{mcbride2008functional,
93+@inproceedings{NanevskiAAMorrisett2008,
109−author = {McBride, C. and Paterson, R.},
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.},
110−file = {:Users/edwin/Documents/Mendeley Desktop/McBride, Paterson/Journal of functional programming/McBride, Paterson - 2008 - Functional pearl Applicative programming with effects.pdf:pdf},
95+author = {{Nanevski A A Morrisett}, G B Shinnar A B Govereau P B Birkedal L C},
111−journal = {Journal of functional programming},
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},
112−number = {1},
103+number = {9},
113−pages = {1--13},
104+pages = {229--240},
114−publisher = {Cambridge Univ Press},
105+title = {{Ynot: Dependent types for imperative programs}},
115−title = {{Functional pearl: Applicative programming with effects}},
106+url = {http://www.scopus.com/inward/record.url?eid=2-s2.0-67650032847&partnerID=40&md5=7a5be3083878399cebafda33b1affa6b},
116−url = {http://journals.cambridge.org/production/action/cjoGetFulltext?fulltextid=1457860},
117−volume = {18},
107+volume = {43},
118year = {2008}
108year = {2008}
119}
109}
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+}
120@inproceedings{madhavapeddy2007melange,
149@inproceedings{madhavapeddy2007melange,
121author = {Madhavapeddy, A. and Ho, A. and Deegan, T. and Scott, D. and Sohan, R.},
150author = {Madhavapeddy, A. and Ho, A. and Deegan, T. and Scott, D. and Sohan, R.},
122booktitle = {ACM SIGOPS Operating Systems Review},
151booktitle = {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},
124number = {3},
153number = {3},
125pages = {101--114},
154pages = {101--114},
126publisher = {ACM},
155publisher = {ACM},
@@ -129,243 +158,228 @@ url = {http://dl.acm.org/citation.cfm?id=1273009},
129volume = {41},
158volume = {41},
130year = {2007}
159year = {2007}
131}
160}
132−@inproceedings{lempsink2009type,
161+@inproceedings{czarnecki2004dsl,
133−author = {Lempsink, E. and Leather, S. and L\"{o}h, A.},
162+author = {Czarnecki, K. and O’Donnell, J. and Striegnitz, J. and Taha, W.},
134−booktitle = {Proceedings of the 2009 ACM SIGPLAN workshop on Generic programming},
163+booktitle = {Domain-Specific Program Generation},
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},
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},
136−pages = {61--72},
165+pages = {51--72},
137−publisher = {ACM},
166+publisher = {Springer},
138−title = {{Type-safe diff for families of datatypes}},
167+title = {{DSL implementation in MetaOCaml, Template Haskell, and C++}},
139−url = {http://dl.acm.org/citation.cfm?id=1596624},
168+url = {http://www.springerlink.com/index/NL620EL7N94M161H.pdf},
140−year = {2009}
169+year = {2004}
141}
170}
142−@book{Approach2012,
171+@article{Wadler2001,
143−author = {Hunt, Andrew and Thomas, David},
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.},
144−booktitle = {Carcinogenesis},
173+author = {Wadler, Philip},
145−doi = {10.1093/carcin/bgs054},
174+doi = {10.1007/3-540-59451-5_2},
146−file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/Carcinogenesis/Hunt, Thomas - Unknown - The Pragmatic Programmer Chapter 2.pdf:pdf},
175+editor = {Jeuring, Johan and Meijer, Erik},
147−isbn = {020161622X},
176+file = {:Users/edwin/Documents/Mendeley Desktop/Wadler/Monads for functional programming/Wadler - Monads for functional programming - 2001.pdf:pdf},
148−issn = {1460-2180},
177+isbn = {3540594515},
178+issn = {03029743},
179+journal = {Advanced Functional Programming},
149−number = {3},
180+number = {August 1992},
150−pmid = {22383472},
181+pages = {24--52},
151−title = {{The Pragmatic Programmer Chapter 2}},
182+publisher = {Springer},
152−url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
183+series = {Lecture Notes in Computer Science},
184+title = {{Monads for functional programming}},
185+url = {http://www.springerlink.com/index/715264614rh13340.pdf},
153−volume = {33}
186+volume = {925},
187+year = {2001}
154}
188}
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+}
155−@inproceedings{stump2010resource,
196+@inproceedings{Taha2003,
156−author = {Stump, A. and Austin, E.},
197+author = {Taha, Walid and Nielsson, Michael Florentin},
157−booktitle = {Proceedings of the 4th ACM SIGPLAN workshop on Programming languages meets program verification},
198+booktitle = {Principles of Programming Languages},
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},
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},
159−pages = {27--38},
214+pages = {NP},
160−publisher = {ACM},
215+pmid = {23150082},
161−title = {{Resource typing in Guru}},
216+title = {{Beautiful Code Chapter 24}},
162−url = {http://dl.acm.org/citation.cfm?id=1707796},
217+url = {http://www.ncbi.nlm.nih.gov/pubmed/23150082},
218+volume = {52},
163−year = {2010}
219+year = {2012}
164}
220}
165@article{mcbride2010ornamental,
221@article{mcbride2010ornamental,
166author = {McBride, Conor},
222author = {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},
168journal = {Journal of Functional Programming},
224journal = {Journal of Functional Programming},
169title = {{Ornamental algebras, algebraic ornaments}},
225title = {{Ornamental algebras, algebraic ornaments}},
170url = {http://personal.cis.strath.ac.uk/$\sim$conor/pub/OAAO/Ornament.pdf},
226url = {http://personal.cis.strath.ac.uk/$\sim$conor/pub/OAAO/Ornament.pdf},
171year = {2010}
227year = {2010}
172}
228}
173−@article{Swierstra2011,
229+@inproceedings{Gall2012,
174−author = {Swierstra, W},
230+author = {Gall, Yann Le and Lee, Adam J and Kapdia, Apu},
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},
231+booktitle = {SCMAT},
176−journal = {Journal of Functional Programming},
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},
177−number = {6},
233+isbn = {9781450312950},
234+keywords = {exposure,policy languages,privacy},
178−pages = {575----583},
235+pages = {219--228},
179−title = {{Sorted: Verifying the Problem of the {Dutch National} Flag in {Agda}}},
236+title = {{PlexC : A Policy Language for Exposure Control}},
180−url = {http://journals.cambridge.org/abstract_S0956796811000207},
181−volume = {21},
182−year = {2011}
237+year = {2012}
183}
238}
184−@article{McBride2002,
239+@article{Campbell-moore,
185−author = {McBride, C},
240+author = {Campbell-moore, Catrin},
186−file = {:Users/edwin/Documents/Mendeley Desktop/McBride/Types for proofs and programs ({TYPES 2000})/McBride - 2000 - Elimination with a Motive.pdf:pdf},
241+file = {:Users/edwin/Documents/Mendeley Desktop/Campbell-moore/A Computable Infinitary Logic/Campbell-moore - A Computable Infinitary Logic - Unknown.pdf:pdf},
187−journal = {Types for proofs and programs ({TYPES 2000})},
242+pages = {1--10},
188−title = {{Elimination with a Motive}},
243+title = {{A Computable Infinitary Logic}}
189−url = {http://www.springerlink.com/index/vbpg19305t46f6dm.pdf},
190−year = {2000}
191}
244}
192−@article{Xi1998,
245+@misc{Resolution2012a,
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.},
246+author = {Fall, Kevin R and Stevens, W. Richard},
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},
249doi = {10.1093/epirev/mxr031},
247doi = {10.1093/epirev/mxr031},
250−file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/Unknown/Brooks - Unknown - The Design of Design Chapter 5.pdf:pdf},
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},
251−isbn = {9780321702081},
252issn = {1478-6729},
249issn = {1478-6729},
253−number = {1},
254−pages = {NP},
255pmid = {22215642},
250pmid = {22215642},
256−title = {{The Design of Design Chapter 5}},
251+title = {{TCP/IP Illustrated Volume 1 Chapter 11}}
257−volume = {34}
258}
252}
259−@inproceedings{ko2011modularising,
253+@inproceedings{Pasalic2002,
260−author = {Ko, H.S. and Gibbons, J.},
254+author = {Pa\v{s}alic, Emir and Taha, Walid and Sheard, Tim},
261−booktitle = {Proceedings of the seventh ACM SIGPLAN workshop on Generic programming},
255+booktitle = {International Conference on Functional 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},
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 = {13--24},
263+pages = {218--229},
264−publisher = {ACM},
264+title = {{Tagless staged interpreters for typed languages}},
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},
265+url = {http://dl.acm.org/citation.cfm?id=583852.581499},
266+volume = {37},
267−year = {2011}
267+year = {2002}
268}
268}
269−@book{Choosing2012,
269+@book{Projects,
270−author = {Fowler, Martin},
270+author = {Hunt, Andrew and Thomas, David},
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},
271+file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/The Pragmatic Programmer Chapter 8/Hunt, Thomas - The Pragmatic Programmer Chapter 8 - Unknown.pdf:pdf},
274−isbn = {9780132107549},
272+isbn = {020161622X},
275−issn = {1460-2180},
273+title = {{The Pragmatic Programmer Chapter 8}}
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}
281}
274}
282−@article{marlow2006making,
275+@inproceedings{Wadler1989,
283−author = {Marlow, S. and {Peyton Jones}, S.},
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.},
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},
277+author = {Wadler, Philip},
285−journal = {Journal of Functional Programming},
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},
286−number = {4-5},
282+number = {June},
287−pages = {415--449},
283+pages = {347--359},
288−publisher = {Cambridge University Press},
284+publisher = {ACM},
289−title = {{Making a fast curry: push/enter vs. eval/apply for higher-order languages}},
285+series = {FPCA '89},
286+title = {{Theorems for free!}},
290−url = {http://dl.acm.org/citation.cfm?id=1166018},
287+url = {http://portal.acm.org/citation.cfm?id=99404},
291−volume = {16},
292−year = {2006}
288+year = {1989}
293}
289}
294−@article{Mandelbaum2007,
290+@inproceedings{swierstra2007beauty,
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.},
291+author = {Swierstra, W. and Altenkirch, T.},
296−author = {Mandelbaum, Yitzhak and Fisher, Kathleen and Walker, David and Fernandez, Mary and Gleyzer, Artem},
292+booktitle = {Proceedings of the ACM SIGPLAN workshop on Haskell workshop},
297−doi = {10.1145/1190215.1190231},
293+file = {:Users/edwin/Documents/Mendeley Desktop/Swierstra, Altenkirch/Beauty in the beast/Swierstra, Altenkirch - Beauty in the beast - 2007.pdf:pdf},
298−isbn = {1595935754},
299−issn = {03621340},
300−journal = {SIGPLAN Not},
301−number = {1},
302−pages = {77--83},
294+pages = {25--36},
303publisher = {ACM},
295publisher = {ACM},
304−series = {POPL '07},
296+title = {{Beauty in the beast}},
305−title = {{PADS/ML: a functional data description language}},
297+url = {http://dl.acm.org/citation.cfm?id=1291206},
306−url = {http://doi.acm.org/10.1145/1190216.1190231},
307−volume = {42},
308year = {2007}
298year = {2007}
309}
299}
310−@article{Abel2010,
300+@inproceedings{Xi1999,
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.},
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.},
312−author = {Abel, Andreas},
302+author = {Xi, Hongwei and Pfenning, Frank},
313−file = {:Users/edwin/Documents/Mendeley Desktop/Abel/EPTCS/Abel - 2010 - MiniAgda Integrating Sized and Dependent Types.pdf:pdf},
303+booktitle = {Proceedings of the 26th ACM SIGPLANSIGACT symposium on Principles of programming languages POPL 99},
314−journal = {EPTCS},
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},
315−pages = {1--15},
311+pages = {214--227},
316−title = {{MiniAgda: Integrating Sized and Dependent Types}},
312+publisher = {ACM Press},
317−url = {http://arxiv.org/abs/1012.4896},
313+series = {POPL '99},
314+title = {{Dependent types in practical programming}},
315+url = {http://portal.acm.org/citation.cfm?doid=292540.292560},
318−volume = {43},
316+volume = {26},
319−year = {2010}
317+year = {1999}
320}
318}
321−@article{Hoare1978,
319+@inproceedings{Kimmell2012,
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.},
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},
323−author = {Hoare, C A R},
321+booktitle = {Programming Languages meets Program Verification},
324−doi = {10.1016/0167-6423(87)90028-1},
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},
325−editor = {McKeag, R M and Macnaghten, A M},
323+title = {{Equational reasoning about programs with general recursion and call-by-value semantics}},
326−file = {:Users/edwin/Documents/Mendeley Desktop/Hoare/Communications of the ACM/Hoare - 1978 - Communicating sequential processes.pdf:pdf},
324+url = {http://dl.acm.org/citation.cfm?id=2103780},
327−isbn = {0131532715},
325+year = {2012}
328−issn = {01676423},
326+}
329−journal = {Communications of the ACM},
327+@article{mccann2000packet,
328+author = {McCann, P.J. and Chandra, S.},
329+journal = {ACM SIGCOMM Computer Communication Review},
330−number = {8},
330+number = {4},
331−pages = {666--677},
331+pages = {321--333},
332−pmid = {2142694823583477576},
333publisher = {ACM},
332publisher = {ACM},
334−series = {International Series in Computer Science},
333+title = {{Packet types: abstract specification of network protocol messages}},
335−title = {{Communicating sequential processes}},
334+url = {http://dl.acm.org/citation.cfm?id=347563},
336−url = {http://linkinghub.elsevier.com/retrieve/pii/0167642387900281},
337−volume = {21},
335+volume = {30},
338−year = {1978}
336+year = {2000}
339}
337}
340−@book{Bird2010,
338+@article{McBride2007,
341−author = {Bird, Richard},
339+author = {McBride, Conor and Paterson, Ross},
342−file = {:Users/edwin/Documents/Mendeley Desktop/Bird/Unknown/Bird - 2010 - Pearls of Functional Algorithm Design.pdf:pdf},
340+file = {:Users/edwin/Documents/Mendeley Desktop/McBride, Paterson/Applicative programming with effects/McBride, Paterson - Applicative programming with effects - 2007.pdf:pdf},
343−isbn = {9780521513388},
341+journal = {Journal of functional programming},
344−title = {{Pearls of Functional Algorithm Design}},
342+title = {{Applicative programming with effects}},
343+url = {http://journals.cambridge.org/abstract_S0956796807006326},
345−year = {2010}
344+year = {2007}
346}
345}
347−@inproceedings{oury2008power,
346+@misc{Ferreira2012,
348−author = {Oury, N. and Swierstra, W.},
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.
349−booktitle = {International Conference on Functional Programming},
348+
350−file = {:Users/edwin/Documents/Mendeley Desktop/Oury, Swierstra/International Conference on Functional Programming/Oury, Swierstra - 2008 - The power of Pi.pdf:pdf},
349+
351−keywords = {Dependent Types},
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.
352−mendeley-tags = {Dependent Types},
351+
353−number = {9},
352+
354−pages = {39--50},
353+I think this paper can be accepted, though I have some small comments and suggestions for improvements:
355−publisher = {ACM},
354+
356−title = {{The power of Pi}},
355+
357−url = {http://dl.acm.org/citation.cfm?id=1411213},
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.
358−volume = {43},
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}},
359−year = {2008}
373+year = {2012}
360}
374}
361−@inproceedings{madhavapeddy2010turning,
375+@misc{The2012b,
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.},
376+author = {Brooks, Fred},
363−booktitle = {Proceedings of the 2nd USENIX conference on Hot topics in cloud computing},
377+doi = {10.1093/epirev/mxr031},
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},
378+file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/The Design of Design Chapter 1/Brooks - The Design of Design Chapter 1 - Unknown.pdf:pdf},
365−publisher = {USENIX Association},
379+isbn = {9780321702081},
366−title = {{Turning down the LAMP: software specialisation for the cloud}},
380+issn = {1478-6729},
367−url = {http://dl.acm.org/citation.cfm?id=1863114},
381+pmid = {22215642},
368−year = {2010}
382+title = {{The Design of Design Chapter 1}}
369}
383}
370@book{peyton1987implementation,
384@book{peyton1987implementation,
371author = {{Peyton Jones}, S.L.},
385author = {{Peyton Jones}, S.L.},
@@ -374,390 +388,572 @@ title = {{The implementation of functional programming languages (prentice-hall
374url = {http://dl.acm.org/citation.cfm?id=1096899},
388url = {http://dl.acm.org/citation.cfm?id=1096899},
375year = {1987}
389year = {1987}
376}
390}
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+}
377−@inproceedings{Pasalic2002,
399+@inproceedings{Danielsson2010,
378−author = {Pa\v{s}alic, Emir and Taha, Walid and Sheard, Tim},
400+author = {Danielsson, Nils Anders},
379booktitle = {International Conference on Functional Programming},
401booktitle = {International Conference on Functional Programming},
380−doi = {10.1145/583852.581499},
402+doi = {10.1145/1932681.1863585},
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},
403+file = {:Users/edwin/Documents/Mendeley Desktop/Danielsson/Total parser combinators/Danielsson - Total parser combinators - 2010.pdf:pdf},
382−isbn = {1-58113-487-8},
404+isbn = {978-1-60558-794-3},
383issn = {03621340},
405issn = {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},
385month = sep,
407month = sep,
386number = {9},
408number = {9},
387−pages = {218--229},
409+pages = {285},
388−title = {{Tagless staged interpreters for typed languages}},
410+title = {{Total parser combinators}},
389−url = {http://dl.acm.org/citation.cfm?id=583852.581499},
411+url = {http://dl.acm.org/citation.cfm?id=1932681.1863585},
390−volume = {37},
412+volume = {45},
391−year = {2002}
413+year = {2010}
392}
414}
393−@inproceedings{Brady2010,
415+@inproceedings{augustsson1999exercise,
394−author = {Brady, Edwin and Hammond, Kevin},
416+author = {Augustsson, L. and Carlsson, M.},
395−booktitle = {Proceedings of the 15th ACM SIGPLAN international conference on Functional programming},
417+booktitle = {In Workshop on Dependent Types in Programming, Gothenburg},
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},
418+keywords = {Depe},
397−isbn = {9781605587943},
419+mendeley-tags = {Depe},
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},
420+publisher = {Citeseer},
399−mendeley-tags = {Dependent Types},
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,
400−pages = {297--308},
434+pages = {74--85},
401−publisher = {ACM},
435+publisher = {ACM Press},
402−title = {{Scrapping your inefficient engine: using partial evaluation to improve domain-specific language implementation}},
436+title = {{Putting curry-howard to work}},
403−url = {http://portal.acm.org/citation.cfm?id=1863587},
437+url = {http://dl.acm.org/citation.cfm?id=1088348.1088356},
404−year = {2010}
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}
405}
464}
406@inproceedings{Fournet2011,
465@inproceedings{Fournet2011,
407author = {Fournet, Cedric and Bhargavan, Karthikeyan and Gordon, Andrew D},
466author = {Fournet, Cedric and Bhargavan, Karthikeyan and Gordon, Andrew D},
408booktitle = {Foundations of security analysis and design {VI}},
467booktitle = {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},
410title = {{Cryptographic verification by typing for a sample protocol implementation}},
469title = {{Cryptographic verification by typing for a sample protocol implementation}},
411url = {http://www.springerlink.com/index/V168041M46658R73.pdf},
470url = {http://www.springerlink.com/index/V168041M46658R73.pdf},
412year = {2010}
471year = {2010}
413}
472}
414−@article{landin1966next,
473+@inproceedings{chlipala2010ur,
415−author = {Landin, P.J.},
474+author = {Chlipala, Adam},
416−file = {:Users/edwin/Documents/Mendeley Desktop/Landin/Communications of the ACM/Landin - 1966 - The next 700 programming languages.pdf:pdf},
475+booktitle = {ACM SIGPLAN Notices},
417−journal = {Communications of the ACM},
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},
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},
477+number = {6},
430−pages = {445--456},
478+pages = {122--133},
431publisher = {ACM},
479publisher = {ACM},
432−title = {{Modular verification of security protocol code by typing}},
480+title = {{Ur: statically-typed metaprogramming with type-level record computation}},
433−url = {http://dl.acm.org/citation.cfm?id=1707801.1706350},
481+url = {http://dl.acm.org/citation.cfm?id=1806612},
434volume = {45},
482volume = {45},
435year = {2010}
483year = {2010}
436}
484}
437−@article{Haskell2012a,
485+@article{Fluet,
438−author = {Biancuzzi, F and Warden, S},
486+annote = {0,3
439−doi = {10.1093/epirev/mxr031},
487+
440−file = {:Users/edwin/Documents/Mendeley Desktop/Biancuzzi, Warden/Unknown/Biancuzzi, Warden - Unknown - Masterminds of Programming Chapter 8.pdf:pdf},
488+
441−isbn = {9780596801670},
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.
442−issn = {1478-6729},
490+
443−pmid = {22215642},
491+
444−title = {{Masterminds of Programming Chapter 8}}
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.
445−}
493+I think this would shorten the introduction and give a much better intuition for the rules.},
446−@book{Brady2012,
494+author = {Fluet, Matthew},
447−author = {Hunt, Andrew and Thomas, David},
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},
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},
496+pages = {1--18},
490−publisher = {Springer},
497+title = {{A Type- and Control-Flow Analysis for System F}}
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}
496}
498}
497−@article{Huet1997,
499+@article{Vytiniotis2011,
498−author = {Huet, G},
500+author = {Vytiniotis, Dimitrios and {Peyton Jones}, Simon and Schrijvers, Tom and Sulzmann, Martin},
499−file = {:Users/edwin/Documents/Mendeley Desktop/Huet/{Journal of Functional Programming}/Huet - 1997 - The zipper.pdf:pdf},
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},
500journal = {{Journal of Functional Programming}},
502journal = {{Journal of Functional Programming}},
501−number = {5},
503+number = {4--5},
502−pages = {549----554},
504+pages = {333----412},
503−title = {{The zipper}},
505+title = {{\textsc{OutsideIn}(X) Modular type inference with local assumptions}},
504−url = {http://journals.cambridge.org/abstract_S0956796897002864},
506+url = {http://journals.cambridge.org/abstract_S0956796811000098},
505−volume = {7},
507+volume = {21},
506−year = {1997}
508+year = {2011}
507}
509}
508@inproceedings{Gregoire2005,
510@inproceedings{Gregoire2005,
509author = {Gregoire, Benjamin and Mahboubi, Assia},
511author = {Gregoire, Benjamin and Mahboubi, Assia},
510booktitle = {{Theorem Proving in Higher Order Logics (TPHOLS 2005)}},
512booktitle = {{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},
512pages = {98----113},
514pages = {98----113},
513title = {{Proving Equalities in a Commutative Ring Done Right in Coq}},
515title = {{Proving Equalities in a Commutative Ring Done Right in Coq}},
514url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.61.3041},
516url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.61.3041},
515year = {2005}
517year = {2005}
516}
518}
517−@misc{Bloat,
519+@book{Cryptography2012,
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,
524author = {Anderson, Ross},
520author = {Anderson, Ross},
525−doi = {10.1093/epirev/mxr031},
521+doi = {10.1093/intimm/dxs023},
526−file = {:Users/edwin/Documents/Mendeley Desktop/Anderson/Unknown/Anderson - Unknown - Security Engineering Chapter 3.pdf:pdf},
522+file = {:Users/edwin/Documents/Mendeley Desktop/Anderson/Security Engineering Chapter 5/Anderson - Security Engineering Chapter 5 - Unknown.pdf:pdf},
527isbn = {9780470068526},
523isbn = {9780470068526},
528−issn = {1478-6729},
524+issn = {1460-2377},
529−pmid = {22215642},
525+number = {4},
526+pmid = {22451589},
530−title = {{Security Engineering Chapter 3}}
527+title = {{Security Engineering Chapter 5}},
528+url = {http://www.ncbi.nlm.nih.gov/pubmed/22451589},
529+volume = {24}
531}
530}
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+}
532−@inproceedings{Augustsson1998,
537+@inproceedings{oury2008power,
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.},
538+author = {Oury, N. and Swierstra, W.},
534−author = {Augustsson, Lennart},
535booktitle = {International Conference on Functional Programming},
539booktitle = {International Conference on Functional Programming},
536−doi = {10.1097/MEG.0b013e328342f213},
540+file = {:Users/edwin/Documents/Mendeley Desktop/Oury, Swierstra/The power of Pi/Oury, Swierstra - The power of Pi - 2008.pdf:pdf},
537−file = {:Users/edwin/Documents/Mendeley Desktop/Augustsson/International Conference on Functional Programming/Augustsson - 1998 - Cayenne - a language with dependent types.pdf:pdf},
541+keywords = {Dependent Types},
538−issn = {14735687},
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},
539−keywords = {Depe,Dependent Types},
558+keywords = {Dependent Types},
540−mendeley-tags = {Depe,Dependent Types},
559+mendeley-tags = {Dependent Types},
541number = {1},
560number = {1},
542−pages = {239--250},
561+pages = {69--111},
543−pmid = {21139473},
544−publisher = {ACM Press},
562+publisher = {Cambridge University Press},
545−title = {{Cayenne - a language with dependent types}},
563+title = {{The view from the left}},
546−url = {http://www.cs.chalmers.se/$\sim$augustss/cayenne/paper.ps},
564+url = {http://www.journals.cambridge.org/abstract_S0956796803004829},
547−volume = {23},
565+volume = {14},
548−year = {1998}
566+year = {2004}
549}
567}
550−@book{Hunt,
568+@book{Cryptography2012a,
551−author = {Hunt, Andrew and Thomas, David},
569+author = {Pfleeger, Charles P and Pfleeger, S. L.},
552−booktitle = {Design},
570+booktitle = {Nicotine & tobacco research : official journal of the Society for Research on Nicotine and Tobacco},
553−file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/Design/Hunt, Thomas - Unknown - The Pragmatic Programmer Chapter 4.pdf:pdf},
571+doi = {10.1093/ntr/nts035},
554−isbn = {020161622X},
572+file = {:Users/edwin/Documents/Mendeley Desktop/Pfleeger, Pfleeger/Security in Computing Chapter 2/Pfleeger, Pfleeger - Security in Computing Chapter 2 - 2012.pdf:pdf},
555−title = {{The Pragmatic Programmer Chapter 4}}
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}
556}
583}
557−@article{burrows1990,
584+@phdthesis{Pretnar2010,
558−author = {Burrows, Michael and Abadi, Martin and Needham, Roger},
585+author = {Pretnar, Matija},
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},
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},
560−journal = {ACM Transactions on Computer Systems},
587+school = {University of Edinburgh},
561−pages = {18----36},
588+title = {{The Logic and Handling of Algebraic Effects}},
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}
589+year = {2010}
566}
590}
567−@inproceedings{atkey2009unembedding,
591+@inproceedings{Brady2010,
568−author = {Atkey, R. and Lindley, S. and Yallop, J.},
592+author = {Brady, Edwin and Hammond, Kevin},
569−booktitle = {Proceedings of the 2nd ACM SIGPLAN symposium on Haskell},
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},
570−pages = {37--48},
598+pages = {297--308},
571publisher = {ACM},
599publisher = {ACM},
572−title = {{Unembedding domain-specific languages}},
600+title = {{Scrapping your inefficient engine: using partial evaluation to improve domain-specific language implementation}},
573−url = {http://dl.acm.org/citation.cfm?id=1596644},
601+url = {http://portal.acm.org/citation.cfm?id=1863587},
574−year = {2009}
602+year = {2010}
575}
603}
576−@inproceedings{Brady2011a,
604+@misc{Danielsson2002,
577−address = {New York, New York, USA},
605+author = {Danielsson, Nils Anders and Altenkirch, Thorsten},
578−author = {Brady, Edwin},
606+file = {:Users/edwin/Documents/Mendeley Desktop/Danielsson, Altenkirch/Subtyping, Declaratively/Danielsson, Altenkirch - Subtyping, Declaratively - 2002.pdf:pdf},
579−booktitle = {Proceedings of the 5th {ACM} workshop on Programming languages meets program verification - {PLPV} '11},
607+title = {{Subtyping, Declaratively}},
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}
608+year = {2002}
590}
609}
591−@inproceedings{gibbons2011modularising,
610+@book{Strings2012,
592−author = {Gibbons, J. and Ko, H.S. and Others},
611+author = {Sedgewick, Robert and Wayne, Kevin},
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},
612+booktitle = {Nicotine & tobacco research : official journal of the Society for Research on Nicotine and Tobacco},
594−title = {{Modularising inductive families}},
613+doi = {10.1093/ntr/nts035},
595−url = {http://www.cs.ox.ac.uk/publications/publication5008-abstract.html},
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},
596−year = {2011}
624+year = {2012}
597}
625}
598−@book{An2012,
626+@inproceedings{Augustsson1985,
599−author = {Fowler, Martin},
627+address = {Berlin, Heidelberg},
600−booktitle = {Carcinogenesis},
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},
601−doi = {10.1093/carcin/bgs054},
678+doi = {10.1093/geront/gns026},
602−file = {:Users/edwin/Documents/Mendeley Desktop/Fowler/Carcinogenesis/Fowler - Unknown - Domain Specific Languages Chapter 1.pdf:pdf},
679+file = {:Users/edwin/Documents/Mendeley Desktop/Sedgewick, Wayne/Algorithms Chapter 4/Sedgewick, Wayne - Algorithms Chapter 4 - 2012.pdf:pdf},
603−isbn = {9780132107549},
680+isbn = {9780132762571},
604−issn = {1460-2180},
681+issn = {1758-5341},
682+month = dec,
605−number = {3},
683+number = {6},
606−pmid = {22383472},
684+pages = {NP},
685+pmid = {23150082},
607−title = {{Domain Specific Languages Chapter 1}},
686+title = {{Algorithms Chapter 4}},
608−url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
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}},
609−volume = {33}
701+volume = {34}
610}
702}
611@inproceedings{coquand1986analysis,
703@inproceedings{coquand1986analysis,
612author = {Coquand, T.},
704author = {Coquand, T.},
613booktitle = {{Proceedings of the First IEEE Symposium on Logic in Computer Science}},
705booktitle = {{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},
615pages = {227----246},
707pages = {227----246},
616title = {{An analysis of Girard's paradox}},
708title = {{An analysis of Girard's paradox}},
617url = {http://hal.inria.fr/docs/00/07/60/23/PDF/RR-0531.pdf},
709url = {http://hal.inria.fr/docs/00/07/60/23/PDF/RR-0531.pdf},
618year = {1986}
710year = {1986}
619}
711}
620−@misc{altenkirch2008nσ,
712+@book{Harper2012,
621−author = {Altenkirch, T. and Oury, N.},
713+author = {Harper, Robert},
622−file = {:Users/edwin/Documents/Mendeley Desktop/Altenkirch, Oury/Unknown/Altenkirch, Oury - 2008 - $Pi$$Sigma$ A Core Language for Dependently Typed Programming.pdf:pdf},
714+file = {:Users/edwin/Documents/Mendeley Desktop/Harper/Practical Foundations for Programming Languages/Harper - Practical Foundations for Programming Languages - 2012.pdf:pdf},
623−title = {{$\Pi$$\Sigma$: A Core Language for Dependently Typed Programming}},
715+title = {{Practical Foundations for Programming Languages}},
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},
657year = {2012}
716year = {2012}
658}
717}
659−@book{luo1994,
718+@misc{dagand2011transporting,
660−author = {Luo, Z.},
719+author = {Dagand, Pierre-Evariste and McBride, Conor},
661−publisher = {Oxford University Press, Inc.},
720+file = {:Users/edwin/Documents/Mendeley Desktop/Dagand, McBride/Transporting Functions across Ornaments/Dagand, McBride - Transporting Functions across Ornaments - 2011.pdf:pdf},
662−title = {{Computation and reasoning: a type theory for computer science}},
721+title = {{Transporting Functions across Ornaments}},
663−url = {http://dl.acm.org/citation.cfm?id=SERIES9893.184757},
722+url = {http://personal.cis.strath.ac.uk/$\sim$dagand/stuffs/paper-2011-patch/paper.pdf},
664−year = {1994}
723+year = {2011}
665}
724}
666−@phdthesis{norell2007thesis,
725+@article{Abel2010,
667−author = {Norell, Ulf},
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.},
668−file = {:Users/edwin/Documents/Mendeley Desktop/Norell/Unknown/Norell - 2007 - Towards a practical programming language based on dependent type theory.pdf:pdf},
727+author = {Abel, Andreas},
669−keywords = {Dependent Types},
728+file = {:Users/edwin/Documents/Mendeley Desktop/Abel/MiniAgda Integrating Sized and Dependent Types/Abel - MiniAgda Integrating Sized and Dependent Types - 2010.pdf:pdf},
670−mendeley-tags = {Dependent Types},
729+journal = {EPTCS},
671−publisher = {Citeseer},
730+pages = {1--15},
672−school = {Chalmers University of Technology},
731+title = {{MiniAgda: Integrating Sized and Dependent Types}},
673−title = {{Towards a practical programming language based on dependent type theory}},
732+url = {http://arxiv.org/abs/1012.4896},
674−url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.65.7934&amp;rep=rep1&amp;type=pdf},
733+volume = {43},
675−year = {2007}
734+year = {2010}
676}
735}
677−@inproceedings{Brady2006b,
736+@article{burrows1990,
678−author = {Brady, Edwin},
737+author = {Burrows, Michael and Abadi, Martin and Needham, Roger},
679−booktitle = {Implementation and Application of Functional Languages ({IFL}'06)},
738+file = {:Users/edwin/Documents/Mendeley Desktop/Burrows, Abadi, Needham/A logic of authentication/Burrows, Abadi, Needham - A logic of authentication - 1990.pdf:pdf},
680−file = {:Users/edwin/Documents/Mendeley Desktop/Brady/Implementation and Application of Functional Languages ({IFL}'06)/Brady - 2006 - Ivor, a proof engine.pdf:pdf},
739+journal = {ACM Transactions on Computer Systems},
681−isbn = {978-3-540-74129-9},
740+pages = {18----36},
682−month = sep,
741+title = {{A logic of authentication}},
683−pages = {145----162},
742+url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.115.3569},
684−title = {{Ivor, a proof engine}},
743+volume = {8},
685−url = {http://dl.acm.org/citation.cfm?id=1757028.1757037},
744+year = {1990}
686−year = {2006}
687}
745}
688−@inproceedings{chlipala2010ur,
746+@article{loh2010tutorial,
689−author = {Chlipala, Adam},
747+author = {L\"{o}h, A. and McBride, C. and Swierstra, W.},
690−booktitle = {ACM SIGPLAN Notices},
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},
691−file = {:Users/edwin/Documents/Mendeley Desktop/Chlipala/ACM SIGPLAN Notices/Chlipala - 2010 - Ur statically-typed metaprogramming with type-level record computation.pdf:pdf},
749+journal = {Fundamenta Informaticae},
692−number = {6},
750+number = {2},
693−pages = {122--133},
751+pages = {177--207},
694−publisher = {ACM},
752+publisher = {IOS Press},
695−title = {{Ur: statically-typed metaprogramming with type-level record computation}},
753+title = {{A tutorial implementation of a dependently typed lambda calculus}},
696−url = {http://dl.acm.org/citation.cfm?id=1806612},
754+url = {http://iospress.metapress.com/index/976W4716TM79M6U8.pdf},
697−volume = {45},
755+volume = {102},
698year = {2010}
756year = {2010}
699}
757}
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+}
700@misc{Abadi1997,
776@misc{Abadi1997,
701author = {Abadi, Martin and Gordon, Andrew D},
777author = {Abadi, Martin and Gordon, Andrew D},
702booktitle = {4TH ACM CONFERENCE ON COMPUTER AND COMMUNICATIONS SECURITY},
778booktitle = {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},
704pages = {36 -- 47},
780pages = {36 -- 47},
705title = {{A calculus for cryptographic protocols: The spi calculus}},
781title = {{A calculus for cryptographic protocols: The spi calculus}},
706url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.49.2176},
782url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.49.2176},
707year = {1997}
783year = {1997}
708}
784}
709−@inproceedings{McBride2006,
785+@article{Haskell2012a,
710−author = {McBride, C and Goguen, H and McKinna, J},
786+author = {Biancuzzi, F and Warden, S},
711−booktitle = {Types for Proofs and Programs {(TYPES 2006)}},
787+doi = {10.1093/epirev/mxr031},
712−title = {{A few constructions on constructors}},
788+file = {:Users/edwin/Documents/Mendeley Desktop/Biancuzzi, Warden/Masterminds of Programming Chapter 8/Biancuzzi, Warden - Masterminds of Programming Chapter 8 - Unknown.pdf:pdf},
713−url = {http://www.springerlink.com/index/P4863U0M41396254.pdf},
789+isbn = {9780596801670},
714−year = {2006}
790+issn = {1478-6729},
791+pmid = {22215642},
792+title = {{Masterminds of Programming Chapter 8}}
715}
793}
716−@article{Jones2003,
794+@inproceedings{madhavapeddy2010turning,
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.},
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.},
718−author = {Jones, Simon Peyton},
796+booktitle = {Proceedings of the 2nd USENIX conference on Hot topics in cloud computing},
719−editor = {Jones, Simon Peyton},
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},
720−isbn = {0521826144},
798+publisher = {USENIX Association},
721−journal = {Language},
799+title = {{Turning down the LAMP: software specialisation for the cloud}},
722−number = {1},
800+url = {http://dl.acm.org/citation.cfm?id=1863114},
723−publisher = {Cambridge University Press},
801+year = {2010}
724−title = {{Haskell 98 Language and Libraries The Revised Report}},
802+}
725−url = {http://www.amazon.ca/exec/obidos/redirect?tag=citeulike09-20&amp;path=ASIN/0521826144},
803+@misc{Braßel,
726−volume = {13},
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}},
727year = {2003}
830year = {2003}
728}
831}
729−@inproceedings{Visser2008,
832+@book{An2012,
730−author = {Visser, E},
833+author = {Fowler, Martin},
731−booktitle = {Generative and Transformational Techniques in Software Engineering},
834+booktitle = {Carcinogenesis},
732−title = {{WebDSL: A case study in domain-specific language engineering}},
835+doi = {10.1093/carcin/bgs054},
733−url = {http://www.springerlink.com/index/A3213003X6268032.pdf},
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},
734year = {2008}
863year = {2008}
735}
864}
736−@inproceedings{ko2011modularising,
865+@misc{Silkensen2012,
737−author = {Ko, H.S. and Gibbons, J.},
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.
738−booktitle = {Proceedings of the seventh ACM SIGPLAN workshop on Generic programming},
867+
739−pages = {13--24},
868+
740−publisher = {ACM},
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.
741−title = {{Modularising inductive families}},
870+
742−url = {http://dl.acm.org/citation.cfm?id=2036921},
871+
743−year = {2011}
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}
744}
891}
745−@misc{Attacks2012a,
892+@misc{The2012c,
746−author = {Anderson, Ross},
893+author = {Robbins, A and Hannah, E and Lamb, L},
747doi = {10.1093/epirev/mxr031},
894doi = {10.1093/epirev/mxr031},
748−file = {:Users/edwin/Documents/Mendeley Desktop/Anderson/Unknown/Anderson - Unknown - Security Engineering Chapter 18.pdf:pdf},
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},
749−isbn = {9780470068526},
896+isbn = {9780596529833},
750issn = {1478-6729},
897issn = {1478-6729},
751−number = {1},
752−pages = {NP},
753pmid = {22215642},
898pmid = {22215642},
754−title = {{Security Engineering Chapter 18}},
899+title = {{Learning the vi and Vim Editors}}
755−volume = {34}
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}
756}
952}
757@inproceedings{l,
953@inproceedings{l,
758author = {L\"{a}mmel, R. and Jones, S.P.},
954author = {L\"{a}mmel, R. and Jones, S.P.},
759booktitle = {ACM SIGPLAN Notices},
955booktitle = {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},
761number = {3},
957number = {3},
762pages = {26--37},
958pages = {26--37},
763publisher = {ACM},
959publisher = {ACM},
@@ -766,213 +962,303 @@ url = {http://dl.acm.org/citation.cfm?id=640136.604179},
766volume = {38},
962volume = {38},
767year = {2003}
963year = {2003}
768}
964}
769−@inproceedings{Delahaye2000,
965+@phdthesis{Okasaki1996,
770−author = {Delahaye, D},
966+author = {Okasaki, Chris},
771−booktitle = {Logic for Programming and Automated Reasoning},
967+file = {:Users/edwin/Documents/Mendeley Desktop/Okasaki/Purely Functional Data Structures/Okasaki - Purely Functional Data Structures - 1996.pdf:pdf},
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},
968+school = {Carnegie Mellon University},
773−pages = {85----95},
969+title = {{Purely Functional Data Structures}},
774−publisher = {Springer},
970+year = {1996}
775−title = {{A tactic language for the system Coq}},
776−url = {http://www.springerlink.com/index/EFQAH8J88K42VN8T.pdf},
777−year = {2000}
778}
971}
779−@misc{pollack1997believe,
972+@inproceedings{McBride2004b,
780−author = {Pollack, R.},
973+author = {McBride, Conor and McKinna, James},
781−file = {:Users/edwin/Documents/Mendeley Desktop/Pollack/Unknown/Pollack - 1997 - How to believe a machine-checked proof.pdf:pdf},
974+booktitle = {Haskell Workshop},
782−title = {{How to believe a machine-checked proof}},
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},
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},
976+title = {{I am not a number : I am a free variable}},
784−year = {1997}
977+year = {2004}
785}
978}
786−@book{Bertot2004,
979+@inproceedings{Brady2005a,
787−author = {Bertot, Yves and Cast\'{e}ran, Pierre},
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},
788publisher = {Springer},
1000publisher = {Springer},
789−title = {{Interactive theorem proving and program development: {Coq'Art}: the {Calculus of Inductive Constructions}}},
1001+title = {{A gentle introduction to multi-stage programming}},
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},
1002+url = {http://www.springerlink.com/index/JEMT0D8VYN5JB2L8.pdf},
791year = {2004}
1003year = {2004}
792}
1004}
793−@inproceedings{brady2011epic,
1005+@article{Rose,
794−author = {Brady, Edwin},
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.
795−booktitle = {Trends in Functional Programming ({TFP}’11)},
1007+
796−file = {:Users/edwin/Documents/Mendeley Desktop/Brady/Trends in Functional Programming ({TFP}’11)/Brady - 2011 - Epic --- A Library for Generating Compilers.pdf:pdf},
1008+
797−title = {{Epic --- A Library for Generating Compilers}},
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.
798−url = {http://scholar.google.co.uk/scholar?cites=2588300990390214449&as_sdt=2005&sciodt=0,5&hl=en#1},
1010+
799−year = {2011}
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}}
800}
1046}
801−@article{dybjer1994inductive,
1047+@inproceedings{morris2006exploring,
802−author = {Dybjer, P.},
1048+author = {Morris, P. and Altenkirch, T. and McBride, C.},
803−journal = {Formal aspects of computing},
1049+booktitle = {Types for Proofs and Programs},
804−number = {4},
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},
805−pages = {440--465},
1051+pages = {252--267},
806publisher = {Springer},
1052publisher = {Springer},
807−title = {{Inductive families}},
1053+title = {{Exploring the regular tree types}},
808−url = {http://www.springerlink.com/index/J17824H467X6J288.pdf},
1054+url = {http://www.springerlink.com/index/f9p1317716614834.pdf},
809−volume = {6},
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},
810year = {1994}
1074year = {1994}
811}
1075}
812−@inproceedings{McBride2004b,
1076+@misc{Hancock,
813−author = {McBride, Conor and McKinna, James},
1077+author = {Hancock, Peter and Setzer, Anton},
814−booktitle = {Haskell Workshop},
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},
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},
1079+keywords = {dependent types,functional programming,interac-,monadic i,o,reactive programming,refinement,repetition constructs,tion},
816−title = {{I am not a number : I am a free variable}},
1080+title = {{Interactive Programs in Dependent Type Theory}},
817−year = {2004}
1081+year = {2000}
818}
1082}
819−@article{Wadler2001,
1083+@book{Chlipala2012,
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.},
1084+author = {Chlipala, Adam},
821−author = {Wadler, Philip},
1085+file = {:Users/edwin/Documents/Mendeley Desktop/Chlipala/Certified Programming with Dependent Types/Chlipala - Certified Programming with Dependent Types - 2012.pdf:pdf},
822−doi = {10.1007/3-540-59451-5_2},
1086+title = {{Certified Programming with Dependent Types}},
823−editor = {Jeuring, Johan and Meijer, Erik},
1087+year = {2012}
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}
836}
1088}
837−@inproceedings{taha1997multi,
1089+@article{Mandelbaum2007,
838−author = {Taha, W. and Sheard, T.},
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.},
839−booktitle = {ACM SIGPLAN Notices},
1091+author = {Mandelbaum, Yitzhak and Fisher, Kathleen and Walker, David and Fernandez, Mary and Gleyzer, Artem},
840−number = {12},
1092+doi = {10.1145/1190215.1190231},
841−pages = {203--217},
1093+isbn = {1595935754},
1094+issn = {03621340},
1095+journal = {SIGPLAN Not},
1096+number = {1},
1097+pages = {77--83},
842publisher = {ACM},
1098publisher = {ACM},
843−title = {{Multi-stage programming with explicit annotations}},
1099+series = {POPL '07},
844−url = {http://dl.acm.org/citation.cfm?id=259019},
1100+title = {{PADS/ML: a functional data description language}},
845−volume = {32},
1101+url = {http://doi.acm.org/10.1145/1190216.1190231},
846−year = {1997}
1102+volume = {42},
1103+year = {2007}
847}
1104}
848−@article{loh2010tutorial,
1105+@article{Nabais2008,
849−author = {L\"{o}h, A. and McBride, C. and Swierstra, W.},
1106+author = {Nabais, Davide},
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},
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},
851−journal = {Fundamenta Informaticae},
1108+journal = {Most},
852−number = {2},
1109+pages = {1--5},
853−pages = {177--207},
1110+title = {{DesCo : a Web Based Information System for Descriptional Complexity of Formal Languages}},
854−publisher = {IOS Press},
1111+year = {2008}
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}
859}
1112}
860−@book{Philosophy2012,
1113+@book{Edition2012,
861−author = {Hunt, Andrew and Thomas, David},
1114+author = {Pfleeger, Charles P and Pfleeger, S. L.},
862−booktitle = {Carcinogenesis},
1115+booktitle = {Nicotine & tobacco research : official journal of the Society for Research on Nicotine and Tobacco},
863−doi = {10.1093/carcin/bgs054},
1116+doi = {10.1093/ntr/nts035},
864−file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/Carcinogenesis/Hunt, Thomas - Unknown - The Pragmatic Programmer Chapter 1.pdf:pdf},
1117+file = {:Users/edwin/Documents/Mendeley Desktop/Pfleeger, Pfleeger/Security in Computing Chapter 1/Pfleeger, Pfleeger - Security in Computing Chapter 1 - 2012.pdf:pdf},
865−isbn = {020161622X},
1118+isbn = {0132390779},
866−issn = {1460-2180},
1119+issn = {1469-994X},
867−number = {3},
1120+month = oct,
868−pmid = {22383472},
1121+number = {10},
869−title = {{The Pragmatic Programmer Chapter 1}},
1122+pages = {NP},
870−url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
1123+pmid = {23012339},
871−volume = {33}
1124+title = {{Security in Computing Chapter 1}},
1125+url = {http://www.ncbi.nlm.nih.gov/pubmed/23012339},
1126+volume = {14},
1127+year = {2012}
872}
1128}
873−@inproceedings{pollack1990implicit,
1129+@book{Eap,
874−author = {Pollack, R.},
1130+author = {Fall, Kevin R and Stevens, W. Richard},
875−booktitle = {{Informal Proceedings of First Workshop on Logical Frameworks, Antibes}},
1131+file = {:Users/edwin/Documents/Mendeley Desktop/Fall, Stevens/TCPIP Illustrated Chapter 18/Fall, Stevens - TCPIP Illustrated Chapter 18 - Unknown.pdf:pdf},
876−file = {:Users/edwin/Documents/Mendeley Desktop/Pollack/{Informal Proceedings of First Workshop on Logical Frameworks, Antibes}/Pollack - 1990 - Implicit syntax.pdf:pdf},
1132+isbn = {9780132808200},
877−publisher = {Citeseer},
1133+title = {{TCP/IP Illustrated Chapter 18}}
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}
881}
1134}
882−@article{gordon2003authenticity,
1135+@book{Fowler,
883−author = {Gordon, A.D. and Jeffrey, A.},
1136+author = {Fowler, Martin},
884−file = {:Users/edwin/Documents/Mendeley Desktop/Gordon, Jeffrey/Journal of computer security/Gordon, Jeffrey - 2003 - Authenticity by typing for security protocols.pdf:pdf},
1137+booktitle = {Language},
885−journal = {Journal of computer security},
1138+file = {:Users/edwin/Documents/Mendeley Desktop/Fowler/Domain Specific Languages Chapter 2/Fowler - Domain Specific Languages Chapter 2 - Unknown.pdf:pdf},
886−number = {4},
1139+isbn = {9780132107549},
887−pages = {451--520},
1140+title = {{Domain Specific Languages Chapter 2}}
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}
893}
1141}
894−@inproceedings{Wadler1989,
1142+@book{Brady2012e,
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.},
1143+author = {Seibel, Peter},
896−author = {Wadler, Philip},
1144+booktitle = {The Gerontologist},
897−booktitle = {Proceedings of the fourth international conference on Functional programming languages and computer architecture},
1145+doi = {10.1093/geront/gns026},
898−doi = {10.1145/99370.99404},
1146+file = {:Users/edwin/Documents/Mendeley Desktop/Seibel/Coders at Work Chapter 9/Seibel - Coders at Work Chapter 9 - 2012.pdf:pdf},
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},
1147+isbn = {9781430219484},
900−isbn = {0897913280},
1148+issn = {1758-5341},
901−number = {June},
1149+month = dec,
902−pages = {347--359},
1150+number = {6},
903−publisher = {ACM},
1151+pages = {NP},
904−series = {FPCA '89},
1152+pmid = {23150082},
905−title = {{Theorems for free!}},
1153+title = {{Coders at Work Chapter 9}},
906−url = {http://portal.acm.org/citation.cfm?id=99404},
1154+url = {http://www.ncbi.nlm.nih.gov/pubmed/23150082},
907−year = {1989}
1155+volume = {52},
1156+year = {2012}
908}
1157}
909−@inproceedings{Augustsson1985,
1158+@article{Regular2012,
910−address = {Berlin, Heidelberg},
1159+author = {Kernighan, Brian},
911−author = {Augustsson, Lennart},
1160+doi = {10.1093/geront/gns026},
912−booktitle = {Functional Programming Languages and Computer Architecture},
1161+file = {:Users/edwin/Documents/Mendeley Desktop/Kernighan/Beautiful Code Chapter 1/Kernighan - Beautiful Code Chapter 1 - 2012.pdf:pdf},
913−doi = {10.1007/3-540-15975-4},
1162+isbn = {9780596510046},
914−editor = {Jouannaud, Jean-Pierre},
1163+issn = {1758-5341},
915−isbn = {978-3-540-15975-9},
1164+month = dec,
916−keywords = {Computer Science},
1165+number = {6},
917−pages = {368----381},
1166+pages = {NP},
918−publisher = {Springer Berlin Heidelberg},
1167+pmid = {23150082},
919−series = {Lecture Notes in Computer Science},
1168+title = {{Beautiful Code Chapter 1}},
920−title = {{Compiling Pattern Matching}},
1169+url = {http://www.ncbi.nlm.nih.gov/pubmed/23150082},
921−url = {http://www.springerlink.com/content/y647423656557505/},
1170+volume = {52},
922−volume = {201},
1171+year = {2012}
923−year = {1985}
924}
1172}
925−@inproceedings{Brady2005a,
1173+@inproceedings{norell2009dependently,
926−author = {Brady, E and Hammond, K},
1174+author = {Norell, Ulf},
927−booktitle = {Implementation and Application of Functional \ldots},
1175+booktitle = {Advanced Functional Programming},
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},
1176+file = {:Users/edwin/Documents/Mendeley Desktop/Norell/Dependently typed programming in Agda/Norell - Dependently typed programming in Agda - 2009.pdf:pdf},
929keywords = {Dependent Types},
1177keywords = {Dependent Types},
930mendeley-tags = {Dependent Types},
1178mendeley-tags = {Dependent Types},
931−title = {{A dependently typed framework for static analysis of program execution costs}},
1179+pages = {230--266},
932−url = {http://www.springerlink.com/index/P446P2HH70107759.pdf},
1180+publisher = {Springer},
933−year = {2005}
1181+title = {{Dependently typed programming in Agda}},
1182+url = {http://www.springerlink.com/index/8X0H38858233VN26.pdf},
1183+year = {2009}
934}
1184}
935−@article{Vytiniotis2011,
1185+@misc{Interface2012a,
936−author = {Vytiniotis, Dimitrios and {Peyton Jones}, Simon and Schrijvers, Tom and Sulzmann, Martin},
1186+author = {Kreibich, Jay A.},
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},
1187+doi = {10.1093/epirev/mxr031},
938−journal = {{Journal of Functional Programming}},
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},
939number = {4--5},
1216number = {4--5},
940pages = {333----412},
1217pages = {333----412},
941−title = {{\textsc{OutsideIn}(X) Modular type inference with local assumptions}},
1218+title = {{OutsideIn (X) Modular type inference with local assumptions}},
942−url = {http://journals.cambridge.org/abstract_S0956796811000098},
1219+url = {http://journals.cambridge.org/production/action/cjoGetFulltext?fulltextid=8274818},
943volume = {21},
1220volume = {21},
944year = {2011}
1221year = {2011}
945}
1222}
946−@article{mccann2000packet,
1223+@inproceedings{fisher2005pads,
947−author = {McCann, P.J. and Chandra, S.},
1224+author = {Fisher, K. and Gruber, R.},
948−journal = {ACM SIGCOMM Computer Communication Review},
1225+booktitle = {ACM SIGPLAN Notices},
949−number = {4},
1226+number = {6},
950−pages = {321--333},
1227+pages = {295--304},
951publisher = {ACM},
1228publisher = {ACM},
952−title = {{Packet types: abstract specification of network protocol messages}},
1229+title = {{PADS: a domain-specific language for processing ad hoc data}},
953−url = {http://dl.acm.org/citation.cfm?id=347563},
1230+url = {http://dl.acm.org/citation.cfm?id=1065046},
954−volume = {30},
1231+volume = {40},
955−year = {2000}
1232+year = {2005}
956}
1233}
957−@article{Miller1992,
1234+@inproceedings{Levitation2010,
958−author = {Miller, Dale},
1235+author = {Chapman, James and Dagand, Pierre-Evariste and McBride, Conor and Morris, Peter},
959−file = {:Users/edwin/Documents/Mendeley Desktop/Miller/Journal of Symbolic Computation/Miller - 1992 - Unification under a mixed prefix.pdf:pdf},
1236+booktitle = {{15th ACM SIGPLAN International Conference on Functional programming (ICFP '10)}},
960−journal = {Journal of Symbolic Computation},
1237+doi = {10.1145/1932681.1863547},
961−title = {{Unification under a mixed prefix}},
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},
962−url = {http://www.sciencedirect.com/science/article/pii/074771719290011R},
1239+isbn = {978-1-60558-794-3},
963−year = {1992}
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}
964}
1249}
965−@inproceedings{norell2009dependently,
1250+@book{While2012,
966−author = {Norell, Ulf},
1251+author = {Hunt, Andrew and Thomas, David},
967−booktitle = {Advanced Functional Programming},
1252+booktitle = {Carcinogenesis},
968−file = {:Users/edwin/Documents/Mendeley Desktop/Norell/Advanced Functional Programming/Norell - 2009 - Dependently typed programming in Agda.pdf:pdf},
1253+doi = {10.1093/carcin/bgs054},
969−keywords = {Dependent Types},
1254+file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/The Pragmatic Programmer Chapter 6/Hunt, Thomas - The Pragmatic Programmer Chapter 6 - Unknown.pdf:pdf},
970−mendeley-tags = {Dependent Types},
1255+isbn = {020161622X},
971−pages = {230--266},
1256+issn = {1460-2180},
972−publisher = {Springer},
1257+number = {3},
973−title = {{Dependently typed programming in Agda}},
1258+pmid = {22383472},
974−url = {http://www.springerlink.com/index/8X0H38858233VN26.pdf},
1259+title = {{The Pragmatic Programmer Chapter 6}},
975−year = {2009}
1260+url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
1261+volume = {33}
976}
1262}
977@article{Hughes1989,
1263@article{Hughes1989,
978abstract = {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.},
1264abstract = {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},
980chapter = {2},
1266chapter = {2},
981doi = {10.1093/comjnl/32.2.98},
1267doi = {10.1093/comjnl/32.2.98},
982editor = {Turner, David A},
1268editor = {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},
984institution = {Programming Methodology Group, University of {G\"{o}teborg} and Chalmers Institute of Technology, Sweden},
1270institution = {Programming Methodology Group, University of {G\"{o}teborg} and Chalmers Institute of Technology, Sweden},
985isbn = {0201172364},
1271isbn = {0201172364},
986issn = {00104620},
1272issn = {00104620},
@@ -993,57 +1279,401 @@ url = {http://comjnl.oupjournals.org/cgi/doi/10.1093/comjnl/32.2.98},
993volume = {32},
1279volume = {32},
994year = {1989}
1280year = {1989}
995}
1281}
996−@article{Steiner1988,
1282+@inproceedings{Asperti2011,
997−author = {Steiner, JG},
1283+author = {Asperti, Andrea and Ricciotti, Wilmer and Coen, Claudio Sacerdoti and Tassi, Enrico},
998−file = {:Users/edwin/Documents/Mendeley Desktop/Steiner/Proc. Winter USENIX Conference/Steiner - 1988 - Kerberos An authentication service for open network systems.pdf:pdf},
1284+booktitle = {Automated Deduction --- CADE-23},
999−journal = {Proc. Winter USENIX Conference},
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},
1000−title = {{Kerberos: An authentication service for open network systems}},
1286+pages = {64----69},
1001−url = {http://www.cse.nd.edu/$\sim$dthain/courses/cse598z/fall2004/papers/kerberos.pdf},
1287+title = {{The Matita Interactive Theorem Prover}},
1002−year = {1988}
1288+year = {2011}
1003}
1289}
1004−@phdthesis{McBride1999,
1290+@article{Brady2006a,
1005−author = {McBride, Conor},
1291+author = {Brady, E and Hammond, K},
1006−file = {:Users/edwin/Documents/Mendeley Desktop/McBride/Unknown/McBride - 1999 - Dependently typed functional programs and their proofs.pdf:pdf},
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},
1007keywords = {Dependent Types},
1294keywords = {Dependent Types},
1008mendeley-tags = {Dependent Types},
1295mendeley-tags = {Dependent Types},
1009−school = {University of Edinburgh},
1296+title = {{A verified staged interpreter is a verified compiler}},
1010−title = {{Dependently typed functional programs and their proofs}},
1297+url = {http://portal.acm.org/citation.cfm?id=1173706.1173724},
1011−url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.26.4785&rep=rep1&type=pdf},
1298+year = {2006}
1012−year = {1999}
1013}
1299}
1014−@inproceedings{augustsson1999exercise,
1300+@article{Xi1998,
1015−author = {Augustsson, L. and Carlsson, M.},
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.},
1016−booktitle = {In Workshop on Dependent Types in Programming, Gothenburg},
1302+author = {Xi, Hongwei and Pfenning, Frank},
1017−keywords = {Depe},
1303+doi = {10.1145/277652.277732},
1018−mendeley-tags = {Depe},
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},
1019−publisher = {Citeseer},
1305+isbn = {0897919874},
1020−title = {{An exercise in dependent types: A well-typed interpreter}},
1306+issn = {03621340},
1021−url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.39.2895},
1307+journal = {ACM Sigplan Notices},
1022−year = {1999}
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}
1023}
1318}
1024−@inproceedings{taha2004gentle,
1319+@inproceedings{Abel2013,
1025−author = {Taha, W.},
1320+author = {Abel, Andreas and Pientka, Brigitte and Thibodeau, David and Setzer, Anton},
1026−booktitle = {Domain-Specific Program Generation},
1321+booktitle = {Principles of Programming Languages},
1027−pages = {30--50},
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},
1028−publisher = {Springer},
1323+isbn = {9781450318327},
1029−title = {{A gentle introduction to multi-stage programming}},
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},
1030−url = {http://www.springerlink.com/index/JEMT0D8VYN5JB2L8.pdf},
1325+title = {{Copatterns: Programming Infinite Structures by Observations}},
1031−year = {2004}
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}
1032}
1380}
1033@inproceedings{Sculthorpe2009,
1381@inproceedings{Sculthorpe2009,
1034author = {Sculthorpe, Neil and Nilsson, Henrik},
1382author = {Sculthorpe, Neil and Nilsson, Henrik},
1035booktitle = {International Conference on Functional Programming ({ICFP} '09)},
1383booktitle = {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},
1037title = {{Safe functional reactive programming through dependent types}},
1385title = {{Safe functional reactive programming through dependent types}},
1038url = {http://dl.acm.org/citation.cfm?id=1596558},
1386url = {http://dl.acm.org/citation.cfm?id=1596558},
1039year = {2009}
1387year = {2009}
1040}
1388}
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+}
1041@misc{TheMendeleySupportTeam2011a,
1671@misc{TheMendeleySupportTeam2011a,
1042abstract = {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.},
1672abstract = {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.},
1043address = {London},
1673address = {London},
1044author = {{The Mendeley Support Team}},
1674author = {{The Mendeley Support Team}},
1045booktitle = {Mendeley Desktop},
1675booktitle = {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},
1047keywords = {Mendeley,how-to,user manual},
1677keywords = {Mendeley,how-to,user manual},
1048pages = {1--16},
1678pages = {1--16},
1049publisher = {Mendeley Ltd.},
1679publisher = {Mendeley Ltd.},
@@ -1051,35 +1681,21 @@ title = {{Getting Started with Mendeley}},
1051url = {http://www.mendeley.com},
1681url = {http://www.mendeley.com},
1052year = {2011}
1682year = {2011}
1053}
1683}
1054−@article{danielsson2011parsing,
1684+@misc{Brady2012b,
1055−author = {Danielsson, N. and Norell, U.},
1685+author = {Brooks, Fred},
1056−journal = {Implementation and Application of Functional Languages},
1686+doi = {10.1093/epirev/mxr031},
1057−pages = {80--99},
1687+file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/The Design of Design Chapter 2/Brooks - The Design of Design Chapter 2 - Unknown.pdf:pdf},
1058−publisher = {Springer},
1688+isbn = {9780321702081},
1059−title = {{Parsing mixfix operators}},
1689+issn = {1478-6729},
1060−url = {http://www.springerlink.com/index/386243257W504252.pdf},
1690+pmid = {22215642},
1061−year = {2011}
1691+title = {{The Design of Design Chapter 2}}
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}}
1076}
1692}
1077@misc{Bove2008,
1693@misc{Bove2008,
1078abstract = {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.},
1694abstract = {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.},
1079author = {Bove, Ana and Dybjer, Peter},
1695author = {Bove, Ana and Dybjer, Peter},
1080booktitle = {Notes},
1696booktitle = {Notes},
1081doi = {10.1007/978-3-642-03153-3_2},
1697doi = {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},
1083number = {February},
1699number = {February},
1084pages = {57--99},
1700pages = {57--99},
1085publisher = {Springer},
1701publisher = {Springer},
@@ -1088,111 +1704,375 @@ url = {http://www.springerlink.com/index/1039q8qk71257677.pdf},
1088volume = {5520},
1704volume = {5520},
1089year = {2008}
1705year = {2008}
1090}
1706}
1091−@article{Okasaki1993,
1707+@article{In2012,
1092−author = {Okasaki, Chris},
1708+author = {Gulhati, Ashish},
1093−file = {:Users/edwin/Documents/Mendeley Desktop/Okasaki/Journal of functional programming/Okasaki - 1993 - Red-Black Trees in A Functional Setting.pdf:pdf},
1709+doi = {10.1093/geront/gns026},
1094−journal = {Journal of functional programming},
1710+file = {:Users/edwin/Documents/Mendeley Desktop/Gulhati/Beautiful Code Chapter 11/Gulhati - Beautiful Code Chapter 11 - 2012.pdf:pdf},
1095−title = {{Red-Black Trees in A Functional Setting}},
1711+isbn = {9780596510046},
1096−year = {1993}
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}
1097}
1721}
1098−@inproceedings{pj2006gadts,
1722+@article{McBride2002,
1099−author = {{Peyton Jones}, S. and Vytiniotis, D. and Weirich, S. and Washburn, G.},
1723+author = {McBride, C},
1100−booktitle = {{International Conference on Functional Programming} ({ICFP} '06)},
1724+file = {:Users/edwin/Documents/Mendeley Desktop/McBride/Elimination with a Motive/McBride - Elimination with a Motive - 2000.pdf:pdf},
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},
1725+journal = {Types for proofs and programs ({TYPES 2000})},
1102−number = {9},
1726+title = {{Elimination with a Motive}},
1103−pages = {50--61},
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},
1104publisher = {ACM},
1735publisher = {ACM},
1105−title = {{Simple unification-based type inference for GADTs}},
1736+title = {{Type-safe diff for families of datatypes}},
1106−url = {http://dl.acm.org/citation.cfm?id=1159811},
1737+url = {http://dl.acm.org/citation.cfm?id=1596624},
1107−volume = {41},
1738+year = {2009}
1108−year = {2006}
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}
1109}
1754}
1110@misc{altenkirch2005dependent,
1755@misc{altenkirch2005dependent,
1111author = {Altenkirch, T. and McBride, C. and McKinna, J.},
1756author = {Altenkirch, T. and McBride, C. and McKinna, J.},
1112booktitle = {Manuscript, available online},
1757booktitle = {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},
1114title = {{Why dependent types matter}},
1759title = {{Why dependent types matter}},
1115url = {http://www.cs.nott.ac.uk/$\sim$txa/talks/splst11.pdf},
1760url = {http://www.cs.nott.ac.uk/$\sim$txa/talks/splst11.pdf},
1116year = {2005}
1761year = {2005}
1117}
1762}
1118−@misc{The2012c,
1763+@misc{Nodes2012a,
1119−author = {Robbins, A and Hannah, E and Lamb, L},
1764+author = {Brooks, Fred},
1120doi = {10.1093/epirev/mxr031},
1765doi = {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},
1766+file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/The Design of Design Chapter 3/Brooks - The Design of Design Chapter 3 - Unknown.pdf:pdf},
1122−isbn = {9780596529833},
1767+isbn = {9780321702081},
1123issn = {1478-6729},
1768issn = {1478-6729},
1124pmid = {22215642},
1769pmid = {22215642},
1125−title = {{Learning the vi and Vim Editors}}
1770+title = {{The Design of Design Chapter 3}}
1126}
1771}
1127−@misc{Resolution2012a,
1772+@article{danielsson2011parsing,
1128−author = {Fall, Kevin R and Stevens, W. Richard},
1773+author = {Danielsson, N. and Norell, U.},
1129−doi = {10.1093/epirev/mxr031},
1774+journal = {Implementation and Application of Functional Languages},
1130−file = {:Users/edwin/Documents/Mendeley Desktop/Fall, Stevens/Unknown/Fall, Stevens - Unknown - TCPIP Illustrated Volume 1 Chapter 11.pdf:pdf},
1775+pages = {80--99},
1131−issn = {1478-6729},
1776+publisher = {Springer},
1132−pmid = {22215642},
1777+title = {{Parsing mixfix operators}},
1133−title = {{TCP/IP Illustrated Volume 1 Chapter 11}}
1778+url = {http://www.springerlink.com/index/386243257W504252.pdf},
1779+year = {2011}
1134}
1780}
1135−@article{Brady2006a,
1781+@book{Bird2010,
1136−author = {Brady, E and Hammond, K},
1782+author = {Bird, Richard},
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},
1783+file = {:Users/edwin/Documents/Mendeley Desktop/Bird/Pearls of Functional Algorithm Design/Bird - Pearls of Functional Algorithm Design - 2010.pdf:pdf},
1138−journal = {\ldots of the 5th international conference on \ldots},
1784+isbn = {9780521513388},
1139−keywords = {Dependent Types},
1785+title = {{Pearls of Functional Algorithm Design}},
1140−mendeley-tags = {Dependent Types},
1786+year = {2010}
1141−title = {{A verified staged interpreter is a verified compiler}},
1142−url = {http://portal.acm.org/citation.cfm?id=1173706.1173724},
1143−year = {2006}
1144}
1787}
1145−@inproceedings{swierstra2007beauty,
1788+@article{Jones1999,
1146−author = {Swierstra, W. and Altenkirch, T.},
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.},
1147−booktitle = {Proceedings of the ACM SIGPLAN workshop on Haskell workshop},
1790+author = {Jones, Mark P},
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},
1791+file = {:Users/edwin/Documents/Mendeley Desktop/Jones/Typing Haskell in Haskell/Jones - Typing Haskell in Haskell - 1999.pdf:pdf},
1149−pages = {25--36},
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},
1150publisher = {ACM},
1827publisher = {ACM},
1151−title = {{Beauty in the beast}},
1828+title = {{Resource typing in Guru}},
1152−url = {http://dl.acm.org/citation.cfm?id=1291206},
1829+url = {http://dl.acm.org/citation.cfm?id=1707796},
1153−year = {2007}
1830+year = {2010}
1154}
1831}
1155−@article{McBride2004a,
1832+@article{fisher2006next,
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.},
1833+author = {Fisher, K. and Mandelbaum, Y. and Walker, D.},
1157−author = {McBride, Conor and McKinna, James},
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},
1158−doi = {10.1017/S0956796803004829},
1835+journal = {Journal of the ACM},
1159−file = {:Users/edwin/Documents/Mendeley Desktop/McBride, McKinna/Journal of Functional Programming/McBride, McKinna - 2004 - The view from the left.pdf:pdf},
1836+number = {2},
1160−issn = {09567968},
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},
1161journal = {Journal of Functional Programming},
1903journal = {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},
1162keywords = {Dependent Types},
1948keywords = {Dependent Types},
1163mendeley-tags = {Dependent Types},
1949mendeley-tags = {Dependent Types},
1164−number = {1},
1950+school = {University of Durham},
1165−pages = {69--111},
1951+title = {{Practical Implementation of a Dependently Typed Functional Programming Language}},
1166−publisher = {Cambridge University Press},
1952+year = {2005}
1167−title = {{The view from the left}},
1953+}
1168−url = {http://www.journals.cambridge.org/abstract_S0956796803004829},
1954+@article{Lee2001,
1169−volume = {14},
1955+author = {Lee, Chin Soon and Jones, Neil D. and Ben-Amram, Amir M.},
1170−year = {2004}
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}}
1171}
1980}
1172−@misc{Nodes2012a,
1981+@inproceedings{Peterson1993,
1173−author = {Brooks, Fred},
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},
1174doi = {10.1093/epirev/mxr031},
2000doi = {10.1093/epirev/mxr031},
1175−file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/Unknown/Brooks - Unknown - The Design of Design Chapter 3.pdf:pdf},
2001+file = {:Users/edwin/Documents/Mendeley Desktop/Anderson/Security Engineering Chapter 18/Anderson - Security Engineering Chapter 18 - Unknown.pdf:pdf},
1176−isbn = {9780321702081},
2002+isbn = {9780470068526},
1177issn = {1478-6729},
2003issn = {1478-6729},
2004+number = {1},
2005+pages = {NP},
1178pmid = {22215642},
2006pmid = {22215642},
1179−title = {{The Design of Design Chapter 3}}
2007+title = {{Security Engineering Chapter 18}},
2008+volume = {34}
1180}
2009}
1181−@inproceedings{Hancock2000,
2010+@inproceedings{bhargavan2010modular,
1182−author = {Hancock, Peter and Setzer, Anton},
2011+author = {Bhargavan, K. and Fournet, C. and Gordon, A.D.},
1183−booktitle = {{Proceedings of the 14th Annual Conference of the EACSL on Computer Science Logic}},
2012+booktitle = {ACM Sigplan Notices},
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},
2013+number = {1},
1185−isbn = {3-540-67895-6},
2014+pages = {445--456},
1186−month = aug,
2015+publisher = {ACM},
1187−pages = {317--331},
2016+title = {{Modular verification of security protocol code by typing}},
1188−title = {{Interactive Programs in Dependent Type Theory}},
2017+url = {http://dl.acm.org/citation.cfm?id=1707801.1706350},
1189−url = {http://dl.acm.org/citation.cfm?id=647850.737221},
2018+volume = {45},
1190−year = {2000}
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}
1191}
2071}
1192@inproceedings{augustsson2008paradise,
2072@inproceedings{augustsson2008paradise,
1193author = {Augustsson, L. and Mansell, H. and Sittampalam, G.},
2073author = {Augustsson, L. and Mansell, H. and Sittampalam, G.},
1194booktitle = {International Conference on Functional Programming},
2074booktitle = {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},
1196number = {9},
2076number = {9},
1197pages = {225--228},
2077pages = {225--228},
1198publisher = {ACM},
2078publisher = {ACM},
@@ -1201,61 +2081,185 @@ url = {http://dl.acm.org/citation.cfm?id=1411203.1411236},
1201volume = {43},
2081volume = {43},
1202year = {2008}
2082year = {2008}
1203}
2083}
1204−@misc{Abel1998,
2084+@article{marlow2006making,
1205−author = {Abel, Andreas},
2085+author = {Marlow, S. and {Peyton Jones}, S.},
1206−booktitle = {Language},
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},
1207−file = {:Users/edwin/Documents/Mendeley Desktop/Abel/Language/Abel - 1998 - foetus - Termination Checker for Simple Functional Programs.pdf:pdf},
2087+journal = {Journal of Functional Programming},
1208−title = {{foetus - Termination Checker for Simple Functional Programs}},
2088+number = {4-5},
1209−year = {1998}
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}
1210}
2095}
1211−@article{Jones1999,
2096+@misc{TheMendeleySupportTeam2011b,
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.},
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.},
1213−author = {Jones, Mark P},
2098+address = {London},
1214−journal = {October},
2099+author = {{The Mendeley Support Team}},
1215−publisher = {Citeseer},
2100+booktitle = {Mendeley Desktop},
1216−title = {{Typing Haskell in Haskell}},
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},
1217−url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.134.7274&amp;rep=rep1&amp;type=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},
1218year = {1999}
2206year = {1999}
1219}
2207}
1220−@inproceedings{morris2006exploring,
2208+@article{Altenkirch2010a,
1221−author = {Morris, P. and Altenkirch, T. and McBride, C.},
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.},
1222−booktitle = {Types for Proofs and Programs},
2210+author = {Altenkirch, Thorsten and Mcbride, Conor and Morris, Peter},
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},
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},
1224−pages = {252--267},
2212+journal = {Citeseer},
1225−publisher = {Springer},
2213+publisher = {Citeseer},
1226−title = {{Exploring the regular tree types}},
2214+title = {{Generic Programming with Dependent Types}},
1227−url = {http://www.springerlink.com/index/f9p1317716614834.pdf},
2215+url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.129.2926&amp;rep=rep1&amp;type=pdf},
1228−year = {2006}
2216+year = {2010}
1229}
2217}
1230−@inproceedings{Sheard2005,
2218+@book{Edition2012a,
1231−address = {New York, New York, USA},
2219+author = {Pfleeger, Charles P and Pfleeger, S. L.},
1232−author = {Sheard, Tim},
2220+booktitle = {Nicotine & tobacco research : official journal of the Society for Research on Nicotine and Tobacco},
1233−booktitle = {Proceedings of the 2005 ACM SIGPLAN workshop on Haskell - Haskell '05},
2221+doi = {10.1093/ntr/nts035},
1234−doi = {10.1145/1088348.1088356},
2222+file = {:Users/edwin/Documents/Mendeley Desktop/Pfleeger, Pfleeger/Security in Computer Chapter 12/Pfleeger, Pfleeger - Security in Computer Chapter 12 - 2012.pdf:pdf},
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},
2223+isbn = {0132390779},
1236−isbn = {159593071X},
2224+issn = {1469-994X},
1237−keywords = {GADT,curry-howard isomorphism,extensional kind system,haskell,logic},
2225+month = oct,
1238−month = sep,
2226+number = {10},
1239−pages = {74--85},
2227+pages = {NP},
1240−publisher = {ACM Press},
2228+pmid = {23012339},
1241−title = {{Putting curry-howard to work}},
2229+title = {{Security in Computer Chapter 12}},
1242−url = {http://dl.acm.org/citation.cfm?id=1088348.1088356},
2230+url = {http://www.ncbi.nlm.nih.gov/pubmed/23012339},
1243−year = {2005}
2231+volume = {14},
2232+year = {2012}
1244}
2233}
1245−@misc{Interface2012a,
2234+@book{Pierce2004,
1246−author = {Kreibich, Jay A.},
2235+author = {Pierce, Benjamin},
1247−doi = {10.1093/epirev/mxr031},
2236+editor = {Pierce, Benjamin},
1248−file = {:Users/edwin/Documents/Mendeley Desktop/Kreibich/Unknown/Kreibich - Unknown - Using SQLite Chapter 7.pdf:pdf},
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},
1249−isbn = {9781449394592},
2238+publisher = {MIT Press},
1250−issn = {1478-6729},
2239+title = {{Advanced topics in types and programming languages}},
1251−pmid = {22215642},
2240+year = {2004}
1252−title = {{Using SQLite Chapter 7}}
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}}
1253}
2257}
1254@book{The2012,
2258@book{The2012,
1255author = {Hunt, Andrew and Thomas, David},
2259author = {Hunt, Andrew and Thomas, David},
1256booktitle = {Carcinogenesis},
2260booktitle = {Carcinogenesis},
1257doi = {10.1093/carcin/bgs054},
2261doi = {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},
1259isbn = {020161622X},
2263isbn = {020161622X},
1260issn = {1460-2180},
2264issn = {1460-2180},
1261number = {3},
2265number = {3},
@@ -1264,68 +2268,18 @@ title = {{The Pragmatic Programmer Chapter 3}},
1264url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
2268url = {http://www.ncbi.nlm.nih.gov/pubmed/22383472},
1265volume = {33}
2269volume = {33}
1266}
2270}
1267−@misc{Brady2012b,
2271+@inproceedings{pollack1990implicit,
1268−author = {Brooks, Fred},
2272+author = {Pollack, R.},
1269−doi = {10.1093/epirev/mxr031},
2273+booktitle = {{Informal Proceedings of First Workshop on Logical Frameworks, Antibes}},
1270−file = {:Users/edwin/Documents/Mendeley Desktop/Brooks/Unknown/Brooks - Unknown - The Design of Design Chapter 2.pdf:pdf},
2274+file = {:Users/edwin/Documents/Mendeley Desktop/Pollack/Implicit syntax/Pollack - Implicit syntax - 1990.pdf:pdf},
1271−isbn = {9780321702081},
2275+publisher = {Citeseer},
1272−issn = {1478-6729},
2276+title = {{Implicit syntax}},
1273−pmid = {22215642},
2277+url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.30.7361&amp;rep=rep1&amp;type=pdf},
1274−title = {{The Design of Design Chapter 2}}
2278+year = {1990}
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}
1320}
2279}
1321−@inproceedings{fisher2005pads,
2280+@article{Bradya,
1322−author = {Fisher, K. and Gruber, R.},
2281+author = {Hunt, Andrew and Thomas, David},
1323−booktitle = {ACM SIGPLAN Notices},
2282+file = {:Users/edwin/Documents/Mendeley Desktop/Hunt, Thomas/The Pragmatic Programmer Chapter 7/Hunt, Thomas - The Pragmatic Programmer Chapter 7 - Unknown.pdf:pdf},
1324−number = {6},
2283+isbn = {020161622X},
1325−pages = {295--304},
2284+title = {{The Pragmatic Programmer Chapter 7}}
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}
1331}
2285}
papers/impl-paper/macros.ltx+4−4
@@ -261,7 +261,7 @@
261\newcommand{\MHRet}[2]{\multicolumn{#1}{l}{\hq #2}}
261\newcommand{\MHRet}[2]{\multicolumn{#1}{l}{\hq #2}}
262\newcommand{\IRet}[1]{\multicolumn{2}{l}{\iq #1}}
262\newcommand{\IRet}[1]{\multicolumn{2}{l}{\iq #1}}
263\newcommand{\IMRet}[2]{\multicolumn{#1}{l}{\iq #2}}
263\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}}
265\newcommand{\MMoRet}[2]{\multicolumn{#1}{l}{\mq #2}}
265\newcommand{\MMoRet}[2]{\multicolumn{#1}{l}{\mq #2}}
266\newcommand{\Data}{\RW{data}}
266\newcommand{\Data}{\RW{data}}
267\newcommand{\Codata}{\RW{codata}}
267\newcommand{\Codata}{\RW{codata}}
@@ -391,7 +391,7 @@ Program & Version & Instructions & Thunks & Memory Accesses & Cells \\
391
391
392%%%%%%%%%%%% TYPE
392%%%%%%%%%%%% TYPE
393
393
394−\newcommand{\Type}{\mbox{\texttt{Set}}} %\star}
394+\newcommand{\Type}{\mbox{\texttt{Type}}} %\star}
395
395
396
396
397%%%%%%%%%%%%% ARROWS
397%%%%%%%%%%%%% ARROWS
@@ -430,7 +430,7 @@ Program & Version & Instructions & Thunks & Memory Accesses & Cells \\
430\newcommand{\pq}{\pad{\:}{=}}
430\newcommand{\pq}{\pad{\:}{=}}
431\newcommand{\dq}{\pad{\:}{:=}}
431\newcommand{\dq}{\pad{\:}{:=}}
432\newcommand{\iq}{\pad{\:}{\leadsto}}
432\newcommand{\iq}{\pad{\:}{\leadsto}}
433−\newcommand{\mq}{\Longrightarrow}
433+\newcommand{\mq}{=} %\Longrightarrow}
434\newcommand{\retq}{\Rightarrow}
434\newcommand{\retq}{\Rightarrow}
435\newcommand{\hq}{\pad{\:}{=}}
435\newcommand{\hq}{\pad{\:}{=}}
436\newcommand{\defq}{\mapsto}
436\newcommand{\defq}{\mapsto}
@@ -559,7 +559,7 @@ Program & Version & Instructions & Thunks & Memory Accesses & Cells \\
559\newcommand{\VectRebuild}{\FN{vectRebuild}}
559\newcommand{\VectRebuild}{\FN{vectRebuild}}
560
560
561\newcommand{\Prop}{\TC{Prop}}
561\newcommand{\Prop}{\TC{Prop}}
562−\newcommand{\Set}{\TC{Set}}
562+\newcommand{\Set}{\TC{Type}}
563\newcommand{\CoqType}{\TC{Type}}
563\newcommand{\CoqType}{\TC{Type}}
564
564
565\newcommand{\List}{\TC{List}}
565\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.
28
28
29The function space $\all{\vx}{\vS}\SC\vT$ may also be written as $(\vx\Hab\vS)\to\vT$,
29The function space $\all{\vx}{\vS}\SC\vT$ may also be written as $(\vx\Hab\vS)\to\vT$,
30or $\vS\to\vT$ if $\vx$ is not free in $\vT$, to make the notation more consistent with
30or $\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
32inferred by the machine~\cite{pollack1990implicit}.
32inferred by the machine~\cite{pollack1990implicit}.
33
33
34\FFIG{
34\FFIG{
@@ -37,9 +37,9 @@ inferred by the machine~\cite{pollack1990implicit}.
37\hg\vb ::= & \lam{\vx}{\vt} & (\mbox{abstraction}) \\
37\hg\vb ::= & \lam{\vx}{\vt} & (\mbox{abstraction}) \\
38
38
39 \mid & \vx & (\mbox{variable}) &
39 \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}) \\
41
41
42− \mid & \vb\SC\:\vt & (\mbox{binding}) &
42+ \mid & \vb\SC\;\vt & (\mbox{binding}) &
43 \mid & \all{\vx}{\vt} & (\mbox{function space}) \\
43 \mid & \all{\vx}{\vt} & (\mbox{function space}) \\
44
44
45 \mid & \vt\;\vt & (\mbox{application}) &
45 \mid & \vt\;\vt & (\mbox{application}) &
@@ -73,8 +73,14 @@ $\LET$ binding:
73\DM{
73\DM{
74\Axiom{\proves\RW{valid}}
74\Axiom{\proves\RW{valid}}
75\hg
75\hg
76−\Rule{\Gamma\proves\RW{valid}}
76+\Rule{\Gamma\proves\vS\Hab\Type_i}
77−{\Gamma;\vb\proves\RW{valid}}
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}}
78}
84}
79
85
80\subsubsection{Evaluation}
86\subsubsection{Evaluation}
@@ -97,8 +103,8 @@ The following contextual closure rule reduces a $\LET$ binding by creating
97a $\delta$-reducible expression:
103a $\delta$-reducible expression:
98
104
99\DM{
105\DM{
100−\Rule{\Gamma;\LET\:\vx\defq\vs\proves\vt\leadsto\vu}
106+\Rule{\Gamma;\LET\;\vx\defq\vs\Hab\vS\proves\vt\leadsto\vu}
101−{\Gamma\proves\LET\:\vx\defq\vs\Hab\vS\SC\vt\leadsto\vu}
107+{\Gamma\proves\LET\;\vx\defq\vs\Hab\vS\SC\vt\leadsto\vu}
102}
108}
103
109
104\demph{Reduction} ($\reduces$) is the structural closure of contraction, and evaluation
110\demph{Reduction} ($\reduces$) is the structural closure of contraction, and evaluation
@@ -116,11 +122,11 @@ reduction rules.
116\begin{array}{lc}
122\begin{array}{lc}
117\beta\mathrm{-contraction} &
123\beta\mathrm{-contraction} &
118\Axiom{
124\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
120} \\
126} \\
121\delta\mathrm{-contraction} &
127\delta\mathrm{-contraction} &
122\Axiom{
128\Axiom{
123−\Gamma;\LET\:\vx\defq\vs\Hab\vS;\Gamma'
129+\Gamma;\LET\;\vx\defq\vs\Hab\vS;\Gamma'
124\proves
130\proves
125\vx\leadsto\vs
131\vx\leadsto\vs
126}
132}
@@ -147,71 +153,71 @@ are no cycles. Otherwise, the typing rules are standard and type inference can
147be implemented in the usual way~\cite{loh2010tutorial}.
153be implemented in the usual way~\cite{loh2010tutorial}.
148
154
149\FFIG{\begin{array}{c}
155\FFIG{\begin{array}{c}
150−\mathsf{Type}\:
156+\mathsf{Type}\;
151\Rule{\Gamma\proves\RW{valid}}
157\Rule{\Gamma\proves\RW{valid}}
152{\Gamma\vdash\Type_n\Hab\Type_{n+1}}
158{\Gamma\vdash\Type_n\Hab\Type_{n+1}}
153\\
159\\
154−\mathsf{Const}_1\:
160+\mathsf{Const}_1\;
155\Rule{\Gamma\proves\RW{valid}}
161\Rule{\Gamma\proves\RW{valid}}
156{\Gamma\vdash\vi\Hab\TC{Int}}
162{\Gamma\vdash\vi\Hab\TC{Int}}
157\hg
163\hg
158−\mathsf{Const}_2\:
164+\mathsf{Const}_2\;
159\Rule{\Gamma\proves\RW{valid}}
165\Rule{\Gamma\proves\RW{valid}}
160{\Gamma\vdash\VV{str}\Hab\TC{String}}
166{\Gamma\vdash\VV{str}\Hab\TC{String}}
161\\
167\\
162−\mathsf{Const}_3\:
168+\mathsf{Const}_3\;
163\Rule{\Gamma\proves\RW{valid}}
169\Rule{\Gamma\proves\RW{valid}}
164{\Gamma\vdash\TC{Int}\Hab\Type_0}
170{\Gamma\vdash\TC{Int}\Hab\Type_0}
165\hg
171\hg
166−\mathsf{Const}_4\:
172+\mathsf{Const}_4\;
167\Rule{\Gamma\proves\RW{valid}}
173\Rule{\Gamma\proves\RW{valid}}
168{\Gamma\vdash\TC{String}\Hab\Type_0}
174{\Gamma\vdash\TC{String}\Hab\Type_0}
169\\
175\\
170−%\mathsf{Pat}_1\:
176+%\mathsf{Pat}_1\;
171%\Rule{(\pat{\vx}{\vS})\in\Gamma}
177%\Rule{(\pat{\vx}{\vS})\in\Gamma}
172%{\Gamma\vdash\vx\Hab\vS}
178%{\Gamma\vdash\vx\Hab\vS}
173%\hg
179%\hg
174−%\mathsf{Pat}_2\:
180+%\mathsf{Pat}_2\;
175%\Rule{(\pty{\vx}{\vS})\in\Gamma}
181%\Rule{(\pty{\vx}{\vS})\in\Gamma}
176%{\Gamma\vdash\vx\Hab\vS}
182%{\Gamma\vdash\vx\Hab\vS}
177\\
183\\
178−\mathsf{Var}_1\:
184+\mathsf{Var}_1\;
179\Rule{(\lam{\vx}{\vS})\in\Gamma}
185\Rule{(\lam{\vx}{\vS})\in\Gamma}
180{\Gamma\vdash\vx\Hab\vS}
186{\Gamma\vdash\vx\Hab\vS}
181\hg
187\hg
182−\mathsf{Var}_2\:
188+\mathsf{Var}_2\;
183\Rule{(\all{\vx}{\vS})\in\Gamma}
189\Rule{(\all{\vx}{\vS})\in\Gamma}
184{\Gamma\vdash\vx\Hab\vS}
190{\Gamma\vdash\vx\Hab\vS}
185\hg
191\hg
186−\mathsf{Val}\:
192+\mathsf{Val}\;
187−\Rule{(\LET\:\vx\Hab\vS\defq\vs)\in\Gamma}
193+\Rule{(\LET\;\vx\defq\vs\Hab\vS)\in\Gamma}
188{\Gamma\vdash\vx\Hab\vS}
194{\Gamma\vdash\vx\Hab\vS}
189\\
195\\
190−\mathsf{App}\:
196+\mathsf{App}\;
191\Rule{\Gamma\vdash\vf\Hab\fbind{\vx}{\vS}{\vT}\hg\Gamma\vdash\vs\Hab\vS}
197\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}
193\\
199\\
194−\mathsf{Lam}\:
200+\mathsf{Lam}\;
195\Rule{\Gamma;\lam{\vx}{\vS}\vdash\ve\Hab\vT\hg\Gamma\proves\fbind{\vx}{\vS}{\vT}\Hab\Type_n}
201\Rule{\Gamma;\lam{\vx}{\vS}\vdash\ve\Hab\vT\hg\Gamma\proves\fbind{\vx}{\vS}{\vT}\Hab\Type_n}
196{\Gamma\vdash\lam{\vx}{\vS}.\ve\Hab\fbind{\vx}{\vS}{\vT}}
202{\Gamma\vdash\lam{\vx}{\vS}.\ve\Hab\fbind{\vx}{\vS}{\vT}}
197\\
203\\
198−\mathsf{Forall}\:
204+\mathsf{Forall}\;
199\Rule{\Gamma;\all{\vx}{\vS}\vdash\vT\Hab\Type_m\hg\Gamma\vdash\vS\Hab\Type_n}
205\Rule{\Gamma;\all{\vx}{\vS}\vdash\vT\Hab\Type_m\hg\Gamma\vdash\vS\Hab\Type_n}
200{\Gamma\vdash\fbind{\vx}{\vS}{\vT}\Hab\Type_p}
206{\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)
202\\
208\\
203−\mathsf{Let}\:
209+\mathsf{Let}\;
204\Rule{\begin{array}{c}\Gamma\proves\ve_1\Hab\vS\hg
210\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\\
206 \Gamma\proves\vS\Hab\Type_n\hg
212 \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}
208 }
214 }
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
210 \vT[\ve_1/\vx]}
216 \vT[\ve_1/\vx]}
211−%\Let\:\vx\Hab\vS\defq\ve_1\:\IN\:\vT}
217+%\Let\;\vx\Hab\vS\defq\ve_1\;\IN\;\vT}
212\\
218\\
213
219
214−\mathsf{Conv}\:
220+\mathsf{Conv}\;
215\Rule{\Gamma\proves\vx\Hab\vA\hg\Gamma\proves\vA'\Hab\Type_n\hg
221\Rule{\Gamma\proves\vx\Hab\vA\hg\Gamma\proves\vA'\Hab\Type_n\hg
216 \Gamma\proves\vA\cumul\vA'}
222 \Gamma\proves\vA\cumul\vA'}
217 {\Gamma\proves\vx\Hab\vA'}
223 {\Gamma\proves\vx\Hab\vA'}
@@ -237,6 +243,7 @@ be implemented in the usual way~\cite{loh2010tutorial}.
237{Cumulativity}
243{Cumulativity}
238{cumul}
244{cumul}
239
245
246+
240\subsection{Inductive Families}
247\subsection{Inductive Families}
241
248
242\label{sect:inductivefams}
249\label{sect:inductivefams}
@@ -251,21 +258,21 @@ sequence of zero or more $\vx$ (i.e., $\vx_1,\vx_2,\ldots,\vx_n$):
251
258
252\DM{
259\DM{
253\AR{
260\AR{
254−\Data\hg\TC{T}\:(\tx\Hab\ttt)\Hab\vt\hg\Where\hg
261+\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
262+\DC{c}_1\Hab\vt\;\mid\;\ldots\;\mid\;\DC{c}_n\Hab\vt
256}
263}
257}
264}
258
265
259−Constructors may take recursive arguments in the family
266+Constructors may take recursive arguments in the family $\TC{T}$, which may be
260−$\TC{T}$. Furthermore these arguments may themselves be indexed by another type ---
267+higher order. Higher order recursive arguments may be computed from any type
261−if such indices do not involve $\TC{T}$ then the constructor is
268+which does not involve $\TC{T}$ itself. This restriction is known as
262−\demph{strictly positive}, which ensures that recursive arguments of the
269+\demph{strict positivity} and ensures that recursive arguments of the
263constructor are structurally smaller than the value itself.
270constructor are structurally smaller than the value itself.
264
271
265For example, the \Idris{} data type \tTC{Nat} would be declared in \TT{} as follows:
272For example, the \Idris{} data type \tTC{Nat} would be declared in \TT{} as follows:
266
273
267\DM{
274\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}
269}
276}
270
277
271A data type may have zero or more parameters (which are invariant
278A 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
274
281
275\DM{
282\DM{
276\AR{
283\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
278\ARd{
286\ARd{
279−& \nil\Hab\List\:\va\\
287+& \nil\Hab\List\;\va\\
280−\mid & (\cons)\Hab\fbind{\vx}{\va}{\fbind{\vxs}{\List\:\va}{\List\:\va}}
288+\mid & (\cons)\Hab\fbind{\vx}{\va}{\fbind{\vxs}{\List\;\va}{\List\;\va}}
281}
289}
282}
290}
283}
291}
@@ -292,11 +300,11 @@ index $\vk$ is given \remph{explicitly}.
292
300
293\DM{
301\DM{
294\AR{
302\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 \\
296\hg\hg\ARd{
304\hg\hg\ARd{
297−& \nil\Hab\Vect\:\va\:\Z\\
305+& \nil\Hab\Vect\;\va\;\Z\\
298\mid & (\cons)\Hab\fbind{\vk}{\Nat}{
306\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)}}
300}
308}
301}
309}
302}
310}
@@ -306,7 +314,8 @@ index $\vk$ is given \remph{explicitly}.
306
314
307\label{sect:patdefs}
315\label{sect:patdefs}
308
316
309−\subsubsection{Syntax}
317+%\subsubsection{Syntax}
318+
310
319
311A pattern matching definition for a function named $\FN{f}$ takes the following form,
320A pattern matching definition for a function named $\FN{f}$ takes the following form,
312consisting of a type declaration followed by one or more pattern clauses:
321consisting 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:
314\DM{
323\DM{
315\AR{
324\AR{
316\FN{f}\Hab\vt\\
325\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\\
318\ldots\\
327\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\\
320}
329}
321}
330}
322
331
@@ -333,152 +342,210 @@ clause is defined by the following rule:
333
342
334\DM{
343\DM{
335\Rule{
344\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
337\Gamma;\lam{\tx}{\tU}\proves\ve\Hab\vT\hg
346\Gamma;\lam{\tx}{\tU}\proves\ve\Hab\vT\hg
338\Gamma\proves\vS\converts\vT}
347\Gamma\proves\vS\converts\vT}
339{
348{
340−\Gamma\proves\pat{\tx}{\tU}\SC\FN{f}\:\tts\:=\:\ve\:\RW{valid}
349+\Gamma\proves\pat{\tx}{\tU}\SC\FN{f}\;\tts\;=\;\ve\;\RW{valid}
341−}
350+}
342−}
351+}
343−
352+
344−A valid pattern matching definition effectively extends \TT{} with a new constant,
353+A valid pattern matching definition effectively extends \TT{} with a new
345−with the given type (extending the initial typing rules given in Section \ref{sect:typerules})
354+constant, with the given type (extending the initial typing rules given in
346−and reduction behaviour (extending the initial reduction rules given in Section
355+Section \ref{sect:typerules}) and reduction behaviour (extending the initial
347−\ref{sect:evaluation}).
356+reduction rules given in Section \ref{sect:evaluation}).
348−
357+Patterns are separated into the accessible patterns (variables and constructor
349−\subsubsection{Semantics}
358+forms which may be inspected) and inaccessible patterns, following
350−
359+Agda~\cite{norell2007thesis} then implemented by compilation into case
351−Matching on an expression proceeds by comparing the expression to
360+trees~\cite{Augustsson1985}.
352−each match clause in order, resulting in either:
361+
353−
362+% \subsubsection{Semantics}
354−\begin{itemize}
363+%
355−\item \demph{Success}, with pattern variables mapping to expressions
364+% Matching on an expression proceeds by comparing the expression to
356−\item \demph{Failure}, with matching continuing by proceeding to the next match clause
365+% each match clause in order, resulting in either:
357−\item Matching being \demph{blocked}, for example by attempting to match a variable
366+%
358−against a constructor pattern. In this case, no reduction occurs, because instantiating
367+% \begin{itemize}
359−the variable may provide enough information for the clause to match.
368+% \item \demph{Success}, with pattern variables mapping to expressions
360−\end{itemize}
369+% \item \demph{Failure}, with matching continuing by proceeding to the next match clause
361−
370+% \item Matching being \demph{blocked}, for example by attempting to match a variable
362−% Pat(x args) => x (Pat' args)
371+% against a constructor pattern. In this case, no reduction occurs, because instantiating
363−% Pat (x) => x
372+% the variable may provide enough information for the clause to match.
364−% Pat _ => _
373+% \end{itemize}
365−
374+%
366−In order to implement pattern matching, we must separate the \remph{accessible} and
375+% % Pat(x args) => x (Pat' args)
367−\remph{inaccessible} patterns. A pattern is \demph{accessible} (that is, it is possible
376+% % Pat (x) => x
368−to match against it) if it is constructor headed, or a variable. Inaccessible patterns
377+% % Pat _ => _
369−are converted to ``match anything'' patterns. Clauses are converted to matchable pattern
378+%
370−clauses with the $\MO{Clause}$ operation, given in Figure \ref{mkclause}.
379+% In order to implement pattern matching, we must separate the \remph{accessible} and
371−We extend the vector notation to meta-operations: the notation $\vec{\MO{Pat}}$ lifts the
380+% \remph{inaccessible} patterns. A pattern is \demph{accessible} (that is, it is possible
372−$\MO{Pat}$ operation across a list of arguments.
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}
373
478
374\FFIG{
479\FFIG{
375−\AR{
480+\begin{array}{ll}
376−\PA{\A}{
481+\mbox{\textbf{Church-Rosser}} &
377−& \MO{Clause} & (\pat{\tx}{\tU}\SC\FN{f}\:\tts\:=\:\ve)
482+\begin{array}{ll}
378− & \MoRet{\FN{f}\:(\vec{\MO{Pat}}\:\tts)\:=\:\ve}
483+\mbox{If}\hg\Gamma\proves\vs\converts\vt \\
379−}
484+\mbox{then there is a common reduct $\vr$ such that}\;\\
380−\medskip\\
485+\Gamma\proves\vs\reducesto\vr\hg\Gamma\proves\vt\reducesto\vr
381−\PA{\A}{
486+\end{array}
382−& \MO{Pat} & (\vx\:\tts) & \MoRet{\vx\:(\vec{\MO{Pat}}\:\tts)
487+\medskip
383− \hg\mbox{(if $\MO{Con}\:\vx$ and $\MO{Arity}\:\vx = \MO{Length}\:\tts$)}} \\
488+\\
384−& \MO{Pat} & \vx & \MoRet{\vx} \hg\mbox(if $\vx$ is a pattern variable)\\
489+\mbox{\textbf{Subject Reduction}} &
385−& \MO{Pat} & \cdot & \MoRet{\_} \hg\mbox(in all other cases)\\
490+\begin{array}{ll}
386−}
491+\mbox{If} & \Gamma\proves\vs\Hab\vS\hg\Gamma\proves\vs\reduces\vt\\
387−}
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}
388}
512}
389−{Building matchable pattern clauses}
513+{Metatheoretic properties of \TT{}}
390−{mkclause}
514+{metatheory}
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−
419
515
420−\FFIG{
516+We assume that \TT{} respects the usual metatheoretic properties, as shown in
421−\AR{
517+Figure \ref{metatheory}. Specifically: the \demph{Church-Rosser} property
422−\PA{\A\A}{
518+(i.e. that distinct reduction sequences lead to the same normal form);
423−& \MO{MatchArg} & (\vx\:\tts) & (\vx\:\tts')
519+\demph{subject reduction} (i.e. that computation preserves type); the
424− & \MoRet{\vec{\MO{MatchArg}}\:\tts\:\tts'\hg\mbox{(if $\MO{Con}\:\vx$)}}\\
520+\demph{cut} property (i.e. that $\RW{let}$-bound terms may be substituted into
425−& \MO{MatchArg} & (\vx\:\tts) & \vx & \MoRet{\Blocked} \\
521+their scope); and \demph{strengthening} (i.e. that removing unused definitions
426−& \MO{MatchArg} & \vx & \vt & \MoRet{\Success\:(\vx\mapsto\vt)} \\
522+from scope does not affect typechecking).
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}
458
523
459−By convention, we write the application of a meta-operation $\MO{Op}$
524+One property which is noticeably absent is \demph{strong normalisation}.
460−across a vector $\tx$ as $\vec{\MO{Op}}\:\tx$.
525+Although desirable to preserve termination and decidability of type checking,
461−In practice, for efficiency, pattern matching is implemented by compiling the match clauses to
526+we allow diverging terms for pragmatic reasons as \Idris{} is primarily a
462−a tree of case expressions~\cite{Augustsson1985}.
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.
463
530
464\subsection{Totality checking}
531\subsection{Totality checking}
465
532
466−In order to ensure termination of type checking
533+In order to ensure termination of type checking we must distinguish terms for
467−we must distinguish terms for which evaluation definitely terminates, and
534+which evaluation definitely terminates, and those which may diverge. \TT{}
468−those which may diverge. \TT{} takes a simple but pragmatic and
535+takes a simple but pragmatic and effective approach to termination checking:
469−effective approach to termination
536+any functions which do not satisfy a syntactic constraint on recursive calls
470−checking: any functions which do not satisfy a syntactic constraint on recursive
537+are marked as \emph{partial}. Additionally, any function which calls a partial
471−calls are marked as \emph{partial}. Additionally, any function which calls a partial
472function or uses a data type which is not strictly positive is also marked as
538function or uses a data type which is not strictly positive is also marked as
473partial. The syntactic constraint we use is that a recursive call in a pattern
539partial. 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
540+clause must have an argument which is structurally smaller than an input
475−in the same position. \TT{} also marks functions which do not cover all possible
541+argument in the same position. \TT{} also marks functions which do not cover
476−inputs as partial. This totality checking is independent of the rest of the type
542+all possible inputs as partial. This totality checking is independent of the
477−theory, and can be extended.
543+rest of the type theory, and can be extended.
478
544
479−This approach, separating the termination requirement from the type theory, means that
545+This approach, separating the termination requirement from the type theory,
480−an \Idris{} programmer makes the decision about the importance of totality for each
546+means that an \Idris{} programmer makes the decision about the importance of
481−function rather than having the totality requirement imposed by the type theory.
547+totality for each function rather than having the totality requirement imposed
548+by the type theory.
482
549
483\subsection{From \Idris{} to \TT{}}
550\subsection{From \Idris{} to \TT{}}
484
551
@@ -526,7 +593,7 @@ algorithm:
526
593
527\begin{SaveVerbatim}{vAddImpSolve}
594\begin{SaveVerbatim}{vAddImpSolve}
528
595
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
530vAdd a O c (Nil a) (Nil a) = Nil a
597vAdd a O c (Nil a) (Nil a) = Nil a
531vAdd a (S k) c ((::) a k x xs) ((::) a k y ys)
598vAdd a (S k) c ((::) a k x xs) ((::) a k y ys)
532 = (::) a k ((+) c x y) (vAdd a k c xs ys)
599 = (::) a k ((+) c x y) (vAdd a k c xs ys)
@@ -540,35 +607,29 @@ switching to \TT{} notation from the ASCII \Idris{} syntax.
540
607
541\FFIG{
608\FFIG{
542\AR{
609\AR{
543−\begin{array}{ll}
610+\FN{vAdd} \Hab(\va\Hab\Type)\to(\vn\Hab\Nat)\to\TC{Num}\;\va\to
544−\FN{vAdd} & \Hab(\va\Hab\Set)\to(\vn\Hab\Nat)\to\TC{Num}\:\va\to
611+ \Vect\;\va\;\vn\to\Vect\;\va\;\vn\to\Vect\;\va\;\vn\\
545− \Vect\:\va\:\vn\to\Vect\:\va\:\vn\to\Vect\:\va\:\vn\\
612+\RW{var}\;\va\Hab\Type,\;\vc\Hab\TC{Num}\;\va\SC\\
546−\end{array}
613+\hg\FN{vAdd} \; \va \; \Z \; \vc \; (\DC{Nil}\;\va) \; (\DC{Nil}\;\va) \;
547−\\
614+\cq\;\DC{Nil}\;\va \\
548−\begin{array}{lccccccc}
615+\RW{var}\;\AR{
549−\multicolumn{5}{l}{
616+\va\Hab\Type,\;\vk\Hab\Nat,\;\vc\Hab\TC{Num}\;\va,\\
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,\\
555\vx\Hab\va,\;\vxs\Hab\Vect\;\va\;\vk,\;
617\vx\Hab\va,\;\vxs\Hab\Vect\;\va\;\vk,\;
556\vy\Hab\va,\;\vys\Hab\Vect\;\va\;\vk
618\vy\Hab\va,\;\vys\Hab\Vect\;\va\;\vk
557\SC
619\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))
558}
626}
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}
566}
627}
567}
628}
568{Pairwise addition of vectors in \TT{}}
629{Pairwise addition of vectors in \TT{}}
569{ttvadd}
630{ttvadd}
570
631
571−\subsubsection{An observation}
632+\subsubsection{An Observation: Programming vs Theorem Proving}
572
633
573\Idris{} programs may contain several high level constructs not present in \TT{}, such
634\Idris{} programs may contain several high level constructs not present in \TT{}, such
574as implicit arguments, type classes, \texttt{where} clauses, pattern matching \texttt{let}
635as 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
580constructing programs and theorems:
641constructing programs and theorems:
581
642
582\begin{itemize}
643\begin{itemize}
583−\item \remph{Pattern matching} is a convenient abstraction for humans to write programs,
644+\item \remph{Pattern matching} is a convenient abstraction for humans to write
584−in that it allows a programmer to express exactly the computational behaviour of a function.
645+programs, in that it allows a programmer to express exactly the computational
585−\item \remph{Tactics}, such as those used in the Coq theorem prover~\cite{Bertot2004},
646+behaviour of a function.
586−are a convenient abstraction for building proofs and programs by \remph{refinement}.
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}.
587\end{itemize}
650\end{itemize}
588
651
589−The idea behind the \Idris{} elaborator, therefore, is to use the high level program
652+The idea behind the \Idris{} elaborator, therefore, is to use the high level
590−to direct \demph{tactics} to build \TT{} programs by refinement. The
653+program to direct \demph{tactics} to build \TT{} programs by refinement. The
591−elaborator is implemented as an Embedded Domain Specific Language (EDSL) in Haskell.
654+elaborator is implemented as a Haskell monad capturing proof state, with a
592−The remainder
655+collection of tactics for updating and refining the proof state. The remainder
593−of this paper describes the EDSL and demonstrates how it is used to implement
656+of this paper describes this elaborator and demonstrates how it is used to
594−all of the high level features of \Idris{}.
657+implement the high level features of \Idris{}.
595
658
596
659
597
660
samples/binary.idr+2−2
@@ -1,6 +1,6 @@
1module main
1module main
2
2
3−data Bit : Nat -> Set where
3+data Bit : Nat -> Type where
4 b0 : Bit 0
4 b0 : Bit 0
5 b1 : Bit 1
5 b1 : Bit 1
6
6
@@ -10,7 +10,7 @@ instance Show (Bit n) where
10
10
11infixl 5 #
11infixl 5 #
12
12
13−data Binary : (width : Nat) -> (value : Nat) -> Set where
13+data Binary : (width : Nat) -> (value : Nat) -> Type where
14 zero : Binary O O
14 zero : Binary O O
15 (#) : Binary w v -> Bit bit -> Binary (S w) (bit + 2 * v)
15 (#) : Binary w v -> Bit bit -> Binary (S w) (bit + 2 * v)
16
16
samples/interp-alt.idr+4−4
@@ -2,18 +2,18 @@ module main
2
2
3data Ty = TyInt | TyBool| TyFun Ty Ty
3data Ty = TyInt | TyBool| TyFun Ty Ty
4
4
5−interpTy : Ty -> Set
5+interpTy : Ty -> Type
6interpTy TyInt = Int
6interpTy TyInt = Int
7interpTy TyBool = Bool
7interpTy TyBool = Bool
8interpTy (TyFun s t) = interpTy s -> interpTy t
8interpTy (TyFun s t) = interpTy s -> interpTy t
9
9
10using (G : Vect Ty n)
10using (G : Vect Ty n)
11
11
12− data Env : Vect Ty n -> Set where
12+ data Env : Vect Ty n -> Type where
13 Nil : Env Nil
13 Nil : Env Nil
14 (::) : interpTy a -> Env G -> Env (a :: G)
14 (::) : interpTy a -> Env G -> Env (a :: G)
15
15
16−-- data HasType : (i : Fin n) -> Vect Ty n -> Ty -> Set where
16+-- data HasType : (i : Fin n) -> Vect Ty n -> Ty -> Type where
17-- stop : HasType fO (t :: G) t
17-- stop : HasType fO (t :: G) t
18-- pop : HasType k G t -> HasType (fS k) (u :: G) t
18-- pop : HasType k G t -> HasType (fS k) (u :: G) t
19
19
@@ -21,7 +21,7 @@ using (G : Vect Ty n)
21 lookup fO (x :: xs) = x
21 lookup fO (x :: xs) = x
22 lookup (fS i) (x :: xs) = lookup i xs
22 lookup (fS i) (x :: xs) = lookup i xs
23
23
24− data Expr : Vect Ty n -> Ty -> Set where
24+ data Expr : Vect Ty n -> Ty -> Type where
25 Var : (i : Fin n) -> Expr G (lookup i G)
25 Var : (i : Fin n) -> Expr G (lookup i G)
26 Val : (x : Int) -> Expr G TyInt
26 Val : (x : Int) -> Expr G TyInt
27 Lam : Expr (a :: G) t -> Expr G (TyFun a t)
27 Lam : Expr (a :: G) t -> Expr G (TyFun a t)
samples/interp.idr+4−4
@@ -2,18 +2,18 @@ module main
2
2
3data Ty = TyInt | TyBool | TyFun Ty Ty
3data Ty = TyInt | TyBool | TyFun Ty Ty
4
4
5−interpTy : Ty -> Set
5+interpTy : Ty -> Type
6interpTy TyInt = Int
6interpTy TyInt = Int
7interpTy TyBool = Bool
7interpTy TyBool = Bool
8interpTy (TyFun s t) = interpTy s -> interpTy t
8interpTy (TyFun s t) = interpTy s -> interpTy t
9
9
10using (G : Vect Ty n)
10using (G : Vect Ty n)
11
11
12− data Env : Vect Ty n -> Set where
12+ data Env : Vect Ty n -> Type where
13 Nil : Env Nil
13 Nil : Env Nil
14 (::) : interpTy a -> Env G -> Env (a :: G)
14 (::) : interpTy a -> Env G -> Env (a :: G)
15
15
16− data HasType : (i : Fin n) -> Vect Ty n -> Ty -> Set where
16+ data HasType : (i : Fin n) -> Vect Ty n -> Ty -> Type where
17 stop : HasType fO (t :: G) t
17 stop : HasType fO (t :: G) t
18 pop : HasType k G t -> HasType (fS k) (u :: G) t
18 pop : HasType k G t -> HasType (fS k) (u :: G) t
19
19
@@ -21,7 +21,7 @@ using (G : Vect Ty n)
21 lookup stop (x :: xs) = x
21 lookup stop (x :: xs) = x
22 lookup (pop k) (x :: xs) = lookup k xs
22 lookup (pop k) (x :: xs) = lookup k xs
23
23
24− data Expr : Vect Ty n -> Ty -> Set where
24+ data Expr : Vect Ty n -> Ty -> Type where
25 Var : HasType i G t -> Expr G t
25 Var : HasType i G t -> Expr G t
26 Val : (x : Int) -> Expr G TyInt
26 Val : (x : Int) -> Expr G TyInt
27 Lam : Expr (a :: G) t -> Expr G (TyFun a t)
27 Lam : Expr (a :: G) t -> Expr G (TyFun a t)
src/Core/CaseTree.hs+1−1
@@ -79,7 +79,7 @@ instance TermSize CaseAlt where
79small :: Name -> [Name] -> SC -> Bool
79small :: Name -> [Name] -> SC -> Bool
80small n args t = let as = findAllUsedArgs t args in
80small n args t = let as = findAllUsedArgs t args in
81 length as == length (nub as) &&
81 length as == length (nub as) &&
82− termsize n t < 20
82+ termsize n t < 5
83
83
84namesUsed :: SC -> [Name]
84namesUsed :: SC -> [Name]
85namesUsed sc = nub $ nu' [] sc where
85namesUsed sc = nub $ nu' [] sc where
src/Core/Elaborate.hs+45−21
@@ -15,6 +15,7 @@ import Core.ProofState
15import Core.TT
15import Core.TT
16import Core.Evaluate
16import Core.Evaluate
17import Core.Typecheck
17import Core.Typecheck
18+import Core.Unify
18
19
19import Control.Monad.State
20import Control.Monad.State
20import Data.Char
21import Data.Char
@@ -118,6 +119,10 @@ get_holes :: Elab' aux [Name]
118get_holes = do ES p _ _ <- get
119get_holes = do ES p _ _ <- get
119 return (holes (fst p))
120 return (holes (fst p))
120
121
122+get_probs :: Elab' aux Fails
123+get_probs = do ES p _ _ <- get
124+ return (problems (fst p))
125+
121-- get the current goal type
126-- get the current goal type
122goal :: Elab' aux Type
127goal :: Elab' aux Type
123goal = do ES p _ _ <- get
128goal = do ES p _ _ <- get
@@ -150,10 +155,6 @@ get_deferred :: Elab' aux [Name]
150get_deferred = do ES p _ _ <- get
155get_deferred = do ES p _ _ <- get
151 return (deferred (fst p))
156 return (deferred (fst p))
152
157
153−get_inj :: Elab' aux [(Term, Term, Term)]
154−get_inj = do ES p _ _ <- get
155− return (injective (fst p))
156−
157checkInjective :: (Term, Term, Term) -> Elab' aux ()
158checkInjective :: (Term, Term, Term) -> Elab' aux ()
158checkInjective (tm, l, r) = do ctxt <- get_context
159checkInjective (tm, l, r) = do ctxt <- get_context
159 if isInj ctxt tm then return ()
160 if isInj ctxt tm then return ()
@@ -296,6 +297,9 @@ deferType n ty ns = processTactic' (DeferType n ty ns)
296instanceArg :: Name -> Elab' aux ()
297instanceArg :: Name -> Elab' aux ()
297instanceArg n = processTactic' (Instance n)
298instanceArg n = processTactic' (Instance n)
298
299
300+setinj :: Name -> Elab' aux ()
301+setinj n = processTactic' (SetInjective n)
302+
299proofstate :: Elab' aux ()
303proofstate :: Elab' aux ()
300proofstate = processTactic' ProofState
304proofstate = processTactic' ProofState
301
305
@@ -375,12 +379,14 @@ apply fn imps =
375 if null imps then [] -- do all we can
379 if null imps then [] -- do all we can
376 else
380 else
377 map fst (filter (not.snd) (zip args (map fst imps)))
381 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) $
379 unified p
383 unified p
380 let unify = -- trace ("Not done " ++ show hs) $
384 let unify = -- trace ("Not done " ++ show hs) $
381− dropGiven dont hs
385+ dropGiven dont hunis hs
382 put (ES (p { dontunify = dont, unified = (n, unify) }, a) s prev)
386 put (ES (p { dontunify = dont, unified = (n, unify) }, a) s prev)
383 ptm <- get_term
387 ptm <- get_term
388+ g <- goal
389+-- trace ("Goal " ++ show g ++ "\n" ++ show (fn, imps, unify) ++ "\n" ++ show ptm) $
384 end_unify
390 end_unify
385 ptm <- get_term
391 ptm <- get_term
386 return (map (updateUnify unify) args)
392 return (map (updateUnify unify) args)
@@ -461,15 +467,20 @@ simple_app fun arg =
461 claim a RType
467 claim a RType
462 claim b RType
468 claim b RType
463 claim f (RBind (MN 0 "aX") (Pi (Var a)) (Var b))
469 claim f (RBind (MN 0 "aX") (Pi (Var a)) (Var b))
470+ tm <- get_term
464 start_unify s
471 start_unify s
465 claim s (Var a)
472 claim s (Var a)
466 prep_fill f [s]
473 prep_fill f [s]
467 -- try elaborating in both orders, since we might learn something useful
474 -- try elaborating in both orders, since we might learn something useful
468 -- either way
475 -- either way
469− try (do focus s; arg
476+-- try (do focus s; arg
470− focus f; fun)
477+-- focus f; fun)
471− (do focus f; fun
478+-- (do focus f; fun
472− focus s; arg)
479+-- focus s; arg)
480+ focus f; fun
481+ focus s; arg
482+ tm <- get_term
483+ ps <- get_probs
473 complete_fill
484 complete_fill
474 hs <- get_holes
485 hs <- get_holes
475 -- We don't need a and b in the hole queue any more since they were just for
486 -- 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
493try' :: Elab' aux a -> Elab' aux a -> Bool -> Elab' aux a
504try' :: Elab' aux a -> Elab' aux a -> Bool -> Elab' aux a
494try' t1 t2 proofSearch
505try' t1 t2 proofSearch
495 = do s <- get
506 = do s <- get
496− case runStateT t1 s of
507+ ps <- get_probs
508+ case prunStateT ps t1 s of
497 OK (v, s') -> do put s'
509 OK (v, s') -> do put s'
498 return v
510 return v
499 Error e1 -> if proofSearch || recoverableErr e1 then
511 Error e1 -> if proofSearch || recoverableErr e1 then
@@ -525,18 +537,30 @@ tryAll xs = tryAll' [] (cantResolve, 0) (map fst xs)
525 tryAll' [res] _ [] = res
537 tryAll' [res] _ [] = res
526 tryAll' (_:_) _ [] = cantResolve
538 tryAll' (_:_) _ [] = cantResolve
527 tryAll' [] (f, _) [] = f
539 tryAll' [] (f, _) [] = f
528− tryAll' cs f (x:xs) = do s <- get
540+ tryAll' cs f (x:xs)
529− case runStateT x s of
541+ = do s <- get
530− OK (v, s') -> tryAll' ((do put s'
542+ ps <- get_probs
531− return v):cs) f xs
543+ case prunStateT ps x s of
532− Error err -> do put s
544+ OK (v, s') -> tryAll' ((do put s'
533− if (score err) < 100
545+ return v):cs) f xs
534− then
546+ Error err -> do put s
535− tryAll' cs (better err f) xs
547+ if (score err) < 100
536− else
548+ then tryAll' cs (better err f) xs
537− tryAll' [] (better err f) xs -- give up
549+ else tryAll' [] (better err f) xs -- give up
550+
538
551
539 better err (f, i) = let s = score err in
552 better err (f, i) = let s = score err in
540 if (s >= i) then (lift (tfail err), s)
553 if (s >= i) then (lift (tfail err), s)
541 else (f, i)
554 else (f, i)
542
555
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
224 do let val = lookupDefAcc Nothing n atRepl ctxt
224 do let val = lookupDefAcc Nothing n atRepl ctxt
225 case val of
225 case val of
226 [(CaseOp inl inr _ _ _ ns tree _ _, acc)]
226 [(CaseOp inl inr _ _ _ ns tree _ _, acc)]
227− | acc == Public || simpl -> -- unoptimised version
227+ | acc == Public -> -- unoptimised version
228 if canSimplify inl inr n stk
228 if canSimplify inl inr n stk
229 then return $ unload env (VP Ref n ty) args
229 then return $ unload env (VP Ref n ty) args
230 else do c <- evCase ntimes (n:stk) top env ns args tree
230 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
11import Control.Monad.State
11import Control.Monad.State
12import System.Console.Haskeline
12import System.Console.Haskeline
13
13
14+import Idris.AbsSyntaxTree (Idris)
15+
14import Util.Pretty
16import Util.Pretty
15
17
16data ShellState = ShellState
18data ShellState = ShellState
@@ -55,21 +57,23 @@ processCommand (Tac e) state
55 err -> (state, show err)
57 err -> (state, show err)
56 | otherwise = (state, "No proof in progress")
58 | otherwise = (state, "No proof in progress")
57
59
58−runShell :: ShellState -> InputT IO ShellState
60+runShell :: ShellState -> Idris ShellState
59−runShell st = do (prompt, parser) <-
61+runShell st = runInputT defaultSettings $ runShell' st
60− maybe (return ("TT# ", parseCommand))
62+ where
61− (\st -> do outputStrLn . render . pretty $ st
63+ runShell' st = do (prompt, parser) <-
62− return (show (thname st) ++ "# ", parseTactic))
64+ maybe (return ("TT# ", parseCommand))
63− (prf st)
65+ (\st -> do outputStrLn . render . pretty $ st
64− x <- getInputLine prompt
66+ return (show (thname st) ++ "# ", parseTactic))
65− cmd <- case x of
67+ (prf st)
66− Nothing -> return $ Right Quit
68+ x <- getInputLine prompt
67− Just input -> return (parser input)
69+ cmd <- case x of
68− case cmd of
70+ Nothing -> return $ Right Quit
69− Left err -> do outputStrLn (show err)
71+ Just input -> return (parser input)
70− runShell st
72+ case cmd of
71− Right cmd -> do let (st', r) = processCommand cmd st
73+ Left err -> do outputStrLn (show err)
72− outputStrLn r
74+ runShell' st
73− if (not (exitNow st')) then runShell st'
75+ Right cmd -> do let (st', r) = processCommand cmd st
74− else return st'
76+ outputStrLn r
77+ if (not (exitNow st')) then runShell' st'
78+ else return st'
75
79
src/Core/ProofState.hs+98−45
@@ -29,7 +29,7 @@ data ProofState = PS { thname :: Name,
29 unified :: (Name, [(Name, Term)]),
29 unified :: (Name, [(Name, Term)]),
30 solved :: Maybe (Name, Term),
30 solved :: Maybe (Name, Term),
31 problems :: Fails,
31 problems :: Fails,
32− injective :: [(Term, Term, Term)],
32+ injective :: [Name],
33 deferred :: [Name], -- names we'll need to define
33 deferred :: [Name], -- names we'll need to define
34 instances :: [Name], -- instance arguments (for type classes)
34 instances :: [Name], -- instance arguments (for type classes)
35 previous :: Maybe ProofState, -- for undo
35 previous :: Maybe ProofState, -- for undo
@@ -68,6 +68,7 @@ data Tactic = Attack
68 | Defer Name
68 | Defer Name
69 | DeferType Name Raw [Name]
69 | DeferType Name Raw [Name]
70 | Instance Name
70 | Instance Name
71+ | SetInjective Name
71 | MoveLast Name
72 | MoveLast Name
72 | ProofState
73 | ProofState
73 | Undo
74 | Undo
@@ -148,15 +149,28 @@ hole _ = False
148
149
149holeName i = MN i "hole"
150holeName i = MN i "hole"
150
151
152+qshow :: Fails -> String
153+qshow fs = show (map (\ (x, y, _, _) -> (x, y)) fs)
154+
151unify' :: Context -> Env -> TT Name -> TT Name -> StateT TState TC [(Name, TT Name)]
155unify' :: 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
156+unify' ctxt env topx topy =
153− addInj inj
157+ do ps <- get
154− case fails of
158+ (u, fails) <- lift $ unify ctxt env topx topy (injective ps) (holes ps)
155− [] -> return u
159+-- trace ("Unified " ++ show (topx, topy) ++ show (injective ps) ++
156− err ->
160+-- " " ++ show u ++ "\n" ++ qshow fails ++ "\nCurrent problems:\n"
157− do ps <- get
161+-- ++ qshow (problems ps) ++ "\n" ++ show (holes ps)) $
158− put (ps { problems = err ++ problems ps })
162+ case fails of
159− return []
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
160
174
161getName :: Monad m => String -> StateT TState m Name
175getName :: Monad m => String -> StateT TState m Name
162getName tag = do ps <- get
176getName tag = do ps <- get
@@ -194,6 +208,7 @@ goalAtFocus :: ProofState -> TC (Binder Type)
194goalAtFocus ps
208goalAtFocus ps
195 | not $ null (holes ps) = do g <- goal (Just (head (holes ps))) (pterm ps)
209 | not $ null (holes ps) = do g <- goal (Just (head (holes ps))) (pterm ps)
196 return (goalType g)
210 return (goalType g)
211+ | otherwise = error $ "No goal in " ++ show (holes ps) ++ show (pterm ps)
197
212
198goal :: Hole -> Term -> TC Goal
213goal :: Hole -> Term -> TC Goal
199goal h tm = g [] tm where
214goal h tm = g [] tm where
@@ -288,6 +303,12 @@ instanceArg n ctxt env (Bind x (Hole t) sc)
288 instances = x:is })
303 instances = x:is })
289 return (Bind x (Hole t) sc)
304 return (Bind x (Hole t) sc)
290
305
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+
291defer :: Name -> RunTactic
312defer :: Name -> RunTactic
292defer n ctxt env (Bind x (Hole t) (P nt x' ty)) | x == x' =
313defer n ctxt env (Bind x (Hole t) (P nt x' ty)) | x == x' =
293 do action (\ps -> let hs = holes ps in
314 do action (\ps -> let hs = holes ps in
@@ -322,10 +343,6 @@ regret ctxt env (Bind x (Hole t) sc) | noOccurrence x sc =
322 return sc
343 return sc
323regret ctxt env (Bind x (Hole t) _) = fail $ show x ++ " : " ++ show t ++ " is not solved"
344regret ctxt env (Bind x (Hole t) _) = fail $ show x ++ " : " ++ show t ++ " is not solved"
324
345
325−addInj :: [(Term, Term, Term)] -> StateT TState TC ()
326−addInj inj = do ps <- get
327− put (ps { injective = inj ++ injective ps })
328−
329exact :: Raw -> RunTactic
346exact :: Raw -> RunTactic
330exact guess ctxt env (Bind x (Hole ty) sc) =
347exact guess ctxt env (Bind x (Hole ty) sc) =
331 do (val, valty) <- lift $ check ctxt env guess
348 do (val, valty) <- lift $ check ctxt env guess
@@ -344,7 +361,7 @@ fill guess ctxt env (Bind x (Hole ty) sc) =
344 ns <- unify' ctxt env valty ty
361 ns <- unify' ctxt env valty ty
345 ps <- get
362 ps <- get
346 let (uh, uns) = unified ps
363 let (uh, uns) = unified ps
347− put (ps { unified = (uh, uns ++ ns) })
364+-- put (ps { unified = (uh, uns ++ ns) })
348-- addLog (show (uh, uns ++ ns))
365-- addLog (show (uh, uns ++ ns))
349 return $ Bind x (Guess ty val) sc
366 return $ Bind x (Guess ty val) sc
350fill _ _ _ _ = fail "Can't fill here."
367fill _ _ _ _ = fail "Can't fill here."
@@ -362,22 +379,25 @@ complete_fill ctxt env (Bind x (Guess ty val) sc) =
362 ns <- unify' ctxt env valty ty
379 ns <- unify' ctxt env valty ty
363 ps <- get
380 ps <- get
364 let (uh, uns) = unified ps
381 let (uh, uns) = unified ps
365− put (ps { unified = (uh, uns ++ ns) })
382+-- put (ps { unified = (uh, uns ++ ns) })
366 return $ Bind x (Guess ty val) sc
383 return $ Bind x (Guess ty val) sc
367complete_fill ctxt env t = fail $ "Can't complete fill at " ++ show t
384complete_fill ctxt env t = fail $ "Can't complete fill at " ++ show t
368
385
369solve :: RunTactic
386solve :: RunTactic
370solve ctxt env (Bind x (Guess ty val) sc)
387solve ctxt env (Bind x (Guess ty val) sc)
371− | pureTerm val = do ps <- get
388+ | True = do ps <- get
372 let (uh, uns) = unified ps
389 let (uh, uns) = unified ps
373 action (\ps -> ps { holes = holes ps \\ [x],
390 action (\ps -> ps { holes = holes ps \\ [x],
374 solved = Just (x, val),
391 solved = Just (x, val),
392+-- problems = solveInProblems
393+-- x val (problems ps),
375 -- dontunify = dontunify ps \\ [x],
394 -- dontunify = dontunify ps \\ [x],
376 -- unified = (uh, uns ++ [(x, val)]),
395 -- unified = (uh, uns ++ [(x, val)]),
377 instances = instances ps \\ [x] })
396 instances = instances ps \\ [x] })
378 return $ {- Bind x (Let ty val) sc -}
397 return $ {- Bind x (Let ty val) sc -}
379 instantiate val (pToV x sc)
398 instantiate val (pToV x sc)
380− | otherwise = lift $ tfail $ IncompleteTerm val
399+ | otherwise = do ps <- get
400+ lift $ tfail $ IncompleteTerm val
381solve _ _ h = do ps <- get
401solve _ _ h = do ps <- get
382 fail $ "Not a guess " ++ show h ++ "\n" ++ show (holes ps, pterm ps)
402 fail $ "Not a guess " ++ show h ++ "\n" ++ show (holes ps, pterm ps)
383
403
@@ -396,7 +416,7 @@ introTy ty mn ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
396 do ns <- unify' ctxt env s tyv
416 do ns <- unify' ctxt env s tyv
397 ps <- get
417 ps <- get
398 let (uh, uns) = unified ps
418 let (uh, uns) = unified ps
399− put (ps { unified = (uh, uns ++ ns) })
419+-- put (ps { unified = (uh, uns ++ ns) })
400 return $ Bind n (Lam tyv) (Bind x (Hole t') (P Bound x t'))
420 return $ Bind n (Lam tyv) (Bind x (Hole t') (P Bound x t'))
401 _ -> fail "Nothing to introduce"
421 _ -> fail "Nothing to introduce"
402introTy ty n ctxt env _ = fail "Can't introduce here."
422introTy ty n ctxt env _ = fail "Can't introduce here."
@@ -494,7 +514,8 @@ hnf_compute ctxt env (Bind x (Hole ty) sc) =
494 do let ty' = hnf ctxt env ty in
514 do let ty' = hnf ctxt env ty in
495-- trace ("HNF " ++ show (ty, ty')) $
515-- trace ("HNF " ++ show (ty, ty')) $
496 return $ Bind x (Hole ty') sc
516 return $ Bind x (Hole ty') sc
497−
517+hnf_compute ctxt env t = return t
518+
498check_in :: Raw -> RunTactic
519check_in :: Raw -> RunTactic
499check_in t ctxt env tm =
520check_in t ctxt env tm =
500 do (val, valty) <- lift $ check ctxt env t
521 do (val, valty) <- lift $ check ctxt env t
@@ -515,7 +536,7 @@ eval_in t ctxt env tm =
515 return tm
536 return tm
516
537
517start_unify :: Name -> RunTactic
538start_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, []) })
519 return tm
540 return tm
520
541
521tmap f (a, b, c) = (f a, b, c)
542tmap f (a, b, c) = (f a, b, c)
@@ -524,22 +545,24 @@ solve_unified :: RunTactic
524solve_unified ctxt env tm =
545solve_unified ctxt env tm =
525 do ps <- get
546 do ps <- get
526 let (_, ns) = unified ps
547 let (_, ns) = unified ps
527− let unify = dropGiven (dontunify ps) ns
548+ let unify = dropGiven (dontunify ps) ns (holes ps)
528 action (\ps -> ps { holes = holes ps \\ map fst unify })
549 action (\ps -> ps { holes = holes ps \\ map fst unify })
529 action (\ps -> ps { pterm = updateSolved unify (pterm ps) })
550 action (\ps -> ps { pterm = updateSolved unify (pterm ps) })
530− action (\ps -> ps { injective = map (tmap (updateSolved unify)) (injective ps) })
531 return (updateSolved unify tm)
551 return (updateSolved unify tm)
532 where
552 where
533
553
534−dropGiven du [] = []
554+dropGiven du [] hs = []
535−dropGiven du ((n, P Bound t ty) : us) | n `elem` du && not (t `elem` du)
555+dropGiven du ((n, P Bound t ty) : us) hs
536− = (t, P Bound n ty) : dropGiven du us
556+ | n `elem` du && not (t `elem` du)
537−dropGiven du (u@(n, _) : us) | n `elem` du = dropGiven du us
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
538-- dropGiven du (u@(_, P a n ty) : us) | n `elem` du = dropGiven du us
561-- 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
540
563
541updateSolved xs x = -- trace ("Updating " ++ show xs ++ " in " ++ show x) $
564updateSolved xs x = -- trace ("Updating " ++ show xs ++ " in " ++ show x) $
542− updateSolved' xs x
565+ updateSolved' xs x
543updateSolved' xs (Bind n (Hole ty) t)
566updateSolved' xs (Bind n (Hole ty) t)
544 | Just v <- lookup n xs = instantiate v (pToV n (updateSolved' xs t))
567 | Just v <- lookup n xs = instantiate v (pToV n (updateSolved' xs t))
545updateSolved' xs (Bind n b t)
568updateSolved' xs (Bind n b t)
@@ -549,11 +572,30 @@ updateSolved' xs (P _ n _)
549 | Just v <- lookup n xs = v
572 | Just v <- lookup n xs = v
550updateSolved' xs t = t
573updateSolved' xs t = t
551
574
552−updateProblems ns [] = []
575+updateEnv ns [] = []
553−updateProblems ns ((x, y, env, err) : ps) =
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) =
554 let x' = updateSolved ns x
590 let x' = updateSolved ns x
555− y' = updateSolved ns y in
591+ y' = updateSolved ns y
556− (x',y',env,err) : updateProblems ns ps
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')
557
599
558processTactic :: Tactic -> ProofState -> TC (ProofState, String)
600processTactic :: Tactic -> ProofState -> TC (ProofState, String)
559processTactic QED ps = case holes ps of
601processTactic QED ps = case holes ps of
@@ -568,18 +610,16 @@ processTactic Undo ps = case previous ps of
568 Just pold -> return (pold, "")
610 Just pold -> return (pold, "")
569processTactic EndUnify ps
611processTactic EndUnify ps
570 = let (h, ns_in) = unified ps
612 = let (h, ns_in) = unified ps
571− ns = dropGiven (dontunify ps) ns_in
613+ ns = dropGiven (dontunify ps) ns_in (holes ps)
572 ns' = map (\ (n, t) -> (n, updateSolved ns t)) ns
614 ns' = map (\ (n, t) -> (n, updateSolved ns t)) ns
573− tm' = -- trace ("Updating " ++ show ns') $ -- ++ " in " ++ show (pterm ps)) $
615+ (ns'', probs') = updateProblems (context ps) ns' (problems ps)
574− updateSolved ns' (pterm ps)
616+ (injective ps) (holes ps)
575− probs' = updateProblems ns' (problems ps) in
617+ tm' = -- trace ("Updating " ++ show ns' ++ "\n" ++ show ns'') $ -- ++ " in " ++ show (pterm ps)) $
576− case probs' of
618+ updateSolved ns'' (pterm ps) in
577− [] -> return (ps { pterm = tm',
619+ return (ps { pterm = tm',
578− unified = (h, []),
620+ unified = (h, []),
579− injective = map (tmap (updateSolved ns'))
621+ problems = probs',
580− (injective ps),
622+ holes = holes ps \\ map fst ns'' }, "")
581− holes = holes ps \\ map fst ns' }, "")
582− errs@((_,_,_,err):_) -> tfail err
583processTactic (Reorder n) ps
623processTactic (Reorder n) ps
584 = do ps' <- execStateT (tactic (Just n) reorder_claims) ps
624 = do ps' <- execStateT (tactic (Just n) reorder_claims) ps
585 return (ps' { previous = Just ps, plog = "" }, plog ps')
625 return (ps' { previous = Just ps, plog = "" }, plog ps')
@@ -590,9 +630,21 @@ processTactic t ps
590 let pterm' = case solved ps' of
630 let pterm' = case solved ps' of
591 Just s -> updateSolved [s] (pterm ps')
631 Just s -> updateSolved [s] (pterm ps')
592 _ -> pterm ps'
632 _ -> 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'',
594 solved = Nothing,
644 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')
596
648
597process :: Tactic -> Name -> StateT TState TC ()
649process :: Tactic -> Name -> StateT TState TC ()
598process EndUnify _
650process EndUnify _
@@ -624,5 +676,6 @@ process t h = tactic (Just h) (mktac t)
624 mktac (Defer n) = defer n
676 mktac (Defer n) = defer n
625 mktac (DeferType n t a) = deferType n t a
677 mktac (DeferType n t a) = deferType n t a
626 mktac (Instance n) = instanceArg n
678 mktac (Instance n) = instanceArg n
679+ mktac (SetInjective n) = setinj n
627 mktac (MoveLast n) = movelast n
680 mktac (MoveLast n) = movelast n
628
681
src/Core/TT.hs+7−3
@@ -482,7 +482,7 @@ data Datatype n = Data { d_typename :: n,
482 deriving (Show, Functor, Eq)
482 deriving (Show, Functor, Eq)
483
483
484instance Eq n => Eq (TT n) where
484instance 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
486 (==) (V x) (V y) = x == y
486 (==) (V x) (V y) = x == y
487 (==) (Bind _ xb xs) (Bind _ yb ys) = xb == yb && xs == ys
487 (==) (Bind _ xb xs) (Bind _ yb ys) = xb == yb && xs == ys
488 (==) (App fx ax) (App fy ay) = fx == fy && ax == ay
488 (==) (App fx ax) (App fy ay) = fx == fy && ax == ay
@@ -794,13 +794,17 @@ showEnv' env t dbg = se 10 env t where
794
794
795-- Check whether a term has any holes in it - impure if so
795-- Check whether a term has any holes in it - impure if so
796
796
797−pureTerm :: TT n -> Bool
797+pureTerm :: TT Name -> Bool
798pureTerm (App f a) = pureTerm f && pureTerm a
798pureTerm (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
800 pureBinder (Hole _) = False
800 pureBinder (Hole _) = False
801 pureBinder (Guess _ _) = False
801 pureBinder (Guess _ _) = False
802 pureBinder (Let t v) = pureTerm t && pureTerm v
802 pureBinder (Let t v) = pureTerm t && pureTerm v
803 pureBinder t = pureTerm (binderTy t)
803 pureBinder t = pureTerm (binderTy t)
804+
805+ notClassName (MN _ "class") = False
806+ notClassName _ = True
807+
804pureTerm _ = True
808pureTerm _ = True
805
809
806-- weaken a term by adding i to each de Bruijn index (i.e. lift it over i bindings)
810-- 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
68 let fty' = case uniqueBinders (map fst env) (finalise fty) of
68 let fty' = case uniqueBinders (map fst env) (finalise fty) of
69 ty@(Bind x (Pi s) t) -> ty
69 ty@(Bind x (Pi s) t) -> ty
70 _ -> uniqueBinders (map fst env)
70 _ -> 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
72 case fty' of
74 case fty' of
73 Bind x (Pi s) t ->
75 Bind x (Pi s) t ->
74-- trace ("Converting " ++ show aty ++ " and " ++ show s ++
76-- trace ("Converting " ++ show aty ++ " and " ++ show s ++
src/Core/Unify.hs+109−44
@@ -20,25 +20,29 @@ import Debug.Trace
20type Injs = [(TT Name, TT Name, TT Name)]
20type Injs = [(TT Name, TT Name, TT Name)]
21type Fails = [(TT Name, TT Name, Env, Err)]
21type Fails = [(TT Name, TT Name, Env, Err)]
22
22
23−data UInfo = UI Int Injs Fails
23+data UInfo = UI Int Fails
24 deriving Show
24 deriving Show
25
25
26−unify :: Context -> Env -> TT Name -> TT Name -> TC ([(Name, TT Name)],
26+data UResult a = UOK a
27− Injs, Fails)
27+ | UPartOK a
28−unify ctxt env topx topy =
28+ | UFail Err
29−-- trace ("Unifying " ++ show (topx, topy)) $
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)) $
30 -- don't bother if topx and topy are different at the head
34 -- don't bother if topx and topy are different at the head
31− case runStateT (un False [] topx topy) (UI 0 [] []) of
35+ case runStateT (un False [] topx topy) (UI 0 []) of
32− OK (v, UI _ inj []) -> return (filter notTrivial v, inj, [])
36+ OK (v, UI _ []) -> return (filter notTrivial v, [])
33−-- Error e@(CantUnify False _ _ _ _ _) -> tfail e
34 res ->
37 res ->
35 let topxn = normalise ctxt env topx
38 let topxn = normalise ctxt env topx
36 topyn = normalise ctxt env topy in
39 topyn = normalise ctxt env topy in
37-- trace ("Unifying " ++ show (topx, topy) ++ "\n\n==>\n" ++ show (topxn, topyn) ++ "\n\n" ++ show res ++ "\n\n") $
40-- trace ("Unifying " ++ show (topx, topy) ++ "\n\n==>\n" ++ show (topxn, topyn) ++ "\n\n" ++ show res ++ "\n\n") $
38 case runStateT (un False [] topxn topyn)
41 case runStateT (un False [] topxn topyn)
39− (UI 0 [] []) of
42+ (UI 0 []) of
40− OK (v, UI _ inj fails) ->
43+ OK (v, UI _ fails) ->
41− return (filter notTrivial v, inj, reverse fails)
44+ return (filter notTrivial v, reverse fails)
45+-- Error e@(CantUnify False _ _ _ _ _) -> tfail e
42 Error e -> tfail e
46 Error e -> tfail e
43 where
47 where
44 notTrivial (x, P _ x' _) = x /= x'
48 notTrivial (x, P _ x' _) = x /= x'
@@ -50,21 +54,22 @@ unify ctxt env topx topy =
50
54
51 injective (P (DCon _ _) _ _) = True
55 injective (P (DCon _ _) _ _) = True
52 injective (P (TCon _ _) _ _) = True
56 injective (P (TCon _ _) _ _) = True
57+ injective (P _ n _) = n `elem` injtc
53 injective (App f a) = injective f
58 injective (App f a) = injective f
54 injective _ = False
59 injective _ = False
55
60
56 notP (P _ _ _) = False
61 notP (P _ _ _) = False
57 notP _ = True
62 notP _ = True
58
63
59− sc i = do UI s x f <- get
64+ sc i = do UI s f <- get
60− put (UI (s+i) x f)
65+ put (UI (s+i) f)
61
66
62− uplus u1 u2 = do UI s i f <- get
67+ uplus u1 u2 = do UI s f <- get
63 r <- u1
68 r <- u1
64− UI s _ f' <- get
69+ UI s f' <- get
65 if (length f == length f')
70 if (length f == length f')
66 then return r
71 then return r
67− else do put (UI s i f); u2
72+ else do put (UI s f); u2
68
73
69 un :: Bool -> [(Name, Name)] -> TT Name -> TT Name ->
74 un :: Bool -> [(Name, Name)] -> TT Name -> TT Name ->
70 StateT UInfo
75 StateT UInfo
@@ -89,34 +94,53 @@ unify ctxt env topx topy =
89 = unifyFail topx topy
94 = unifyFail topx topy
90 un' fn names topx@(P (TCon _ _) x _) topy@(P (DCon _ _) y _)
95 un' fn names topx@(P (TCon _ _) x _) topy@(P (DCon _ _) y _)
91 = unifyFail topx topy
96 = unifyFail topx topy
92− un' fn bnames (P Bound x _) (P Bound y _)
97+ un' fn bnames tx@(P _ x _) ty@(P _ y _)
93− | (x,y) `elem` bnames = do sc 1; return []
98+ | (x,y) `elem` bnames || x == y = do sc 1; return []
94− un' fn bnames (P Bound x _) tm
99+ | injective tx && not (holeIn env y || y `elem` holes)
95− | holeIn env x = do UI s i f <- get
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
96 -- injectivity check
106 -- injectivity check
97− when (notP tm && fn) $
107+ if (notP tm && fn)
98-- trace (show (x, tm, normalise ctxt env tm)) $
108-- trace (show (x, tm, normalise ctxt env tm)) $
99− put (UI s ((tm, topx, topy) : i) f)
109+-- put (UI s ((tm, topx, topy) : i) f)
100− sc 1
110+ then unifyTmpFail xtm tm
101− checkCycle (x, tm)
111+ else do sc 1
102− un' fn bnames tm (P Bound y _)
112+ checkCycle (x, tm)
103− | holeIn env y = do UI s i f <- get
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
104 -- injectivity check
117 -- injectivity check
105− when (notP tm && fn) $
118+ if (notP tm && fn)
106-- trace (show (y, tm, normalise ctxt env tm)) $
119-- trace (show (y, tm, normalise ctxt env tm)) $
107− put (UI s ((tm, topx, topy) : i) f)
120+-- put (UI s ((tm, topx, topy) : i) f)
108− sc 1
121+ then unifyTmpFail tm ytm
109− checkCycle (y, tm)
122+ else do sc 1
110− un' fn bnames (V i) (P Bound x _)
123+ checkCycle (y, tm)
124+ | not (injective ytm) && injective tm = unifyFail ytm tm
125+ un' fn bnames (V i) (P _ x _)
111 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
126 | 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)
113 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
128 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
114
129
115− un' fn bnames appx@(App fx ax) appy@(App fy ay)
130+ un' fn bnames appx@(App fx ax) appy@(App fy ay)
116− = do let (headx, _) = unApply fx
131+ | injective fx && metavarApp appy
117− let (heady, _) = unApply fy
132+ || injective fy && metavarApp appx
118− checkHeads headx heady
133+ || injective fx && injective fy
119− uplus -- do the second one if the first adds any errors
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
120 (do hf <- un' True bnames fx fy
144 (do hf <- un' True bnames fx fy
121 let ax' = hnormalise hf ctxt env (substNames hf ax)
145 let ax' = hnormalise hf ctxt env (substNames hf ax)
122 let ay' = hnormalise hf ctxt env (substNames hf ay)
146 let ay' = hnormalise hf ctxt env (substNames hf ay)
@@ -129,8 +153,17 @@ unify ctxt env topx topy =
129 hf <- un' False bnames fx' fy'
153 hf <- un' False bnames fx' fy'
130 sc 1
154 sc 1
131 combine bnames hf ha)
155 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
132 where hnormalise [] _ _ t = t
165 where hnormalise [] _ _ t = t
133− hnormalise ns ctxt env t = normalise ctxt env t
166+ hnormalise ns ctxt env t = hnf ctxt env t
134 checkHeads (P (DCon _ _) x _) (P (DCon _ _) y _)
167 checkHeads (P (DCon _ _) x _) (P (DCon _ _) y _)
135 | x /= y = unifyFail appx appy
168 | x /= y = unifyFail appx appy
136 checkHeads (P (TCon _ _) x _) (P (TCon _ _) y _)
169 checkHeads (P (TCon _ _) x _) (P (TCon _ _) y _)
@@ -141,6 +174,25 @@ unify ctxt env topx topy =
141 = unifyFail appx appy
174 = unifyFail appx appy
142 checkHeads _ _ = return []
175 checkHeads _ _ = return []
143
176
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+
144 un' fn bnames x (Bind n (Lam t) (App y (P Bound n' _)))
196 un' fn bnames x (Bind n (Lam t) (App y (P Bound n' _)))
145 | n == n' = un' False bnames x y
197 | n == n' = un' False bnames x y
146 un' fn bnames (Bind n (Lam t) (App x (P Bound n' _))) y
198 un' fn bnames (Bind n (Lam t) (App x (P Bound n' _))) y
@@ -155,20 +207,28 @@ unify ctxt env topx topy =
155 combine bnames h1 h2
207 combine bnames h1 h2
156 un' fn bnames x y
208 un' fn bnames x y
157 | OK True <- convEq' ctxt x y = do sc 1; return []
209 | 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
159 let r = recoverable x y
211 let r = recoverable x y
160 let err = CantUnify r
212 let err = CantUnify r
161 topx topy (CantUnify r x y (Msg "") [] s) (errEnv env) s
213 topx topy (CantUnify r x y (Msg "") [] s) (errEnv env) s
162 if (not r) then lift $ tfail err
214 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))
164 return [] -- lift $ tfail err
216 return [] -- lift $ tfail err
165
217
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+
166 -- shortcut failure, if we *know* nothing can fix it
226 -- 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
168 let r = recoverable x y
228 let r = recoverable x y
169 let err = CantUnify r
229 let err = CantUnify r
170 topx topy (CantUnify r x y (Msg "") [] s) (errEnv env) s
230 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))
172 lift $ tfail err
232 lift $ tfail err
173
233
174
234
@@ -186,12 +246,12 @@ unify ctxt env topx topy =
186 uB bnames (Pi tx) (Pi ty) = do sc 1; un' False bnames tx ty
246 uB bnames (Pi tx) (Pi ty) = do sc 1; un' False bnames tx ty
187 uB bnames (Hole tx) (Hole ty) = un' False bnames tx ty
247 uB bnames (Hole tx) (Hole ty) = un' False bnames tx ty
188 uB bnames (PVar tx) (PVar ty) = un' False bnames tx ty
248 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
190 let r = recoverable (binderTy x) (binderTy y)
250 let r = recoverable (binderTy x) (binderTy y)
191 let err = CantUnify r topx topy
251 let err = CantUnify r topx topy
192 (CantUnify r (binderTy x) (binderTy y) (Msg "") [] s)
252 (CantUnify r (binderTy x) (binderTy y) (Msg "") [] s)
193 (errEnv env) s
253 (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))
195 return [] -- lift $ tfail err
255 return [] -- lift $ tfail err
196
256
197 checkCycle p@(x, P _ _ _) = return [p]
257 checkCycle p@(x, P _ _ _) = return [p]
@@ -199,6 +259,11 @@ unify ctxt env topx topy =
199 | not (x `elem` freeNames tm) = return [(x, tm)]
259 | not (x `elem` freeNames tm) = return [(x, tm)]
200 | otherwise = lift $ tfail (InfiniteUnify x tm (errEnv env))
260 | otherwise = lift $ tfail (InfiniteUnify x tm (errEnv env))
201
261
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+
202 combine bnames as [] = return as
267 combine bnames as [] = return as
203 combine bnames as ((n, t) : bs)
268 combine bnames as ((n, t) : bs)
204 = case lookup n as of
269 = case lookup n as of
src/IRTS/CodegenJavaScript.hs+169−181
@@ -1,10 +1,5 @@
1{-# LANGUAGE PatternGuards #-}
1{-# LANGUAGE PatternGuards #-}
2
2
3−{-
4− BigInteger Javascript code taken from:
5− https://github.com/peterolson/BigInteger.js
6−-}
7−
8module IRTS.CodegenJavaScript (codegenJavaScript) where
3module IRTS.CodegenJavaScript (codegenJavaScript) where
9
4
10import Idris.AbsSyntax
5import Idris.AbsSyntax
@@ -19,11 +14,10 @@ import Util.System
19import Control.Arrow
14import Control.Arrow
20import Data.Char
15import Data.Char
21import Data.List
16import Data.List
17+import qualified Data.Map as Map
22import System.IO
18import System.IO
23
19
24−type NamespaceName = String
20+idrNamespace :: String
25−
26−idrNamespace :: NamespaceName
27idrNamespace = "__IDR__"
21idrNamespace = "__IDR__"
28
22
29codegenJavaScript
23codegenJavaScript
@@ -31,10 +25,14 @@ codegenJavaScript
31 -> FilePath
25 -> FilePath
32 -> OutputType
26 -> OutputType
33 -> IO ()
27 -> IO ()
34−codegenJavaScript definitions filename outputType =
28+codegenJavaScript definitions filename outputType = do
35− writeFile filename output
29+ path <- getDataDir
30+ idrRuntime <- readFile (path ++ "/js/Runtime.js")
31+ writeFile filename (idrRuntime ++ modules ++ functions ++ mainLoop)
36 where
32 where
37 def = map (first translateNamespace) definitions
33 def = map (first translateNamespace) definitions
34+
35+ functions = concatMap translateDeclaration def
38
36
39 mainLoop :: String
37 mainLoop :: String
40 mainLoop = intercalate "\n" [ "\nfunction main() {"
38 mainLoop = intercalate "\n" [ "\nfunction main() {"
@@ -42,115 +40,72 @@ codegenJavaScript definitions filename outputType =
42 , "}\n\nmain();\n"
40 , "}\n\nmain();\n"
43 ]
41 ]
44
42
45− output :: String
43+ modules =
46− output = concat [ idrRuntime
44+ concatMap allocMod mods
47− , concatMap (translateModule Nothing) def
45+ where
48− , mainLoop
46+ allocMod m = intercalate "." m ++ " = {};\n"
49− ]
47+ sortMods a b = compare (length a) (length b)
50−
48+
51−idrRuntime :: String
49+ mods =
52−idrRuntime =
50+ drop 1 $ sortBy sortMods $ nub $ concatMap (inits . fst) def
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)
118
51
119translateIdentifier :: String -> String
52translateIdentifier :: String -> String
120translateIdentifier =
53translateIdentifier =
121− concatMap replaceBadChars
54+ replaceReserved . concatMap replaceBadChars
122 where replaceBadChars :: Char -> String
55 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"
151 replaceBadChars c
56 replaceBadChars c
57+ | ' ' <- c = "_"
58+ | '_' <- c = "__"
152 | isDigit c = "_" ++ [c] ++ "_"
59 | isDigit c = "_" ++ [c] ++ "_"
60+ | not (isLetter c && isAscii c) = '_' : show (ord c)
153 | otherwise = [c]
61 | 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+ ]
154
109
155translateNamespace :: Name -> [String]
110translateNamespace :: Name -> [String]
156translateNamespace (UN _) = [idrNamespace]
111translateNamespace (UN _) = [idrNamespace]
@@ -162,42 +117,36 @@ translateName (UN name) = translateIdentifier name
162translateName (NS name _) = translateName name
117translateName (NS name _) = translateName name
163translateName (MN i name) = translateIdentifier name ++ show i
118translateName (MN i name) = translateIdentifier name ++ show i
164
119
165−translateQualifiedName :: Name -> String
166−translateQualifiedName name =
167− intercalate "." (translateNamespace name) ++ "." ++ translateName name
168−
169translateConstant :: Const -> String
120translateConstant :: Const -> String
170translateConstant (I i) = show i
121translateConstant (I i) = show i
171−translateConstant (BI i) = "__IDR__.bigInt('" ++ show i ++ "')"
122+translateConstant (BI i) = "__IDRRT__.bigInt('" ++ show i ++ "')"
172translateConstant (Fl f) = show f
123translateConstant (Fl f) = show f
173translateConstant (Ch c) = show c
124translateConstant (Ch c) = show c
174translateConstant (Str s) = show s
125translateConstant (Str s) = show s
175−translateConstant IType = "__IDR__.Int"
126+translateConstant IType = "__IDRRT__.Int"
176−translateConstant ChType = "__IDR__.Char"
127+translateConstant ChType = "__IDRRT__.Char"
177−translateConstant StrType = "__IDR__.String"
128+translateConstant StrType = "__IDRRT__.String"
178−translateConstant BIType = "__IDR__.Integer"
129+translateConstant BIType = "__IDRRT__.Integer"
179−translateConstant FlType = "__IDR__.Float"
130+translateConstant FlType = "__IDRRT__.Float"
180−translateConstant Forgot = "__IDR__.Forgot"
131+translateConstant Forgot = "__IDRRT__.Forgot"
181translateConstant c =
132translateConstant c =
182 "(function(){throw 'Unimplemented Const: " ++ show c ++ "';})()"
133 "(function(){throw 'Unimplemented Const: " ++ show c ++ "';})()"
183
134
184translateParameterlist =
135translateParameterlist =
185 map translateParameter
136 map translateParameter
186− where translateParameter (MN i name) = name ++ show i
137+ where translateParameter (MN i name) = translateIdentifier name ++ show i
187− translateParameter (UN name) = name
138+ translateParameter (UN name) = translateIdentifier name
188
139
189−translateDeclaration :: NamespaceName -> SDecl -> String
140+translateDeclaration :: ([String], SDecl) -> String
190−translateDeclaration modname (SFun name params stackSize body) =
141+translateDeclaration (path, SFun name params stackSize body) =
191− modname
142+ intercalate "." (path ++ [translateName name])
192− ++ "."
193− ++ translateName name
194 ++ " = function("
143 ++ " = function("
195 ++ intercalate "," p
144 ++ intercalate "," p
196 ++ "){\n"
145 ++ "){\n"
197 ++ concatMap assignVar (zip [0..] p)
146 ++ concatMap assignVar (zip [0..] p)
198 ++ concatMap allocVar [numP..(numP+stackSize-1)]
147 ++ concatMap allocVar [numP..(numP+stackSize-1)]
199 ++ "return "
148 ++ "return "
200− ++ translateExpression modname body
149+ ++ translateExpression body
201 ++ ";\n};\n"
150 ++ ";\n};\n"
202 where
151 where
203 numP :: Int
152 numP :: Int
@@ -216,32 +165,32 @@ translateVariableName :: LVar -> String
216translateVariableName (Loc i) =
165translateVariableName (Loc i) =
217 "__var_" ++ show i
166 "__var_" ++ show i
218
167
219−translateExpression :: NamespaceName -> SExp -> String
168+translateExpression :: SExp -> String
220−translateExpression modname (SLet name value body) =
169+translateExpression (SLet name value body) =
221 "(function("
170 "(function("
222 ++ translateVariableName name
171 ++ translateVariableName name
223 ++ "){\nreturn "
172 ++ "){\nreturn "
224− ++ translateExpression modname body
173+ ++ translateExpression body
225 ++ ";\n})("
174 ++ ";\n})("
226− ++ translateExpression modname value
175+ ++ translateExpression value
227 ++ ")"
176 ++ ")"
228
177
229−translateExpression _ (SConst cst) =
178+translateExpression (SConst cst) =
230 translateConstant cst
179 translateConstant cst
231
180
232−translateExpression _ (SV var) =
181+translateExpression (SV var) =
233 translateVariableName var
182 translateVariableName var
234
183
235−translateExpression modname (SApp False name vars) =
184+translateExpression (SApp False name vars) =
236 createTailcall $ translateFunctionCall name vars
185 createTailcall $ translateFunctionCall name vars
237
186
238−translateExpression modname (SApp True name vars) =
187+translateExpression (SApp True name vars) =
239− "new __IDR__.Tailcall("
188+ "new __IDRRT__.Tailcall("
240 ++ "function(){\n"
189 ++ "function(){\n"
241 ++ "return " ++ translateFunctionCall name vars
190 ++ "return " ++ translateFunctionCall name vars
242 ++ ";\n});"
191 ++ ";\n});"
243
192
244−translateExpression _ (SOp op vars)
193+translateExpression (SOp op vars)
245 | LPlus <- op
194 | LPlus <- op
246 , (lhs:rhs:_) <- vars = translateBinaryOp "+" lhs rhs
195 , (lhs:rhs:_) <- vars = translateBinaryOp "+" lhs rhs
247 | LMinus <- op
196 | LMinus <- op
@@ -329,13 +278,13 @@ translateExpression _ (SOp op vars)
329 | LIntStr <- op
278 | LIntStr <- op
330 , (arg:_) <- vars = "String(" ++ translateVariableName arg ++ ")"
279 , (arg:_) <- vars = "String(" ++ translateVariableName arg ++ ")"
331 | LIntBig <- op
280 | LIntBig <- op
332− , (arg:_) <- vars = "__IDR__.bigint(" ++ translateVariableName arg ++ ")"
281+ , (arg:_) <- vars = "__IDRRT__.bigInt(" ++ translateVariableName arg ++ ")"
333 | LBigInt <- op
282 | LBigInt <- op
334 , (arg:_) <- vars = translateVariableName arg ++ ".valueOf()"
283 , (arg:_) <- vars = translateVariableName arg ++ ".valueOf()"
335 | LBigStr <- op
284 | LBigStr <- op
336 , (arg:_) <- vars = translateVariableName arg ++ ".toString()"
285 , (arg:_) <- vars = translateVariableName arg ++ ".toString()"
337 | LStrBig <- op
286 | LStrBig <- op
338− , (arg:_) <- vars = "__IDR__.bigint(" ++ translateVariableName arg ++ ")"
287+ , (arg:_) <- vars = "__IDRRT__.bigInt(" ++ translateVariableName arg ++ ")"
339 | LFloatStr <- op
288 | LFloatStr <- op
340 , (arg:_) <- vars = "String(" ++ translateVariableName arg ++ ")"
289 , (arg:_) <- vars = "String(" ++ translateVariableName arg ++ ")"
341 | LStrFloat <- op
290 | LStrFloat <- op
@@ -394,78 +343,117 @@ translateExpression _ (SOp op vars)
394 ++ f
343 ++ f
395 ++ translateVariableName rhs
344 ++ translateVariableName rhs
396
345
397−translateExpression _ (SError msg) =
346+translateExpression (SError msg) =
398 "(function(){throw \'" ++ msg ++ "\';})();"
347 "(function(){throw \'" ++ msg ++ "\';})();"
399
348
400−translateExpression _ (SForeign _ _ "putStr" [(FString, var)]) =
349+translateExpression (SForeign _ _ "putStr" [(FString, var)]) =
401− "__IDR__.print(" ++ translateVariableName var ++ ");"
350+ "__IDRRT__.print(" ++ translateVariableName var ++ ");"
402
351
403−translateExpression _ (SForeign _ _ fun args) =
352+translateExpression (SForeign _ _ fun args)
404− fun
353+ | "." `isPrefixOf` fun, "[]=" `isSuffixOf` fun
405− ++ "("
354+ , (obj:idx:val:[]) <- args =
406− ++ intercalate "," (map (translateVariableName . snd) args)
355+ concat [object obj, field, index idx, assign val]
407− ++ ");"
408
356
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) =
410 "(function(e){\n"
398 "(function(e){\n"
411− ++ intercalate " else " (map (translateCase modname "e") cases)
399+ ++ intercalate " else " (map (translateCase "e") cases)
412 ++ "\n})("
400 ++ "\n})("
413 ++ translateVariableName var
401 ++ translateVariableName var
414 ++ ")"
402 ++ ")"
415
403
416−translateExpression modname (SCase var cases) =
404+translateExpression (SCase var cases) =
417 "(function(e){\n"
405 "(function(e){\n"
418− ++ intercalate " else " (map (translateCase modname "e") cases)
406+ ++ intercalate " else " (map (translateCase "e") cases)
419 ++ "\n})("
407 ++ "\n})("
420 ++ translateVariableName var
408 ++ translateVariableName var
421 ++ ")"
409 ++ ")"
422
410
423−translateExpression _ (SCon i name vars) =
411+translateExpression (SCon i name vars) =
424− concat [ "new __IDR__.Con("
412+ concat [ "new __IDRRT__.Con("
425 , show i
413 , show i
426− , ","
414+ , ",["
427− , '\'' : translateQualifiedName name ++ "\',["
428 , intercalate "," $ map translateVariableName vars
415 , intercalate "," $ map translateVariableName vars
429 , "])"
416 , "])"
430 ]
417 ]
431
418
432−translateExpression modname (SUpdate var e) =
419+translateExpression (SUpdate var e) =
433− translateVariableName var ++ " = " ++ translateExpression modname e
420+ translateVariableName var ++ " = " ++ translateExpression e
434
421
435−translateExpression modname (SProj var i) =
422+translateExpression (SProj var i) =
436 translateVariableName var ++ ".vars[" ++ show i ++"]"
423 translateVariableName var ++ ".vars[" ++ show i ++"]"
437
424
438−translateExpression _ SNothing = "null"
425+translateExpression SNothing = "null"
439
426
440−translateExpression _ e =
427+translateExpression e =
441 "(function(){throw 'Not yet implemented: "
428 "(function(){throw 'Not yet implemented: "
442 ++ filter (/= '\'') (show e)
429 ++ filter (/= '\'') (show e)
443 ++ "';})()"
430 ++ "';})()"
444
431
445−translateCase :: String -> String -> SAlt -> String
432+translateCase :: String -> SAlt -> String
446−translateCase modname _ (SDefaultCase e) =
433+translateCase _ (SDefaultCase e) =
447− createIfBlock "true" (translateExpression modname e)
434+ createIfBlock "true" (translateExpression e)
448
435
449−translateCase modname var (SConstCase ty e)
436+translateCase var (SConstCase ty e)
450 | ChType <- ty = matchHelper "Char"
437 | ChType <- ty = matchHelper "Char"
451 | StrType <- ty = matchHelper "String"
438 | StrType <- ty = matchHelper "String"
452 | IType <- ty = matchHelper "Int"
439 | IType <- ty = matchHelper "Int"
453 | BIType <- ty = matchHelper "Integer"
440 | BIType <- ty = matchHelper "Integer"
454 | FlType <- ty = matchHelper "Float"
441 | FlType <- ty = matchHelper "Float"
442+ | PtrType <- ty = matchHelper "Pointer"
455 | Forgot <- ty = matchHelper "Forgot"
443 | Forgot <- ty = matchHelper "Forgot"
456 where
444 where
457− matchHelper tyName = translateTypeMatch modname var tyName e
445+ matchHelper tyName = translateTypeMatch var tyName e
458
446
459−translateCase modname var (SConstCase cst@(BI _) e) =
447+translateCase var (SConstCase cst@(BI _) e) =
460 let cond = var ++ ".equals(" ++ translateConstant cst ++ ")" in
448 let cond = var ++ ".equals(" ++ translateConstant cst ++ ")" in
461− createIfBlock cond (translateExpression modname e)
449+ createIfBlock cond (translateExpression e)
462
450
463−translateCase modname var (SConstCase cst e) =
451+translateCase var (SConstCase cst e) =
464 let cond = var ++ " == " ++ translateConstant cst in
452 let cond = var ++ " == " ++ translateConstant cst in
465− createIfBlock cond (translateExpression modname e)
453+ createIfBlock cond (translateExpression e)
466
454
467−translateCase modname var (SConCase a i name vars e) =
455+translateCase var (SConCase a i name vars e) =
468− let isCon = var ++ " instanceof __IDR__.Con"
456+ let isCon = var ++ " instanceof __IDRRT__.Con"
469 isI = show i ++ " == " ++ var ++ ".i"
457 isI = show i ++ " == " ++ var ++ ".i"
470 params = intercalate "," $ map (("__var_" ++) . show) [a..(a+length vars)]
458 params = intercalate "," $ map (("__var_" ++) . show) [a..(a+length vars)]
471 args = ".apply(this," ++ var ++ ".vars)"
459 args = ".apply(this," ++ var ++ ".vars)"
@@ -474,13 +462,13 @@ translateCase modname var (SConCase a i name vars e) =
474 ++ params
462 ++ params
475 ++ "){\nreturn " ++ b ++ "\n})" ++ args
463 ++ "){\nreturn " ++ b ++ "\n})" ++ args
476 cond = intercalate " && " [isCon, isI] in
464 cond = intercalate " && " [isCon, isI] in
477− createIfBlock cond $ f (translateExpression modname e)
465+ createIfBlock cond $ f (translateExpression e)
478
466
479−translateTypeMatch :: String -> String -> String -> SExp -> String
467+translateTypeMatch :: String -> String -> SExp -> String
480−translateTypeMatch modname var ty exp =
468+translateTypeMatch var ty exp =
481− let e = translateExpression modname exp in
469+ let e = translateExpression exp in
482 createIfBlock (var
470 createIfBlock (var
483− ++ " instanceof __IDR__.Type && "
471+ ++ " instanceof __IDRRT__.Type && "
484 ++ var ++ ".type == '"++ ty ++"'") e
472 ++ var ++ ".type == '"++ ty ++"'") e
485
473
486
474
@@ -490,7 +478,7 @@ createIfBlock cond e =
490 ++ ";\n}"
478 ++ ";\n}"
491
479
492createTailcall call =
480createTailcall call =
493− "__IDR__.tailcall(function(){return " ++ call ++ "})"
481+ "__IDRRT__.tailcall(function(){return " ++ call ++ "})"
494
482
495translateFunctionCall name vars =
483translateFunctionCall name vars =
496 concat (intersperse "." $ translateNamespace name)
484 concat (intersperse "." $ translateNamespace name)
src/IRTS/Compiler.hs+3−3
@@ -73,7 +73,7 @@ compile target f tm
73 Bytecode -> liftIO $ dumpBC c f
73 Bytecode -> liftIO $ dumpBC c f
74 ToJavaScript -> liftIO $ codegenJavaScript c f outty
74 ToJavaScript -> liftIO $ codegenJavaScript c f outty
75 Error e -> fail $ show e
75 Error e -> fail $ show e
76− where checkMVs = do i <- get
76+ where checkMVs = do i <- getIState
77 case idris_metavars i \\ primDefs of
77 case idris_metavars i \\ primDefs of
78 [] -> return ()
78 [] -> return ()
79 ms -> fail $ "There are undefined metavariables: " ++ show ms
79 ms -> fail $ "There are undefined metavariables: " ++ show ms
@@ -91,7 +91,7 @@ irMain tm = do i <- ir tm
91
91
92allNames :: [Name] -> Name -> Idris [Name]
92allNames :: [Name] -> Name -> Idris [Name]
93allNames ns n | n `elem` ns = return []
93allNames ns n | n `elem` ns = return []
94−allNames ns n = do i <- get
94+allNames ns n = do i <- getIState
95 case lookupCtxt Nothing n (idris_callgraph i) of
95 case lookupCtxt Nothing n (idris_callgraph i) of
96 [ns'] -> do more <- mapM (allNames (n:ns)) (map fst (calls ns'))
96 [ns'] -> do more <- mapM (allNames (n:ns)) (map fst (calls ns'))
97 return (nub (n : concat more))
97 return (nub (n : concat more))
@@ -193,7 +193,7 @@ instance ToIR (TT Name) where
193 | (P (DCon t a) n _, args) <- unApply tm
193 | (P (DCon t a) n _, args) <- unApply tm
194 = irCon env t a n args
194 = irCon env t a n args
195 | (P _ n _, args) <- unApply tm
195 | (P _ n _, args) <- unApply tm
196− = do i <- get
196+ = do i <- getIState
197 args' <- mapM (ir' env) args
197 args' <- mapM (ir' env) args
198 case getPrim i n args' of
198 case getPrim i n args' of
199 Just tm -> return tm
199 Just tm -> return tm
src/Idris/AbsSyntax.hs+92−92
@@ -26,57 +26,57 @@ import Util.Pretty
26
26
27
27
28getContext :: Idris Context
28getContext :: Idris Context
29−getContext = do i <- get; return (tt_ctxt i)
29+getContext = do i <- getIState; return (tt_ctxt i)
30
30
31getObjectFiles :: Idris [FilePath]
31getObjectFiles :: Idris [FilePath]
32−getObjectFiles = do i <- get; return (idris_objs i)
32+getObjectFiles = do i <- getIState; return (idris_objs i)
33
33
34addObjectFile :: FilePath -> Idris ()
34addObjectFile :: 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 }
36
36
37getLibs :: Idris [String]
37getLibs :: Idris [String]
38−getLibs = do i <- get; return (idris_libs i)
38+getLibs = do i <- getIState; return (idris_libs i)
39
39
40addLib :: String -> Idris ()
40addLib :: 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 }
42
42
43addHdr :: String -> Idris ()
43addHdr :: 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 }
45
45
46totcheck :: (FC, Name) -> Idris ()
46totcheck :: (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] }
48
48
49setFlags :: Name -> [FnOpt] -> Idris ()
49setFlags :: 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) }
51
51
52setAccessibility :: Name -> Accessibility -> Idris ()
52setAccessibility :: Name -> Accessibility -> Idris ()
53setAccessibility n a
53setAccessibility n a
54− = do i <- get
54+ = do i <- getIState
55 let ctxt = setAccess n a (tt_ctxt i)
55 let ctxt = setAccess n a (tt_ctxt i)
56− put (i { tt_ctxt = ctxt })
56+ putIState $ i { tt_ctxt = ctxt }
57
57
58setTotality :: Name -> Totality -> Idris ()
58setTotality :: Name -> Totality -> Idris ()
59setTotality n a
59setTotality n a
60− = do i <- get
60+ = do i <- getIState
61 let ctxt = setTotal n a (tt_ctxt i)
61 let ctxt = setTotal n a (tt_ctxt i)
62− put (i { tt_ctxt = ctxt })
62+ putIState $ i { tt_ctxt = ctxt }
63
63
64getTotality :: Name -> Idris Totality
64getTotality :: Name -> Idris Totality
65getTotality n
65getTotality n
66− = do i <- get
66+ = do i <- getIState
67 case lookupTotal n (tt_ctxt i) of
67 case lookupTotal n (tt_ctxt i) of
68 [t] -> return t
68 [t] -> return t
69 _ -> return (Total [])
69 _ -> return (Total [])
70
70
71addToCG :: Name -> CGInfo -> Idris ()
71addToCG :: Name -> CGInfo -> Idris ()
72addToCG n cg
72addToCG n cg
73− = do i <- get
73+ = do i <- getIState
74− put (i { idris_callgraph = addDef n cg (idris_callgraph i) })
74+ putIState $ i { idris_callgraph = addDef n cg (idris_callgraph i) }
75
75
76addDocStr :: Name -> String -> Idris ()
76addDocStr :: Name -> String -> Idris ()
77addDocStr n doc
77addDocStr n doc
78− = do i <- get
78+ = do i <- getIState
79− put (i { idris_docstrings = addDef n doc (idris_docstrings i) })
79+ putIState $ i { idris_docstrings = addDef n doc (idris_docstrings i) }
80
80
81addToCalledG :: Name -> [Name] -> Idris ()
81addToCalledG :: Name -> [Name] -> Idris ()
82addToCalledG n ns = return () -- TODO
82addToCalledG n ns = return () -- TODO
@@ -87,13 +87,13 @@ addToCalledG n ns = return () -- TODO
87
87
88addInstance :: Bool -> Name -> Name -> Idris ()
88addInstance :: Bool -> Name -> Name -> Idris ()
89addInstance int n i
89addInstance int n i
90− = do ist <- get
90+ = do ist <- getIState
91 case lookupCtxt Nothing n (idris_classes ist) of
91 case lookupCtxt Nothing n (idris_classes ist) of
92 [CI a b c d ins] ->
92 [CI a b c d ins] ->
93 do let cs = addDef n (CI a b c d (addI i ins)) (idris_classes ist)
93 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 }
95 _ -> do let cs = addDef n (CI (MN 0 "none") [] [] [] [i]) (idris_classes ist)
95 _ -> 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 }
97 where addI i ins | int = i : ins
97 where addI i ins | int = i : ins
98 | chaser n = ins ++ [i]
98 | chaser n = ins ++ [i]
99 | otherwise = insI i ins
99 | otherwise = insI i ins
@@ -107,45 +107,45 @@ addInstance int n i
107
107
108addClass :: Name -> ClassInfo -> Idris ()
108addClass :: Name -> ClassInfo -> Idris ()
109addClass n i
109addClass n i
110− = do ist <- get
110+ = do ist <- getIState
111 let i' = case lookupCtxt Nothing n (idris_classes ist) of
111 let i' = case lookupCtxt Nothing n (idris_classes ist) of
112 [c] -> c { class_instances = class_instances i }
112 [c] -> c { class_instances = class_instances i }
113 _ -> i
113 _ -> i
114− put (ist { idris_classes = addDef n i' (idris_classes ist) })
114+ putIState $ ist { idris_classes = addDef n i' (idris_classes ist) }
115
115
116addIBC :: IBCWrite -> Idris ()
116addIBC :: IBCWrite -> Idris ()
117addIBC ibc@(IBCDef n)
117addIBC ibc@(IBCDef n)
118− = do i <- get
118+ = do i <- getIState
119 when (notDef (ibc_write i)) $
119 when (notDef (ibc_write i)) $
120− put (i { ibc_write = ibc : ibc_write i })
120+ putIState $ i { ibc_write = ibc : ibc_write i }
121 where notDef [] = True
121 where notDef [] = True
122 notDef (IBCDef n': is) | n == n' = False
122 notDef (IBCDef n': is) | n == n' = False
123 notDef (_ : is) = notDef is
123 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 }
125
125
126clearIBC :: Idris ()
126clearIBC :: Idris ()
127−clearIBC = do i <- get; put (i { ibc_write = [] })
127+clearIBC = do i <- getIState; putIState $ i { ibc_write = [] }
128
128
129getHdrs :: Idris [String]
129getHdrs :: Idris [String]
130−getHdrs = do i <- get; return (idris_hdrs i)
130+getHdrs = do i <- getIState; return (idris_hdrs i)
131
131
132setErrLine :: Int -> Idris ()
132setErrLine :: Int -> Idris ()
133−setErrLine x = do i <- get;
133+setErrLine x = do i <- getIState;
134 case (errLine i) of
134 case (errLine i) of
135− Nothing -> put (i { errLine = Just x })
135+ Nothing -> putIState $ i { errLine = Just x }
136 Just _ -> return ()
136 Just _ -> return ()
137
137
138clearErr :: Idris ()
138clearErr :: Idris ()
139−clearErr = do i <- get
139+clearErr = do i <- getIState
140− put (i { errLine = Nothing })
140+ putIState $ i { errLine = Nothing }
141
141
142getSO :: Idris (Maybe String)
142getSO :: Idris (Maybe String)
143−getSO = do i <- get
143+getSO = do i <- getIState
144 return (compiled_so i)
144 return (compiled_so i)
145
145
146setSO :: Maybe String -> Idris ()
146setSO :: Maybe String -> Idris ()
147−setSO s = do i <- get
147+setSO s = do i <- getIState
148− put (i { compiled_so = s })
148+ putIState $ (i { compiled_so = s })
149
149
150getIState :: Idris IState
150getIState :: Idris IState
151getIState = get
151getIState = get
@@ -154,9 +154,9 @@ putIState :: IState -> Idris ()
154putIState = put
154putIState = put
155
155
156getName :: Idris Int
156getName :: Idris Int
157−getName = do i <- get;
157+getName = do i <- getIState;
158 let idx = idris_name i;
158 let idx = idris_name i;
159− put (i { idris_name = idx + 1 })
159+ putIState $ (i { idris_name = idx + 1 })
160 return idx
160 return idx
161
161
162checkUndefined :: FC -> Name -> Idris ()
162checkUndefined :: FC -> Name -> Idris ()
@@ -175,24 +175,24 @@ isUndefined fc n
175 _ -> return True
175 _ -> return True
176
176
177setContext :: Context -> Idris ()
177setContext :: Context -> Idris ()
178−setContext ctxt = do i <- get; put (i { tt_ctxt = ctxt } )
178+setContext ctxt = do i <- getIState; putIState $ (i { tt_ctxt = ctxt } )
179
179
180updateContext :: (Context -> Context) -> Idris ()
180updateContext :: (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) } )
182
182
183addConstraints :: FC -> (Int, [UConstraint]) -> Idris ()
183addConstraints :: FC -> (Int, [UConstraint]) -> Idris ()
184addConstraints fc (v, cs)
184addConstraints fc (v, cs)
185− = do i <- get
185+ = do i <- getIState
186 let ctxt = tt_ctxt i
186 let ctxt = tt_ctxt i
187 let ctxt' = ctxt { uconstraints = cs ++ uconstraints ctxt,
187 let ctxt' = ctxt { uconstraints = cs ++ uconstraints ctxt,
188 next_tvar = v }
188 next_tvar = v }
189 let ics = zip cs (repeat fc) ++ idris_constraints i
189 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 }
191
191
192addDeferred :: [(Name, Type)] -> Idris ()
192addDeferred :: [(Name, Type)] -> Idris ()
193addDeferred ns = do mapM_ (\(n, t) -> updateContext (addTyDecl n (tidyNames [] t))) ns
193addDeferred ns = do mapM_ (\(n, t) -> updateContext (addTyDecl n (tidyNames [] t))) ns
194− i <- get
194+ i <- getIState
195− put (i { idris_metavars = map fst ns ++ idris_metavars i })
195+ putIState $ i { idris_metavars = map fst ns ++ idris_metavars i }
196 where tidyNames used (Bind (MN i x) b sc)
196 where tidyNames used (Bind (MN i x) b sc)
197 = let n' = uniqueName (UN x) used in
197 = let n' = uniqueName (UN x) used in
198 Bind n' b $ tidyNames (n':used) sc
198 Bind n' b $ tidyNames (n':used) sc
@@ -202,8 +202,8 @@ addDeferred ns = do mapM_ (\(n, t) -> updateContext (addTyDecl n (tidyNames [] t
202 tidyNames used b = b
202 tidyNames used b = b
203
203
204solveDeferred :: Name -> Idris ()
204solveDeferred :: Name -> Idris ()
205−solveDeferred n = do i <- get
205+solveDeferred n = do i <- getIState
206− put (i { idris_metavars = idris_metavars i \\ [n] })
206+ putIState $ i { idris_metavars = idris_metavars i \\ [n] }
207
207
208iputStrLn :: String -> Idris ()
208iputStrLn :: String -> Idris ()
209iputStrLn = liftIO . putStrLn
209iputStrLn = liftIO . putStrLn
@@ -212,164 +212,164 @@ iWarn :: FC -> String -> Idris ()
212iWarn fc err = liftIO $ putStrLn (show fc ++ ":" ++ err)
212iWarn fc err = liftIO $ putStrLn (show fc ++ ":" ++ err)
213
213
214setLogLevel :: Int -> Idris ()
214setLogLevel :: Int -> Idris ()
215−setLogLevel l = do i <- get
215+setLogLevel l = do i <- getIState
216 let opts = idris_options i
216 let opts = idris_options i
217 let opt' = opts { opt_logLevel = l }
217 let opt' = opts { opt_logLevel = l }
218− put (i { idris_options = opt' } )
218+ putIState $ i { idris_options = opt' }
219
219
220setCmdLine :: [Opt] -> Idris ()
220setCmdLine :: [Opt] -> Idris ()
221−setCmdLine opts = do i <- get
221+setCmdLine opts = do i <- getIState
222 let iopts = idris_options i
222 let iopts = idris_options i
223− put (i { idris_options = iopts { opt_cmdline = opts } })
223+ putIState $ i { idris_options = iopts { opt_cmdline = opts } }
224
224
225getDumpDefun :: Idris (Maybe FilePath)
225getDumpDefun :: Idris (Maybe FilePath)
226−getDumpDefun = do i <- get
226+getDumpDefun = do i <- getIState
227 return $ findC (opt_cmdline (idris_options i))
227 return $ findC (opt_cmdline (idris_options i))
228 where findC [] = Nothing
228 where findC [] = Nothing
229 findC (DumpDefun x : _) = Just x
229 findC (DumpDefun x : _) = Just x
230 findC (_ : xs) = findC xs
230 findC (_ : xs) = findC xs
231
231
232getDumpCases :: Idris (Maybe FilePath)
232getDumpCases :: Idris (Maybe FilePath)
233−getDumpCases = do i <- get
233+getDumpCases = do i <- getIState
234 return $ findC (opt_cmdline (idris_options i))
234 return $ findC (opt_cmdline (idris_options i))
235 where findC [] = Nothing
235 where findC [] = Nothing
236 findC (DumpCases x : _) = Just x
236 findC (DumpCases x : _) = Just x
237 findC (_ : xs) = findC xs
237 findC (_ : xs) = findC xs
238
238
239logLevel :: Idris Int
239logLevel :: Idris Int
240−logLevel = do i <- get
240+logLevel = do i <- getIState
241 return (opt_logLevel (idris_options i))
241 return (opt_logLevel (idris_options i))
242
242
243setErrContext :: Bool -> Idris ()
243setErrContext :: Bool -> Idris ()
244−setErrContext t = do i <- get
244+setErrContext t = do i <- getIState
245 let opts = idris_options i
245 let opts = idris_options i
246 let opt' = opts { opt_errContext = t }
246 let opt' = opts { opt_errContext = t }
247− put (i { idris_options = opt' })
247+ putIState $ i { idris_options = opt' }
248
248
249errContext :: Idris Bool
249errContext :: Idris Bool
250−errContext = do i <- get
250+errContext = do i <- getIState
251 return (opt_errContext (idris_options i))
251 return (opt_errContext (idris_options i))
252
252
253useREPL :: Idris Bool
253useREPL :: Idris Bool
254−useREPL = do i <- get
254+useREPL = do i <- getIState
255 return (opt_repl (idris_options i))
255 return (opt_repl (idris_options i))
256
256
257setREPL :: Bool -> Idris ()
257setREPL :: Bool -> Idris ()
258−setREPL t = do i <- get
258+setREPL t = do i <- getIState
259 let opts = idris_options i
259 let opts = idris_options i
260 let opt' = opts { opt_repl = t }
260 let opt' = opts { opt_repl = t }
261− put (i { idris_options = opt' })
261+ putIState $ i { idris_options = opt' }
262
262
263setTarget :: Target -> Idris ()
263setTarget :: Target -> Idris ()
264−setTarget t = do i <- get
264+setTarget t = do i <- getIState
265 let opts = idris_options i
265 let opts = idris_options i
266 let opt' = opts { opt_target = t }
266 let opt' = opts { opt_target = t }
267− put (i { idris_options = opt' })
267+ putIState $ i { idris_options = opt' }
268
268
269target :: Idris Target
269target :: Idris Target
270−target = do i <- get
270+target = do i <- getIState
271 return (opt_target (idris_options i))
271 return (opt_target (idris_options i))
272
272
273setOutputTy :: OutputType -> Idris ()
273setOutputTy :: OutputType -> Idris ()
274−setOutputTy t = do i <- get
274+setOutputTy t = do i <- getIState
275 let opts = idris_options i
275 let opts = idris_options i
276 let opt' = opts { opt_outputTy = t }
276 let opt' = opts { opt_outputTy = t }
277− put (i { idris_options = opt' })
277+ putIState $ i { idris_options = opt' }
278
278
279outputTy :: Idris OutputType
279outputTy :: Idris OutputType
280−outputTy = do i <- get
280+outputTy = do i <- getIState
281 return $ opt_outputTy $ idris_options i
281 return $ opt_outputTy $ idris_options i
282
282
283verbose :: Idris Bool
283verbose :: Idris Bool
284−verbose = do i <- get
284+verbose = do i <- getIState
285 return (opt_verbose (idris_options i))
285 return (opt_verbose (idris_options i))
286
286
287setVerbose :: Bool -> Idris ()
287setVerbose :: Bool -> Idris ()
288−setVerbose t = do i <- get
288+setVerbose t = do i <- getIState
289 let opts = idris_options i
289 let opts = idris_options i
290 let opt' = opts { opt_verbose = t }
290 let opt' = opts { opt_verbose = t }
291− put (i { idris_options = opt' })
291+ putIState $ i { idris_options = opt' }
292
292
293typeInType :: Idris Bool
293typeInType :: Idris Bool
294−typeInType = do i <- get
294+typeInType = do i <- getIState
295 return (opt_typeintype (idris_options i))
295 return (opt_typeintype (idris_options i))
296
296
297setTypeInType :: Bool -> Idris ()
297setTypeInType :: Bool -> Idris ()
298−setTypeInType t = do i <- get
298+setTypeInType t = do i <- getIState
299 let opts = idris_options i
299 let opts = idris_options i
300 let opt' = opts { opt_typeintype = t }
300 let opt' = opts { opt_typeintype = t }
301− put (i { idris_options = opt' })
301+ putIState $ i { idris_options = opt' }
302
302
303coverage :: Idris Bool
303coverage :: Idris Bool
304−coverage = do i <- get
304+coverage = do i <- getIState
305 return (opt_coverage (idris_options i))
305 return (opt_coverage (idris_options i))
306
306
307setCoverage :: Bool -> Idris ()
307setCoverage :: Bool -> Idris ()
308−setCoverage t = do i <- get
308+setCoverage t = do i <- getIState
309 let opts = idris_options i
309 let opts = idris_options i
310 let opt' = opts { opt_coverage = t }
310 let opt' = opts { opt_coverage = t }
311− put (i { idris_options = opt' })
311+ putIState $ i { idris_options = opt' }
312
312
313setIBCSubDir :: FilePath -> Idris ()
313setIBCSubDir :: FilePath -> Idris ()
314−setIBCSubDir fp = do i <- get
314+setIBCSubDir fp = do i <- getIState
315 let opts = idris_options i
315 let opts = idris_options i
316 let opt' = opts { opt_ibcsubdir = fp }
316 let opt' = opts { opt_ibcsubdir = fp }
317− put (i { idris_options = opt' })
317+ putIState $ i { idris_options = opt' }
318
318
319valIBCSubDir :: IState -> Idris FilePath
319valIBCSubDir :: IState -> Idris FilePath
320valIBCSubDir i = return (opt_ibcsubdir (idris_options i))
320valIBCSubDir i = return (opt_ibcsubdir (idris_options i))
321
321
322addImportDir :: FilePath -> Idris ()
322addImportDir :: FilePath -> Idris ()
323−addImportDir fp = do i <- get
323+addImportDir fp = do i <- getIState
324 let opts = idris_options i
324 let opts = idris_options i
325 let opt' = opts { opt_importdirs = fp : opt_importdirs opts }
325 let opt' = opts { opt_importdirs = fp : opt_importdirs opts }
326− put (i { idris_options = opt' })
326+ putIState $ i { idris_options = opt' }
327
327
328setImportDirs :: [FilePath] -> Idris ()
328setImportDirs :: [FilePath] -> Idris ()
329−setImportDirs fps = do i <- get
329+setImportDirs fps = do i <- getIState
330 let opts = idris_options i
330 let opts = idris_options i
331 let opt' = opts { opt_importdirs = fps }
331 let opt' = opts { opt_importdirs = fps }
332− put (i { idris_options = opt' })
332+ putIState $ i { idris_options = opt' }
333
333
334allImportDirs :: IState -> Idris [FilePath]
334allImportDirs :: IState -> Idris [FilePath]
335allImportDirs i = do let optdirs = opt_importdirs (idris_options i)
335allImportDirs i = do let optdirs = opt_importdirs (idris_options i)
336 return ("." : optdirs)
336 return ("." : optdirs)
337
337
338impShow :: Idris Bool
338impShow :: Idris Bool
339−impShow = do i <- get
339+impShow = do i <- getIState
340 return (opt_showimp (idris_options i))
340 return (opt_showimp (idris_options i))
341
341
342setImpShow :: Bool -> Idris ()
342setImpShow :: Bool -> Idris ()
343−setImpShow t = do i <- get
343+setImpShow t = do i <- getIState
344 let opts = idris_options i
344 let opts = idris_options i
345 let opt' = opts { opt_showimp = t }
345 let opt' = opts { opt_showimp = t }
346− put (i { idris_options = opt' })
346+ putIState $ i { idris_options = opt' }
347
347
348logLvl :: Int -> String -> Idris ()
348logLvl :: Int -> String -> Idris ()
349−logLvl l str = do i <- get
349+logLvl l str = do i <- getIState
350 let lvl = opt_logLevel (idris_options i)
350 let lvl = opt_logLevel (idris_options i)
351 when (lvl >= l)
351 when (lvl >= l)
352 $ do liftIO (putStrLn str)
352 $ do liftIO (putStrLn str)
353− put (i { idris_log = idris_log i ++ str ++ "\n" } )
353+ putIState $ i { idris_log = idris_log i ++ str ++ "\n" }
354
354
355cmdOptType :: Opt -> Idris Bool
355cmdOptType :: Opt -> Idris Bool
356−cmdOptType x = do i <- get
356+cmdOptType x = do i <- getIState
357 return $ x `elem` opt_cmdline (idris_options i)
357 return $ x `elem` opt_cmdline (idris_options i)
358
358
359iLOG :: String -> Idris ()
359iLOG :: String -> Idris ()
360iLOG = logLvl 1
360iLOG = logLvl 1
361
361
362noErrors :: Idris Bool
362noErrors :: Idris Bool
363−noErrors = do i <- get
363+noErrors = do i <- getIState
364 case errLine i of
364 case errLine i of
365 Nothing -> return True
365 Nothing -> return True
366 _ -> return False
366 _ -> return False
367
367
368setTypeCase :: Bool -> Idris ()
368setTypeCase :: Bool -> Idris ()
369−setTypeCase t = do i <- get
369+setTypeCase t = do i <- getIState
370 let opts = idris_options i
370 let opts = idris_options i
371 let opt' = opts { opt_typecase = t }
371 let opt' = opts { opt_typecase = t }
372− put (i { idris_options = opt' })
372+ putIState $ i { idris_options = opt' }
373
373
374
374
375-- For inferring types of things
375-- For inferring types of things
@@ -634,8 +634,8 @@ addStatics n tm ptm =
634 let statics' = nub $ map fst statics ++
634 let statics' = nub $ map fst statics ++
635 filter (\x -> not (elem x dnames)) stnames
635 filter (\x -> not (elem x dnames)) stnames
636 let stpos = staticList statics' tm
636 let stpos = staticList statics' tm
637− i <- get
637+ i <- getIState
638− put (i { idris_statics = addDef n stpos (idris_statics i) })
638+ putIState $ i { idris_statics = addDef n stpos (idris_statics i) }
639 addIBC (IBCStatic n)
639 addIBC (IBCStatic n)
640 where
640 where
641 initStatics (Bind n (Pi ty) sc) (PPi p _ _ s)
641 initStatics (Bind n (Pi ty) sc) (PPi p _ _ s)
@@ -659,14 +659,14 @@ implicit syn n ptm = implicit' syn [] n ptm
659
659
660implicit' :: SyntaxInfo -> [Name] -> Name -> PTerm -> Idris PTerm
660implicit' :: SyntaxInfo -> [Name] -> Name -> PTerm -> Idris PTerm
661implicit' syn ignore n ptm
661implicit' syn ignore n ptm
662− = do i <- get
662+ = do i <- getIState
663 let (tm', impdata) = implicitise syn ignore i ptm
663 let (tm', impdata) = implicitise syn ignore i ptm
664-- let (tm'', spos) = findStatics i tm'
664-- 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) }
666 addIBC (IBCImp n)
666 addIBC (IBCImp n)
667 logLvl 5 ("Implicit " ++ show n ++ " " ++ show impdata)
667 logLvl 5 ("Implicit " ++ show n ++ " " ++ show impdata)
668-- i <- get
668-- i <- get
669−-- put (i { idris_statics = addDef n spos (idris_statics i) })
669+-- putIState $ i { idris_statics = addDef n spos (idris_statics i) }
670 return tm'
670 return tm'
671
671
672implicitise :: SyntaxInfo -> [Name] -> IState -> PTerm -> (PTerm, [PArg])
672implicitise :: SyntaxInfo -> [Name] -> IState -> PTerm -> (PTerm, [PArg])
src/Idris/AbsSyntaxTree.hs+5−2
@@ -136,7 +136,7 @@ idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
136
136
137-- The monad for the main REPL - reading and processing files and updating
137-- The monad for the main REPL - reading and processing files and updating
138-- global state (hence the IO inner monad).
138-- global state (hence the IO inner monad).
139−type Idris = StateT IState (InputT IO)
139+type Idris = StateT IState IO
140
140
141-- Commands in the REPL
141-- Commands in the REPL
142
142
@@ -524,6 +524,7 @@ type PDo = PDo' PTerm
524-- The priority gives a hint as to elaboration order. Best to elaborate
524-- The priority gives a hint as to elaboration order. Best to elaborate
525-- things early which will help give a more concrete type to other
525-- things early which will help give a more concrete type to other
526-- variables, e.g. a before (interpTy a).
526-- variables, e.g. a before (interpTy a).
527+-- TODO: priority no longer serves any purpose, drop it!
527
528
528data PArg' t = PImp { priority :: Int,
529data PArg' t = PImp { priority :: Int,
529 lazyarg :: Bool, pname :: Name, getTm :: t,
530 lazyarg :: Bool, pname :: Name, getTm :: t,
@@ -579,7 +580,9 @@ deriving instance Binary OptInfo
579!-}
580!-}
580
581
581
582
582−data TypeInfo = TI { con_names :: [Name], codata :: Bool }
583+data TypeInfo = TI { con_names :: [Name],
584+ codata :: Bool,
585+ param_pos :: [Int] }
583 deriving Show
586 deriving Show
584{-!
587{-!
585deriving instance Binary TypeInfo
588deriving 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
33-- covering...)
33-- covering...)
34
34
35mkPatTm :: PTerm -> Idris Term
35mkPatTm :: PTerm -> Idris Term
36−mkPatTm t = do i <- get
36+mkPatTm t = do i <- getIState
37 let timp = addImpl' True [] [] i t
37 let timp = addImpl' True [] [] i t
38 evalStateT (toTT timp) 0
38 evalStateT (toTT timp) 0
39 where
39 where
40− toTT (PRef _ n) = do i <- lift $ get
40+ toTT (PRef _ n) = do i <- lift getIState
41 case lookupDef Nothing n (tt_ctxt i) of
41 case lookupDef Nothing n (tt_ctxt i) of
42 [TyDecl nt _] -> return $ P nt n Erased
42 [TyDecl nt _] -> return $ P nt n Erased
43 _ -> return $ P Ref n Erased
43 _ -> return $ P Ref n Erased
44 toTT (PApp _ t args) = do t' <- toTT t
44 toTT (PApp _ t args) = do t' <- toTT t
45 args' <- mapM (toTT . getTm) args
45 args' <- mapM (toTT . getTm) args
46 return $ mkApp t' args'
46 return $ mkApp t' args'
47− toTT _ = do v <- get
47+ toTT _ = do v <- get
48 put (v + 1)
48 put (v + 1)
49 return (P Bound (MN v "imp") Erased)
49 return (P Bound (MN v "imp") Erased)
50
50
51mkPTerm :: Name -> [TT Name] -> Idris PTerm
51mkPTerm :: Name -> [TT Name] -> Idris PTerm
52−mkPTerm f args = do i <- get
52+mkPTerm f args = do i <- getIState
53 let fapp = mkApp (P Bound f Erased) (map eraseName args)
53 let fapp = mkApp (P Bound f Erased) (map eraseName args)
54 return $ delab i fapp
54 return $ delab i fapp
55 where eraseName (App f a) = App (eraseName f) (eraseName a)
55 where eraseName (App f a) = App (eraseName f) (eraseName a)
@@ -90,7 +90,7 @@ dropDefault (c : cs) = c : dropDefault cs
90dropDefault [] = []
90dropDefault [] = []
91
91
92expandTree :: SC -> Idris SC
92expandTree :: SC -> Idris SC
93−expandTree (Case n alts) = do i <- get
93+expandTree (Case n alts) = do i <- getIState
94 as <- expandAlts i (dropDefault alts)
94 as <- expandAlts i (dropDefault alts)
95 (getDefault alts)
95 (getDefault alts)
96 alts' <- mapM expandTreeA as
96 alts' <- mapM expandTreeA as
@@ -110,8 +110,8 @@ expandAlts i all@(ConCase n _ _ _ : alts) def
110 | (TyDecl c@(DCon _ arity) ty : _) <- lookupDef Nothing n (tt_ctxt i)
110 | (TyDecl c@(DCon _ arity) ty : _) <- lookupDef Nothing n (tt_ctxt i)
111 = do let tyn = getTy n (tt_ctxt i)
111 = do let tyn = getTy n (tt_ctxt i)
112 case lookupCtxt Nothing tyn (idris_datatypes i) of
112 case lookupCtxt Nothing tyn (idris_datatypes i) of
113− (TI ns _ : _) -> do let ps = map mkPat ns
113+ (TI ns _ _: _) -> do let ps = map mkPat ns
114− return $ addAlts ps (altsFor all) all
114+ return $ addAlts ps (altsFor all) all
115 _ -> return all
115 _ -> return all
116 where
116 where
117 altsFor [] = []
117 altsFor [] = []
@@ -225,7 +225,7 @@ genAll i args = case filter (/=Placeholder) $ concatMap otherPats (nub args) of
225 let p = PApp fc (PRef fc n) (zipWith upd xs' xs)
225 let p = PApp fc (PRef fc n) (zipWith upd xs' xs)
226 let tyn = getTy n (tt_ctxt i)
226 let tyn = getTy n (tt_ctxt i)
227 case lookupCtxt Nothing tyn (idris_datatypes i) of
227 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])
229 _ -> [p]
229 _ -> [p]
230 ops fc n arg o = return Placeholder
230 ops fc n arg o = return Placeholder
231
231
@@ -300,14 +300,14 @@ calcProd i fc n pats = do patsprod <- mapM prodRec pats
300 cotype ty
300 cotype ty
301 | (P _ t _, _) <- unApply (getRetTy ty)
301 | (P _ t _, _) <- unApply (getRetTy ty)
302 = case lookupCtxt Nothing t (idris_datatypes i) of
302 = case lookupCtxt Nothing t (idris_datatypes i) of
303− [TI _ True] -> True
303+ [TI _ True _] -> True
304 _ -> False
304 _ -> False
305 | otherwise = False
305 | otherwise = False
306
306
307calcTotality :: [Name] -> FC -> Name -> [([Name], Term, Term)]
307calcTotality :: [Name] -> FC -> Name -> [([Name], Term, Term)]
308 -> Idris Totality
308 -> Idris Totality
309calcTotality path fc n pats
309calcTotality path fc n pats
310− = do i <- get
310+ = do i <- getIState
311 let opts = case lookupCtxt Nothing n (idris_flags i) of
311 let opts = case lookupCtxt Nothing n (idris_flags i) of
312 [fs] -> fs
312 [fs] -> fs
313 _ -> []
313 _ -> []
@@ -370,7 +370,7 @@ checkTotality path fc n
370 totalityError t = tclift $ tfail (At fc (Msg (show n ++ " is " ++ show t)))
370 totalityError t = tclift $ tfail (At fc (Msg (show n ++ " is " ++ show t)))
371
371
372 warnPartial n t
372 warnPartial n t
373− = do i <- get
373+ = do i <- getIState
374 case lookupDef Nothing n (tt_ctxt i) of
374 case lookupDef Nothing n (tt_ctxt i) of
375 [x] -> do
375 [x] -> do
376 iputStrLn $ show fc ++ ":Warning - " ++ show n ++ " is " ++ show t
376 iputStrLn $ show fc ++ ":Warning - " ++ show n ++ " is " ++ show t
@@ -399,11 +399,11 @@ checkDeclTotality (fc, n)
399
399
400buildSCG :: (FC, Name) -> Idris ()
400buildSCG :: (FC, Name) -> Idris ()
401buildSCG (_, n) = do
401buildSCG (_, n) = do
402− ist <- get
402+ ist <- getIState
403 case lookupCtxt Nothing n (idris_callgraph ist) of
403 case lookupCtxt Nothing n (idris_callgraph ist) of
404 [cg] -> case lookupDef Nothing n (tt_ctxt ist) of
404 [cg] -> case lookupDef Nothing n (tt_ctxt ist) of
405 [CaseOp _ _ _ _ _ args sc _ _] ->
405 [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"
407 ++ show sc
407 ++ show sc
408 let newscg = buildSCG' ist sc args
408 let newscg = buildSCG' ist sc args
409 logLvl 5 $ show newscg
409 logLvl 5 $ show newscg
@@ -495,11 +495,12 @@ buildSCG' ist sc args = -- trace ("Building SCG for " ++ show sc) $
495
495
496checkSizeChange :: Name -> Idris Totality
496checkSizeChange :: Name -> Idris Totality
497checkSizeChange n = do
497checkSizeChange n = do
498− ist <- get
498+ ist <- getIState
499 case lookupCtxt Nothing n (idris_callgraph ist) of
499 case lookupCtxt Nothing n (idris_callgraph ist) of
500 [cg] -> do let ms = mkMultiPaths ist [] (scg cg)
500 [cg] -> do let ms = mkMultiPaths ist [] (scg cg)
501− logLvl 6 ("Multipath for " ++ show n ++ ":\n" ++
501+ logLvl 5 ("Multipath for " ++ show n ++ ":\n" ++
502 "from " ++ show (scg cg) ++ "\n" ++
502 "from " ++ show (scg cg) ++ "\n" ++
503+ show (length ms) ++ "\n" ++
503 showSep "\n" (map show ms))
504 showSep "\n" (map show ms))
504 logLvl 6 (show cg)
505 logLvl 6 (show cg)
505 -- every multipath must have an infinitely descending
506 -- every multipath must have an infinitely descending
@@ -507,7 +508,8 @@ checkSizeChange n = do
507 -- also need to checks functions called are all total
508 -- also need to checks functions called are all total
508 -- (Unchecked is okay as we'll spot problems here)
509 -- (Unchecked is okay as we'll spot problems here)
509 let tot = map (checkMP ist (length (argsdef cg))) ms
510 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)
511 return (noPartial tot)
513 return (noPartial tot)
512 [] -> do logLvl 5 $ "No paths for " ++ show n
514 [] -> do logLvl 5 $ "No paths for " ++ show n
513 return Unchecked
515 return Unchecked
src/Idris/DataOpts.hs+2−2
@@ -48,8 +48,8 @@ forceArgs n t = do i <- getIState
48
48
49 guarded :: Term -> [Int]
49 guarded :: Term -> [Int]
50 guarded t@(App f a)
50 guarded t@(App f a)
51− | (P (TCon _ _) _ _, args) <- unApply t
51+-- | (P (TCon _ _) _ _, args) <- unApply t
52− = mapMaybe isF args ++ concatMap guarded args
52+-- = mapMaybe isF args ++ concatMap guarded args
53 | (P (DCon _ _) _ _, args) <- unApply t
53 | (P (DCon _ _) _ _, args) <- unApply t
54 = mapMaybe isF args ++ concatMap guarded args
54 = mapMaybe isF args ++ concatMap guarded args
55 guarded t = mapMaybe isF [t]
55 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
44 n = liftname info n_in in -}
44 n = liftname info n_in in -}
45 do checkUndefined fc n
45 do checkUndefined fc n
46 ctxt <- getContext
46 ctxt <- getContext
47− i <- get
47+ i <- getIState
48 logLvl 3 $ show n ++ " pre-type " ++ showImp True ty'
48 logLvl 3 $ show n ++ " pre-type " ++ showImp True ty'
49 ty' <- implicit syn n ty'
49 ty' <- implicit syn n ty'
50 let ty = addImpl i ty'
50 let ty = addImpl i ty'
@@ -67,7 +67,7 @@ elabType info syn doc fc opts n ty' = {- let ty' = piBind (params info) ty_in
67 let (t, _) = unApply (getRetTy nty')
67 let (t, _) = unApply (getRetTy nty')
68 let corec = case t of
68 let corec = case t of
69 P _ rcty _ -> case lookupCtxt Nothing rcty (idris_datatypes i) of
69 P _ rcty _ -> case lookupCtxt Nothing rcty (idris_datatypes i) of
70− [TI _ True] -> True
70+ [TI _ True _] -> True
71 _ -> False
71 _ -> False
72 _ -> False
72 _ -> False
73 let opts' = if corec then (Coinductive : opts) else opts
73 let opts' = if corec then (Coinductive : opts) else opts
@@ -91,7 +91,7 @@ elabPostulate info syn doc fc opts n ty
91 fty <- case lookupTy Nothing n ctxt of
91 fty <- case lookupTy Nothing n ctxt of
92 [] -> tclift $ tfail $ (At fc (NoTypeDecl n)) -- can't happen!
92 [] -> tclift $ tfail $ (At fc (NoTypeDecl n)) -- can't happen!
93 [ty] -> return ty
93 [ty] -> return ty
94− ist <- get
94+ ist <- getIState
95 let (ap, _) = unApply (getRetTy fty)
95 let (ap, _) = unApply (getRetTy fty)
96 logLvl 5 $ "Checking collapsibility of " ++ show (ap, fty)
96 logLvl 5 $ "Checking collapsibility of " ++ show (ap, fty)
97 let postOK = case ap of
97 let postOK = case ap of
@@ -110,7 +110,7 @@ elabData info syn doc fc codata (PLaterdecl n t_in)
110 = do iLOG (show (fc, doc))
110 = do iLOG (show (fc, doc))
111 checkUndefined fc n
111 checkUndefined fc n
112 ctxt <- getContext
112 ctxt <- getContext
113− i <- get
113+ i <- getIState
114 t_in <- implicit syn n t_in
114 t_in <- implicit syn n t_in
115 let t = addImpl i t_in
115 let t = addImpl i t_in
116 ((t', defer, is), log) <- tclift $ elaborate ctxt n (TType (UVal 0)) []
116 ((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)
126 = do iLOG (show fc)
126 = do iLOG (show fc)
127 undef <- isUndefined fc n
127 undef <- isUndefined fc n
128 ctxt <- getContext
128 ctxt <- getContext
129− i <- get
129+ i <- getIState
130 t_in <- implicit syn n t_in
130 t_in <- implicit syn n t_in
131 let t = addImpl i t_in
131 let t = addImpl i t_in
132 ((t', defer, is), log) <- tclift $ elaborate ctxt n (TType (UVal 0)) []
132 ((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)
140 when undef $ updateContext (addTyDecl n cty)
140 when undef $ updateContext (addTyDecl n cty)
141 cons <- mapM (elabCon info syn n codata) dcons
141 cons <- mapM (elabCon info syn n codata) dcons
142 ttag <- getName
142 ttag <- getName
143− i <- get
143+ i <- getIState
144− put (i { idris_datatypes = addDef n (TI (map fst cons) codata)
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)
145 (idris_datatypes i) })
148 (idris_datatypes i) })
146 addIBC (IBCDef n)
149 addIBC (IBCDef n)
147 addIBC (IBCData n)
150 addIBC (IBCData n)
@@ -150,13 +153,42 @@ elabData info syn doc fc codata (PDatadecl n t_in dcons)
150 collapseCons n cons
153 collapseCons n cons
151 updateContext (addDatatype (Data n ttag cty cons))
154 updateContext (addDatatype (Data n ttag cty cons))
152 mapM_ (checkPositive n) cons
155 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
153
185
154elabRecord :: ElabInfo -> SyntaxInfo -> String -> FC -> Name ->
186elabRecord :: ElabInfo -> SyntaxInfo -> String -> FC -> Name ->
155 PTerm -> String -> Name -> PTerm -> Idris ()
187 PTerm -> String -> Name -> PTerm -> Idris ()
156elabRecord info syn doc fc tyn ty cdoc cn cty
188elabRecord info syn doc fc tyn ty cdoc cn cty
157 = do elabData info syn doc fc False (PDatadecl tyn ty [(cdoc, cn, cty, fc)])
189 = do elabData info syn doc fc False (PDatadecl tyn ty [(cdoc, cn, cty, fc)])
158 cty' <- implicit syn cn cty
190 cty' <- implicit syn cn cty
159− i <- get
191+ i <- getIState
160 cty <- case lookupTy Nothing cn (tt_ctxt i) of
192 cty <- case lookupTy Nothing cn (tt_ctxt i) of
161 [t] -> return (delab i t)
193 [t] -> return (delab i t)
162 _ -> fail "Something went inexplicably wrong"
194 _ -> fail "Something went inexplicably wrong"
@@ -181,13 +213,13 @@ elabRecord info syn doc fc tyn ty cdoc cn cty
181 isNonImp _ = Nothing
213 isNonImp _ = Nothing
182
214
183 tryElabDecl info (fn, ty, val)
215 tryElabDecl info (fn, ty, val)
184− = do i <- get
216+ = do i <- getIState
185 idrisCatch (do elabDecl' EAll info ty
217 idrisCatch (do elabDecl' EAll info ty
186 elabDecl' EAll info val)
218 elabDecl' EAll info val)
187 (\v -> do iputStrLn $ show fc ++
219 (\v -> do iputStrLn $ show fc ++
188 ":Warning - can't generate setter for " ++
220 ":Warning - can't generate setter for " ++
189 show fn ++ " (" ++ show ty ++ ")"
221 show fn ++ " (" ++ show ty ++ ")"
190− put i)
222+ putIState i)
191
223
192 getImplB k (PPi (Imp l s _) n Placeholder sc)
224 getImplB k (PPi (Imp l s _) n Placeholder sc)
193 = getImplB k sc
225 = getImplB k sc
@@ -265,7 +297,7 @@ elabCon :: ElabInfo -> SyntaxInfo -> Name -> Bool ->
265elabCon info syn tn codata (doc, n, t_in, fc)
297elabCon info syn tn codata (doc, n, t_in, fc)
266 = do checkUndefined fc n
298 = do checkUndefined fc n
267 ctxt <- getContext
299 ctxt <- getContext
268− i <- get
300+ i <- getIState
269 t_in <- implicit syn n (if codata then mkLazy t_in else t_in)
301 t_in <- implicit syn n (if codata then mkLazy t_in else t_in)
270 let t = addImpl i t_in
302 let t = addImpl i t_in
271 logLvl 2 $ show fc ++ ":Constructor " ++ show n ++ " : " ++ showImp True t
303 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
311 (zip [0..] cs)
343 (zip [0..] cs)
312 -- if the return type of 'ty' is collapsible, the optimised version should
344 -- if the return type of 'ty' is collapsible, the optimised version should
313 -- just do nothing
345 -- just do nothing
314− ist <- get
346+ ist <- getIState
315 let (ap, _) = unApply (getRetTy fty)
347 let (ap, _) = unApply (getRetTy fty)
316 logLvl 5 $ "Checking collapsibility of " ++ show (ap, fty)
348 logLvl 5 $ "Checking collapsibility of " ++ show (ap, fty)
317 -- FIXME: Really ought to only do this for total functions!
349 -- 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
322 _ -> False
354 _ -> False
323 _ -> False
355 _ -> False
324 solveDeferred n
356 solveDeferred n
325− ist <- get
357+ ist <- getIState
326 when doNothing $
358 when doNothing $
327 case lookupCtxt Nothing n (idris_optimisation ist) of
359 case lookupCtxt Nothing n (idris_optimisation ist) of
328 [oi] -> do let opts = addDef n (oi { collapsible = True })
360 [oi] -> do let opts = addDef n (oi { collapsible = True })
329 (idris_optimisation ist)
361 (idris_optimisation ist)
330− put (ist { idris_optimisation = opts })
362+ putIState (ist { idris_optimisation = opts })
331 _ -> do let opts = addDef n (Optimise True [] [])
363 _ -> do let opts = addDef n (Optimise True [] [])
332 (idris_optimisation ist)
364 (idris_optimisation ist)
333− put (ist { idris_optimisation = opts })
365+ putIState (ist { idris_optimisation = opts })
334 addIBC (IBCOpt n)
366 addIBC (IBCOpt n)
335− ist <- get
367+ ist <- getIState
336 let pats = pats_in
368 let pats = pats_in
337 -- logLvl 3 (showSep "\n" (map (\ (l,r) ->
369 -- logLvl 3 (showSep "\n" (map (\ (l,r) ->
338 -- show l ++ " = " ++
370 -- show l ++ " = " ++
@@ -369,7 +401,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
369 pdef' <- applyOpts optpdef
401 pdef' <- applyOpts optpdef
370 logLvl 2 $ "Optimised patterns"
402 logLvl 2 $ "Optimised patterns"
371 logLvl 5 $ show pdef'
403 logLvl 5 $ show pdef'
372− ist <- get
404+ ist <- getIState
373 -- let wf = wellFounded ist n sc
405 -- let wf = wellFounded ist n sc
374 let tot = if pcover || AssertTotal `elem` opts
406 let tot = if pcover || AssertTotal `elem` opts
375 then Unchecked -- finish checking later
407 then Unchecked -- finish checking later
@@ -393,8 +425,8 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
393 logLvl 3 (show tree)
425 logLvl 3 (show tree)
394 logLvl 3 $ "Optimised: " ++ show tree'
426 logLvl 3 $ "Optimised: " ++ show tree'
395 ctxt <- getContext
427 ctxt <- getContext
396− ist <- get
428+ ist <- getIState
397− put (ist { idris_patdefs = addDef n pdef' (idris_patdefs ist) })
429+ putIState (ist { idris_patdefs = addDef n pdef' (idris_patdefs ist) })
398 case lookupTy (namespace info) n ctxt of
430 case lookupTy (namespace info) n ctxt of
399 [ty] -> do updateContext (addCasedef n (inlinable opts)
431 [ty] -> do updateContext (addCasedef n (inlinable opts)
400 tcase knowncovering
432 tcase knowncovering
@@ -405,7 +437,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
405 setTotality n tot
437 setTotality n tot
406 totcheck (fc, n)
438 totcheck (fc, n)
407 when (tot /= Unchecked) $ addIBC (IBCTotal n tot)
439 when (tot /= Unchecked) $ addIBC (IBCTotal n tot)
408− i <- get
440+ i <- getIState
409 case lookupDef Nothing n (tt_ctxt i) of
441 case lookupDef Nothing n (tt_ctxt i) of
410 (CaseOp _ _ _ _ _ scargs sc scargs' sc' : _) ->
442 (CaseOp _ _ _ _ _ scargs sc scargs' sc' : _) ->
411 do let calls = findCalls sc' scargs'
443 do let calls = findCalls sc' scargs'
@@ -453,7 +485,7 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
453elabVal :: ElabInfo -> Bool -> PTerm -> Idris (Term, Type)
485elabVal :: ElabInfo -> Bool -> PTerm -> Idris (Term, Type)
454elabVal info aspat tm_in
486elabVal info aspat tm_in
455 = do ctxt <- getContext
487 = do ctxt <- getContext
456− i <- get
488+ i <- getIState
457 let tm = addImpl i tm_in
489 let tm = addImpl i tm_in
458 logLvl 10 (showImp True tm)
490 logLvl 10 (showImp True tm)
459 -- try:
491 -- try:
@@ -478,7 +510,7 @@ elabVal info aspat tm_in
478checkPossible :: ElabInfo -> FC -> Bool -> Name -> PTerm -> Idris Bool
510checkPossible :: ElabInfo -> FC -> Bool -> Name -> PTerm -> Idris Bool
479checkPossible info fc tcgen fname lhs_in
511checkPossible info fc tcgen fname lhs_in
480 = do ctxt <- getContext
512 = do ctxt <- getContext
481− i <- get
513+ i <- getIState
482 let lhs = addImpl i lhs_in
514 let lhs = addImpl i lhs_in
483 -- if the LHS type checks, it is possible
515 -- if the LHS type checks, it is possible
484 case elaborate ctxt (MN 0 "patLHS") infP []
516 case elaborate ctxt (MN 0 "patLHS") infP []
@@ -505,15 +537,25 @@ elabClause info tcgen (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
505 = do ctxt <- getContext
537 = do ctxt <- getContext
506 -- Build the LHS as an "Infer", and pull out its type and
538 -- Build the LHS as an "Infer", and pull out its type and
507 -- pattern bindings
539 -- pattern bindings
508− i <- get
540+ i <- getIState
509− let lhs = addImplPat i lhs_in
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)
510 logLvl 5 ("LHS: " ++ show fc ++ " " ++ showImp True lhs)
550 logLvl 5 ("LHS: " ++ show fc ++ " " ++ showImp True lhs)
551+ logLvl 4 ("Fixed parameters: " ++ show params ++ " from " ++ show (fn_ty, fn_is))
511 ((lhs', dlhs, []), _) <-
552 ((lhs', dlhs, []), _) <-
512 tclift $ elaborate ctxt (MN 0 "patLHS") infP []
553 tclift $ elaborate ctxt (MN 0 "patLHS") infP []
513 (erun fc (buildTC i info True tcgen fname (infTerm lhs)))
554 (erun fc (buildTC i info True tcgen fname (infTerm lhs)))
514 let lhs_tm = orderPats (getInferTerm lhs')
555 let lhs_tm = orderPats (getInferTerm lhs')
515 let lhs_ty = getInferType lhs'
556 let lhs_ty = getInferType lhs'
516 logLvl 3 ("Elaborated: " ++ show lhs_tm)
557 logLvl 3 ("Elaborated: " ++ show lhs_tm)
558+ logLvl 3 ("Elaborated type: " ++ show lhs_ty)
517 (clhs, clhsty) <- recheckC fc [] lhs_tm
559 (clhs, clhsty) <- recheckC fc [] lhs_tm
518 logLvl 5 ("Checked " ++ show clhs)
560 logLvl 5 ("Checked " ++ show clhs)
519 -- Elaborate where block
561 -- Elaborate where block
@@ -533,7 +575,7 @@ elabClause info tcgen (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
533 logLvl 5 $ "Where block:\n " ++ show wbefore ++ "\n" ++ show wafter
575 logLvl 5 $ "Where block:\n " ++ show wbefore ++ "\n" ++ show wafter
534 mapM_ (elabDecl' EAll info) wbefore
576 mapM_ (elabDecl' EAll info) wbefore
535 -- Now build the RHS, using the type of the LHS as the goal.
577 -- 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
537 logLvl 5 (showImp True (expandParams decorate newargs defs (defs \\ decls) rhs_in))
579 logLvl 5 (showImp True (expandParams decorate newargs defs (defs \\ decls) rhs_in))
538 let rhs = addImplBoundInf i (map fst newargs) (defs \\ decls)
580 let rhs = addImplBoundInf i (map fst newargs) (defs \\ decls)
539 (expandParams decorate newargs defs (defs \\ decls) rhs_in)
581 (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)
567 case converts ctxt [] clhsty crhsty of
609 case converts ctxt [] clhsty crhsty of
568 OK _ -> return ()
610 OK _ -> return ()
569 Error e -> ierror (At fc (CantUnify False clhsty crhsty e [] 0))
611 Error e -> ierror (At fc (CantUnify False clhsty crhsty e [] 0))
570− i <- get
612+ i <- getIState
571 checkInferred fc (delab' i crhs True) rhs
613 checkInferred fc (delab' i crhs True) rhs
572 return $ Right (clhs, crhs)
614 return $ Right (clhs, crhs)
573 where
615 where
@@ -598,11 +640,45 @@ elabClause info tcgen (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
598 -- _ -> MN i (show n)) . l
640 -- _ -> MN i (show n)) . l
599 }
641 }
600
642
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+
601elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
677elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
602 = do ctxt <- getContext
678 = do ctxt <- getContext
603 -- Build the LHS as an "Infer", and pull out its type and
679 -- Build the LHS as an "Infer", and pull out its type and
604 -- pattern bindings
680 -- pattern bindings
605− i <- get
681+ i <- getIState
606 let lhs = addImpl i lhs_in
682 let lhs = addImpl i lhs_in
607 logLvl 5 ("LHS: " ++ showImp True lhs)
683 logLvl 5 ("LHS: " ++ showImp True lhs)
608 ((lhs', dlhs, []), _) <-
684 ((lhs', dlhs, []), _) <-
@@ -655,7 +731,7 @@ elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
655 logLvl 3 ("New function type " ++ show wtype)
731 logLvl 3 ("New function type " ++ show wtype)
656 let wname = MN windex (show fname)
732 let wname = MN windex (show fname)
657 let imps = getImps wtype -- add to implicits context
733 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) })
659 addIBC (IBCDef wname)
735 addIBC (IBCDef wname)
660 def' <- checkDef fc [(wname, wtype)]
736 def' <- checkDef fc [(wname, wtype)]
661 addDeferred def'
737 addDeferred def'
@@ -673,9 +749,9 @@ elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
673 (map (pexp . (PRef fc) . fst) bargs_pre ++
749 (map (pexp . (PRef fc) . fst) bargs_pre ++
674 pexp wval :
750 pexp wval :
675 (map (pexp . (PRef fc) . fst) bargs_post))
751 (map (pexp . (PRef fc) . fst) bargs_post))
676− logLvl 1 ("New RHS " ++ show rhs)
752+ logLvl 5 ("New RHS " ++ showImp True rhs)
677 ctxt <- getContext -- New context with block added
753 ctxt <- getContext -- New context with block added
678− i <- get
754+ i <- getIState
679 ((rhs', defer, is), _) <-
755 ((rhs', defer, is), _) <-
680 tclift $ elaborate ctxt (MN 0 "wpatRHS") clhsty []
756 tclift $ elaborate ctxt (MN 0 "wpatRHS") clhsty []
681 (do pbinds lhs_tm
757 (do pbinds lhs_tm
@@ -686,6 +762,7 @@ elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
686 def' <- checkDef fc defer
762 def' <- checkDef fc defer
687 addDeferred def'
763 addDeferred def'
688 mapM_ (elabCaseBlock info) is
764 mapM_ (elabCaseBlock info) is
765+ logLvl 5 ("Checked RHS " ++ show rhs')
689 (crhs, crhsty) <- recheckC fc [] rhs'
766 (crhs, crhsty) <- recheckC fc [] rhs'
690 return $ Right (clhs, crhs)
767 return $ Right (clhs, crhs)
691 where
768 where
@@ -699,7 +776,7 @@ elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
699 mkAuxC wname lhs ns ns' d = return $ d
776 mkAuxC wname lhs ns ns' d = return $ d
700
777
701 mkAux wname toplhs ns ns' (PClause fc n tm_in (w:ws) rhs wheres)
778 mkAux wname toplhs ns ns' (PClause fc n tm_in (w:ws) rhs wheres)
702− = do i <- get
779+ = do i <- getIState
703 let tm = addImpl i tm_in
780 let tm = addImpl i tm_in
704 logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
781 logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
705 showImp True toplhs)
782 showImp True toplhs)
@@ -710,7 +787,7 @@ elabClause info tcgen (_, PWith fc fname lhs_in withs wval_in withblock)
710 lhs <- updateLHS n wname mvars ns ns' (fullApp tm) w
787 lhs <- updateLHS n wname mvars ns ns' (fullApp tm) w
711 return $ PClause fc wname lhs ws rhs wheres
788 return $ PClause fc wname lhs ws rhs wheres
712 mkAux wname toplhs ns ns' (PWith fc n tm_in (w:ws) wval withs)
789 mkAux wname toplhs ns ns' (PWith fc n tm_in (w:ws) wval withs)
713− = do i <- get
790+ = do i <- getIState
714 let tm = addImpl i tm_in
791 let tm = addImpl i tm_in
715 logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
792 logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
716 showImp True toplhs)
793 showImp True toplhs)
@@ -765,6 +842,8 @@ elabClass info syn doc fc constraints tn ps ds
765 (filter clause ds)
842 (filter clause ds)
766 let (methods, imethods)
843 let (methods, imethods)
767 = unzip (map (\ ( x,y,z) -> (x, y)) ims)
844 = 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) [])
768 -- build instance constructor type
847 -- build instance constructor type
769 -- decorate names of functions to ensure they can't be referred
848 -- decorate names of functions to ensure they can't be referred
770 -- to elsewhere in the class declaration
849 -- to elsewhere in the class declaration
@@ -785,9 +864,7 @@ elabClass info syn doc fc constraints tn ps ds
785 mapM_ (elabDecl EAll info) (concat fns)
864 mapM_ (elabDecl EAll info) (concat fns)
786 -- add the default definitions
865 -- add the default definitions
787 mapM_ (elabDecl EAll info) (concat (map (snd.snd) defs))
866 mapM_ (elabDecl EAll info) (concat (map (snd.snd) defs))
788− i <- get
867+ i <- getIState
789− let defaults = map (\ (x, (y, z)) -> (x,y)) defs
790− addClass tn (CI cn (map nodoc imethods) defaults (map fst ps) [])
791 addIBC (IBCClass tn)
868 addIBC (IBCClass tn)
792 where
869 where
793 nodoc (n, (_, o, t)) = (n, (o, t))
870 nodoc (n, (_, o, t)) = (n, (o, t))
@@ -800,7 +877,7 @@ elabClass info syn doc fc constraints tn ps ds
800
877
801 impbind [] x = x
878 impbind [] x = x
802 impbind ((n, ty): ns) x = PPi impl n ty (impbind ns x)
879 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)
804 conbind [] x = x
881 conbind [] x = x
805
882
806 getMName (PTy _ _ _ _ n _) = nsroot n
883 getMName (PTy _ _ _ _ n _) = nsroot n
@@ -818,7 +895,7 @@ elabClass info syn doc fc constraints tn ps ds
818 Just (syn, o, ty) -> do let ty' = insertConstraint c ty
895 Just (syn, o, ty) -> do let ty' = insertConstraint c ty
819 let ds = map (decorateid defaultdec)
896 let ds = map (decorateid defaultdec)
820 [PTy "" syn fc [] n ty',
897 [PTy "" syn fc [] n ty',
821− PClauses fc (TCGen:o ++ opts) n cs]
898+ PClauses fc (Inlinable:TCGen:o ++ opts) n cs]
822 iLOG (show ds)
899 iLOG (show ds)
823 return (n, ((defaultdec n, ds!!1), ds))
900 return (n, ((defaultdec n, ds!!1), ds))
824 _ -> fail $ show n ++ " is not a method"
901 _ -> fail $ show n ++ " is not a method"
@@ -841,7 +918,7 @@ elabClass info syn doc fc constraints tn ps ds
841 let ty = PPi constraint (MN 0 "pc") c con
918 let ty = PPi constraint (MN 0 "pc") c con
842 iLOG (showImp True ty)
919 iLOG (showImp True ty)
843 iLOG (showImp True lhs ++ " = " ++ showImp True rhs)
920 iLOG (showImp True lhs ++ " = " ++ showImp True rhs)
844− i <- get
921+ i <- getIState
845 let conn = case con of
922 let conn = case con of
846 PRef _ n -> n
923 PRef _ n -> n
847 PApp _ (PRef _ n) _ -> n
924 PApp _ (PRef _ n) _ -> n
@@ -888,7 +965,7 @@ elabClass info syn doc fc constraints tn ps ds
888
965
889 insertConstraint c (PPi p@(Imp _ _ _) n ty sc)
966 insertConstraint c (PPi p@(Imp _ _ _) n ty sc)
890 = PPi p n ty (insertConstraint c sc)
967 = 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
892
969
893 -- make arguments explicit and don't bind class parameters
970 -- make arguments explicit and don't bind class parameters
894 toExp ns e (PPi (Imp l s _) n ty sc)
971 toExp ns e (PPi (Imp l s _) n ty sc)
@@ -905,10 +982,11 @@ elabInstance :: ElabInfo -> SyntaxInfo ->
905 Maybe Name -> -- explicit name
982 Maybe Name -> -- explicit name
906 [PDecl] -> Idris ()
983 [PDecl] -> Idris ()
907elabInstance info syn fc cs n ps t expn ds
984elabInstance info syn fc cs n ps t expn ds
908− = do i <- get
985+ = do i <- getIState
909 (n, ci) <- case lookupCtxtName (namespace info) n (idris_classes i) of
986 (n, ci) <- case lookupCtxtName (namespace info) n (idris_classes i) of
910 [c] -> return c
987 [c] -> return c
911 _ -> fail $ show fc ++ ":" ++ show n ++ " is not a type class"
988 _ -> fail $ show fc ++ ":" ++ show n ++ " is not a type class"
989+ let constraint = PApp fc (PRef fc n) (map pexp ps)
912 let iname = case expn of
990 let iname = case expn of
913 Nothing -> UN ('@':show n ++ "$" ++ show ps)
991 Nothing -> UN ('@':show n ++ "$" ++ show ps)
914 Just nm -> nm
992 Just nm -> nm
@@ -945,9 +1023,7 @@ elabInstance info syn fc cs n ps t expn ds
945 logLvl 3 $ "Method types " ++ showSep "\n" (map (showDeclImp True . mkTyDecl) mtys)
1023 logLvl 3 $ "Method types " ++ showSep "\n" (map (showDeclImp True . mkTyDecl) mtys)
946 logLvl 3 $ "Instance is " ++ show ps ++ " implicits " ++
1024 logLvl 3 $ "Instance is " ++ show ps ++ " implicits " ++
947 show (concat (nub wparams))
1025 show (concat (nub wparams))
948− let lhs = case concat (nub wparams) of
1026+ let lhs = PRef fc iname
949− [] -> PRef fc iname
950− as -> PApp fc (PRef fc iname) as
951 let rhs = PApp fc (PRef fc (instanceName ci))
1027 let rhs = PApp fc (PRef fc (instanceName ci))
952 (map (pexp . mkMethApp) mtys)
1028 (map (pexp . mkMethApp) mtys)
953 let idecls = [PClauses fc [Inlinable, TCGen] iname
1029 let idecls = [PClauses fc [Inlinable, TCGen] iname
@@ -955,6 +1031,10 @@ elabInstance info syn fc cs n ps t expn ds
955 iLOG (show idecls)
1031 iLOG (show idecls)
956 mapM (elabDecl EAll info) idecls
1032 mapM (elabDecl EAll info) idecls
957 addIBC (IBCInstance intInst n iname)
1033 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)
958 where
1038 where
959 intInst = case ps of
1039 intInst = case ps of
960 [PConstant IType] -> True
1040 [PConstant IType] -> True
@@ -1010,7 +1090,7 @@ elabInstance info syn fc cs n ps t expn ds
1010
1090
1011 mkTyDecl (n, op, t, _) = PTy "" syn fc op n t
1091 mkTyDecl (n, op, t, _) = PTy "" syn fc op n t
1012
1092
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)
1014 conbind [] x = x
1094 conbind [] x = x
1015
1095
1016 coninsert cs (PPi p@(Imp _ _ _) n t sc) = PPi p n t (coninsert cs sc)
1096 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
1046 = decorate ns iname m == decorate ns iname m'
1126 = decorate ns iname m == decorate ns iname m'
1047 clauseFor m iname ns _ = False
1127 clauseFor m iname ns _ = False
1048
1128
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+
1049decorateid decorate (PTy doc s f o n t) = PTy doc s f o (decorate n) t
1154decorateid decorate (PTy doc s f o n t) = PTy doc s f o (decorate n) t
1050decorateid decorate (PClauses f o n cs)
1155decorateid decorate (PClauses f o n cs)
1051 = PClauses f o (decorate n) (map dc cs)
1156 = PClauses f o (decorate n) (map dc cs)
@@ -1109,7 +1214,7 @@ elabDecl' what info (PData doc s f co d)
1109elabDecl' what info d@(PClauses f o n ps)
1214elabDecl' what info d@(PClauses f o n ps)
1110 | what /= ETypes
1215 | what /= ETypes
1111 = do iLOG $ "Elaborating clause " ++ show n
1216 = do iLOG $ "Elaborating clause " ++ show n
1112− i <- get -- get the type options too
1217+ i <- getIState -- get the type options too
1113 let o' = case lookupCtxt Nothing n (idris_flags i) of
1218 let o' = case lookupCtxt Nothing n (idris_flags i) of
1114 [fs] -> fs
1219 [fs] -> fs
1115 [] -> []
1220 [] -> []
@@ -1118,7 +1223,7 @@ elabDecl' what info (PMutual f ps)
1118 = do mapM_ (elabDecl ETypes info) ps
1223 = do mapM_ (elabDecl ETypes info) ps
1119 mapM_ (elabDecl EDefns info) ps
1224 mapM_ (elabDecl EDefns info) ps
1120elabDecl' what info (PParams f ns ps)
1225elabDecl' what info (PParams f ns ps)
1121− = do i <- get
1226+ = do i <- getIState
1122 iLOG $ "Expanding params block with " ++ show ns ++ " decls " ++
1227 iLOG $ "Expanding params block with " ++ show ns ++ " decls " ++
1123 show (concatMap tldeclared ps)
1228 show (concatMap tldeclared ps)
1124 let nblock = pblock i
1229 let nblock = pblock i
@@ -1151,8 +1256,8 @@ elabDecl' what info (PRecord doc s f tyn ty cdoc cn cty)
1151 = do iLOG $ "Elaborating record " ++ show tyn
1256 = do iLOG $ "Elaborating record " ++ show tyn
1152 elabRecord info s doc f tyn ty cdoc cn cty
1257 elabRecord info s doc f tyn ty cdoc cn cty
1153elabDecl' _ info (PDSL n dsl)
1258elabDecl' _ info (PDSL n dsl)
1154− = do i <- get
1259+ = do i <- getIState
1155− put (i { idris_dsls = addDef n dsl (idris_dsls i) })
1260+ putIState (i { idris_dsls = addDef n dsl (idris_dsls i) })
1156 addIBC (IBCDSL n)
1261 addIBC (IBCDSL n)
1157elabDecl' what info (PDirective i)
1262elabDecl' what info (PDirective i)
1158 | what /= EDefns = i
1263 | what /= EDefns = i
@@ -1174,7 +1279,7 @@ checkInferred fc inf user =
1174 do logLvl 6 $ "Checked to\n" ++ showImp True inf ++ "\n\nFROM\n\n" ++
1279 do logLvl 6 $ "Checked to\n" ++ showImp True inf ++ "\n\nFROM\n\n" ++
1175 showImp True user
1280 showImp True user
1176 logLvl 10 $ "Checking match"
1281 logLvl 10 $ "Checking match"
1177− i <- get
1282+ i <- getIState
1178 tclift $ case matchClause' True i user inf of
1283 tclift $ case matchClause' True i user inf of
1179 Right vs -> return ()
1284 Right vs -> return ()
1180 Left (x, y) -> tfail $ At fc
1285 Left (x, y) -> tfail $ At fc
@@ -1188,7 +1293,7 @@ checkInferred fc inf user =
1188
1293
1189inferredDiff :: FC -> PTerm -> PTerm -> Idris Bool
1294inferredDiff :: FC -> PTerm -> PTerm -> Idris Bool
1190inferredDiff fc inf user =
1295inferredDiff fc inf user =
1191− do i <- get
1296+ do i <- getIState
1192 logLvl 6 $ "Checked to\n" ++ showImp True inf ++ "\n" ++
1297 logLvl 6 $ "Checked to\n" ++ showImp True inf ++ "\n" ++
1193 showImp True user
1298 showImp True user
1194 tclift $ case matchClause' True i user inf of
1299 tclift $ case matchClause' True i user inf of
src/Idris/ElabTerm.hs+145−59
@@ -39,6 +39,27 @@ build :: IState -> ElabInfo -> Bool -> Name -> PTerm ->
39 ElabD (Term, [(Name, Type)], [PDecl])
39 ElabD (Term, [(Name, Type)], [PDecl])
40build ist info pattern fn tm
40build ist info pattern fn tm
41 = do elab ist info pattern False fn tm
41 = 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)
42 is <- getAux
63 is <- getAux
43 tt <- get_term
64 tt <- get_term
44 let (tm, ds) = runState (collectDeferred tt) []
65 let (tm, ds) = runState (collectDeferred tt) []
@@ -54,6 +75,11 @@ buildTC :: IState -> ElabInfo -> Bool -> Bool -> Name -> PTerm ->
54 ElabD (Term, [(Name, Type)], [PDecl])
75 ElabD (Term, [(Name, Type)], [PDecl])
55buildTC ist info pattern tcgen fn tm
76buildTC ist info pattern tcgen fn tm
56 = do elab ist info pattern tcgen fn tm
77 = 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)
57 is <- getAux
83 is <- getAux
58 tt <- get_term
84 tt <- get_term
59 let (tm, ds) = runState (collectDeferred tt) []
85 let (tm, ds) = runState (collectDeferred tt) []
@@ -72,8 +98,6 @@ elab ist info pattern tcgen fn tm
72 (do update_term orderPats
98 (do update_term orderPats
73-- tm <- get_term
99-- tm <- get_term
74 mkPat)
100 mkPat)
75− inj <- get_inj
76− mapM_ checkInjective inj
77 where
101 where
78 isph arg = case getTm arg of
102 isph arg = case getTm arg of
79 Placeholder -> (True, priority arg)
103 Placeholder -> (True, priority arg)
@@ -110,11 +134,11 @@ elab ist info pattern tcgen fn tm
110 elab' ina (PResolveTC (FC "HACK" _)) -- for chasing parent classes
134 elab' ina (PResolveTC (FC "HACK" _)) -- for chasing parent classes
111 = resolveTC 5 fn ist
135 = resolveTC 5 fn ist
112 elab' ina (PResolveTC fc)
136 elab' ina (PResolveTC fc)
113− | pattern = do c <- unique_hole (MN 0 "c")
137+ | True = do c <- unique_hole (MN 0 "class")
114− instanceArg c
138+ instanceArg c
115 | otherwise = do g <- goal
139 | otherwise = do g <- goal
116 try (resolveTC 2 fn ist)
140 try (resolveTC 2 fn ist)
117− (do c <- unique_hole (MN 0 "c")
141+ (do c <- unique_hole (MN 0 "class")
118 instanceArg c)
142 instanceArg c)
119 elab' ina (PRefl fc t) = elab' ina (PApp fc (PRef fc eqCon) [pimp (MN 0 "a") Placeholder,
143 elab' ina (PRefl fc t) = elab' ina (PApp fc (PRef fc eqCon) [pimp (MN 0 "a") Placeholder,
120 pimp (MN 0 "x") t])
144 pimp (MN 0 "x") t])
@@ -122,15 +146,23 @@ elab ist info pattern tcgen fn tm
122 pimp (MN 0 "b") Placeholder,
146 pimp (MN 0 "b") Placeholder,
123 pexp l, pexp r])
147 pexp l, pexp r])
124 elab' ina@(_, a) (PPair fc l r)
148 elab' ina@(_, a) (PPair fc l r)
125− = try (elabE (True, a) (PApp fc (PRef fc pairTy)
149+ = do hnf_compute
126− [pexp l,pexp r]))
150+ g <- goal
127− (elabE (True, a) (PApp fc (PRef fc pairCon)
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)
128 [pimp (MN 0 "A") Placeholder,
155 [pimp (MN 0 "A") Placeholder,
129 pimp (MN 0 "B") Placeholder,
156 pimp (MN 0 "B") Placeholder,
130− pexp l, pexp r]))
157+ pexp l, pexp r])
131 elab' ina (PDPair fc l@(PRef _ n) t r)
158 elab' ina (PDPair fc l@(PRef _ n) t r)
132 = case t of
159 = 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
134 _ -> asType
166 _ -> asType
135 where asType = elab' ina (PApp fc (PRef fc sigmaTy)
167 where asType = elab' ina (PApp fc (PRef fc sigmaTy)
136 [pexp t,
168 [pexp t,
@@ -144,10 +176,14 @@ elab ist info pattern tcgen fn tm
144 pimp (MN 0 "P") Placeholder,
176 pimp (MN 0 "P") Placeholder,
145 pexp l, pexp r])
177 pexp l, pexp r])
146 elab' ina (PAlternative True as)
178 elab' ina (PAlternative True as)
147− = do ty <- goal
179+ = do hnf_compute
180+ ty <- goal
148 ctxt <- get_context
181 ctxt <- get_context
149 let (tc, _) = unApply ty
182 let (tc, _) = unApply ty
150 let as' = pruneByType tc ctxt as
183 let as' = pruneByType tc ctxt as
184+-- case as' of
185+-- [a] -> elab' ina a
186+-- as -> lift $ tfail $ CantResolveAlts (map showHd as)
151 tryAll (zip (map (elab' ina) as') (map showHd as'))
187 tryAll (zip (map (elab' ina) as') (map showHd as'))
152 where showHd (PApp _ h _) = show h
188 where showHd (PApp _ h _) = show h
153 showHd x = show x
189 showHd x = show x
@@ -181,6 +217,7 @@ elab ist info pattern tcgen fn tm
181 = do -- n' <- unique_hole n
217 = do -- n' <- unique_hole n
182 -- let sc' = mapPT (repN n n') sc
218 -- let sc' = mapPT (repN n n') sc
183 ptm <- get_term
219 ptm <- get_term
220+ g <- goal
184 attack; intro (Just n);
221 attack; intro (Just n);
185 -- trace ("------ intro " ++ show n ++ " ---- \n" ++ show ptm)
222 -- trace ("------ intro " ++ show n ++ " ---- \n" ++ show ptm)
186 elabE (True, a) sc; solve
223 elabE (True, a) sc; solve
@@ -231,6 +268,7 @@ elab ist info pattern tcgen fn tm
231 focus valn
268 focus valn
232 elabE (True, a) val
269 elabE (True, a) val
233 elabE (True, a) sc
270 elabE (True, a) sc
271+ ptm <- get_term
234 solve
272 solve
235 elab' ina tm@(PApp fc (PInferRef _ f) args) = do
273 elab' ina tm@(PApp fc (PInferRef _ f) args) = do
236 rty <- goal
274 rty <- goal
@@ -277,43 +315,58 @@ elab ist info pattern tcgen fn tm
277 Just xs@(_:_) -> NS n xs
315 Just xs@(_:_) -> NS n xs
278 _ -> n
316 _ -> n
279
317
318+ -- if f is local, just do a simple_app
280 elab' (ina, g) tm@(PApp fc (PRef _ f) args')
319 elab' (ina, g) tm@(PApp fc (PRef _ f) args')
281 = do let args = {- case lookupCtxt f (inblock info) of
320 = do let args = {- case lookupCtxt f (inblock info) of
282 Just ps -> (map (pexp . (PRef fc)) ps ++ args')
321 Just ps -> (map (pexp . (PRef fc)) ps ++ args')
283 _ ->-} args'
322 _ ->-} args'
284-- newtm <- mkSpecialised ist fc f (map getTm args') tm
323-- newtm <- mkSpecialised ist fc f (map getTm args') tm
285− ivs <- get_instances
324+ env <- get_env
286− -- HACK: we shouldn't resolve type classes if we're defining an instance
325+ if (f `elem` map fst env && length args' == 1)
287− -- function or default definition.
326+ then -- simple app, as below
288− let isinf = f == inferCon || tcname f
327+ do simple_app (elabE (ina, g) (PRef fc f))
289− ctxt <- get_context
328+ (elabE (True, g) (getTm (head args')))
290− let guarded = isConName Nothing f ctxt
329+ solve
291−-- when True
330+ else
292− tryWhen True
331+ do ivs <- get_instances
293− (do ns <- apply (Var f) (map isph args)
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)
294 ptm <- get_term
344 ptm <- get_term
345+ g <- goal
295 let (ns', eargs) = unzip $
346 let (ns', eargs) = unzip $
296 sortBy (\(_,x) (_,y) ->
347 sortBy (\(_,x) (_,y) ->
297 compare (priority x) (priority y))
348 compare (priority x) (priority y))
298 (zip ns args)
349 (zip ns args)
299− tryWhen True
350+ elabArgs (ina || not isinf, guarded)
300− (elabArgs (ina || not isinf, guarded)
351+ [] False ns' (map (\x -> (lazyarg x, getTm x)) eargs)
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)))
305 mkSpecialised ist fc f (map getTm args') tm
352 mkSpecialised ist fc f (map getTm args') tm
306− solve)
353+ solve
307− (do apply_elab f (map (toElab (ina || not isinf, guarded)) args)
354+ ptm <- get_term
308− mkSpecialised ist fc f (map getTm args') tm
355+ ivs' <- get_instances
309− solve)
356+ ps' <- get_probs
310−-- ptm <- get_term
357+ -- Attempt to resolve any type classes which have 'complete' types,
311−-- elog (show ptm)
358+ -- i.e. no holes in them
312− ivs' <- get_instances
359+ when (not pattern || (ina && not tcgen && not guarded)) $
313− when (not pattern || (ina && not tcgen)) $
360+ mapM_ (\n -> do focus n
314− mapM_ (\n -> do focus n
361+ g <- goal
315− -- let insts = filter tcname $ map fst (ctxtAlist (tt_ctxt ist))
362+ env <- get_env
316− resolveTC 7 fn ist) (ivs' \\ ivs)
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)
317 where tcArg (n, PConstraint _ _ Placeholder _) = True
370 where tcArg (n, PConstraint _ _ Placeholder _) = True
318 tcArg _ = False
371 tcArg _ = False
319
372
@@ -321,10 +374,13 @@ elab ist info pattern tcgen fn tm
321 tacTm (PProof _) = True
374 tacTm (PProof _) = True
322 tacTm _ = False
375 tacTm _ = False
323
376
377+ setInjective (PRef _ n) = setinj n
378+ setInjective (PApp _ (PRef _ n) _) = setinj n
379+ setInjective _ = return ()
380+
324 elab' ina@(_, a) (PApp fc f [arg])
381 elab' ina@(_, a) (PApp fc f [arg])
325 = erun fc $
382 = erun fc $
326− do ptm <- get_term
383+ do simple_app (elabE ina f) (elabE (True, a) (getTm arg))
327− simple_app (elabE ina f) (elabE (True, a) (getTm arg))
328 solve
384 solve
329 elab' ina Placeholder = do (h : hs) <- get_holes
385 elab' ina Placeholder = do (h : hs) <- get_holes
330 movelast h
386 movelast h
@@ -436,22 +492,29 @@ pruneAlt xs = map prune xs
436
492
437-- Rule out alternatives that don't return the same type as the head of the goal
493-- Rule out alternatives that don't return the same type as the head of the goal
438-- (If there are none left as a result, do nothing)
494-- (If there are none left as a result, do nothing)
439−
440pruneByType :: Term -> Context -> [PTerm] -> [PTerm]
495pruneByType :: Term -> Context -> [PTerm] -> [PTerm]
441pruneByType (P _ n _) c as
496pruneByType (P _ n _) c as
442− = let as' = filter (headIs n) as in
497+-- if the goal type is polymorphic, keep e
443− case as' of
498+ | [] <- lookupTy Nothing n c = as
444− [] -> as
499+ | otherwise
445− _ -> as'
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'
446 where
507 where
447− headIs f (PApp _ (PRef _ f') _) = typeHead f f'
508+ headIs var f (PApp _ (PRef _ f') _) = typeHead var f f'
448− headIs f (PApp _ f' _) = headIs f f'
509+ headIs var f (PApp _ f' _) = headIs var f f'
449− headIs f (PPi _ _ _ sc) = headIs f sc
510+ headIs var f (PPi _ _ _ sc) = headIs var f sc
450− headIs _ _ = True -- keep if it's not an application
511+ headIs _ _ _ = True -- keep if it's not an application
451
512
452− typeHead f f' = case lookupTy Nothing f' c of
513+ typeHead var f f'
514+ = case lookupTy Nothing f' c of
453 [ty] -> case unApply (getRetTy ty) of
515 [ty] -> case unApply (getRetTy ty) of
454 (P _ ftyn _, _) -> ftyn == f
516 (P _ ftyn _, _) -> ftyn == f
517+ (V _, _) -> var -- keep, variable
455 _ -> False
518 _ -> False
456 _ -> False
519 _ -> False
457
520
@@ -462,13 +525,20 @@ trivial ist = try' (do elab ist toplevel False False (MN 0 "tac")
462 (PRefl (FC "prf" 0) Placeholder)
525 (PRefl (FC "prf" 0) Placeholder)
463 return ())
526 return ())
464 (do env <- get_env
527 (do env <- get_env
465− tryAll (map fst env)
528+ g <- goal
529+ tryAll env
466 return ()) True
530 return ()) True
467 where
531 where
468 tryAll [] = fail "No trivial solution"
532 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
470 (MN 0 "tac") (PRef (FC "prf" 0) x))
539 (MN 0 "tac") (PRef (FC "prf" 0) x))
471 (tryAll xs) True
540 (tryAll xs) True
541+ else tryAll xs
472
542
473findInstances :: IState -> Term -> [Name]
543findInstances :: IState -> Term -> [Name]
474findInstances ist t
544findInstances ist t
@@ -483,7 +553,11 @@ resolveTC 0 fn ist = fail $ "Can't resolve type class"
483resolveTC 1 fn ist = try' (trivial ist) (resolveTC 0 fn ist) True
553resolveTC 1 fn ist = try' (trivial ist) (resolveTC 0 fn ist) True
484resolveTC depth fn ist
554resolveTC depth fn ist
485 = do hnf_compute
555 = 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)
487 (do t <- goal
561 (do t <- goal
488 let insts = findInstances ist t
562 let insts = findInstances ist t
489 let (tc, ttypes) = unApply t
563 let (tc, ttypes) = unApply t
@@ -491,17 +565,23 @@ resolveTC depth fn ist
491 tm <- get_term
565 tm <- get_term
492-- traceWhen (depth > 6) ("GOAL: " ++ show t ++ "\nTERM: " ++ show tm) $
566-- traceWhen (depth > 6) ("GOAL: " ++ show t ++ "\nTERM: " ++ show tm) $
493-- (tryAll (map elabTC (map fst (ctxtAlist (tt_ctxt ist)))))
567-- (tryAll (map elabTC (map fst (ctxtAlist (tt_ctxt ist)))))
568+-- if scopeOnly then fail "Can't resolve" else
494 let depth' = if scopeOnly then 2 else depth
569 let depth' = if scopeOnly then 2 else depth
495 blunderbuss t depth' insts) True
570 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
496 where
576 where
497 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
577 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
498 | otherwise = (fail "Can't resolve", show n)
578 | otherwise = (fail "Can't resolve", show n)
499
579
500−-- needsDefault t num@(P _ (NS (UN "Num") ["builtins"]) _) [P Bound a _]
580+ needsDefault t num@(P _ (NS (UN "Num") ["Builtins"]) _) [P Bound a _]
501−-- = do focus a
581+ = do focus a
502−-- fill (RConstant IType) -- default Int
582+ fill (RConstant IType) -- default Int
503−-- solve
583+ solve
504−-- return False
584+ return False
505 needsDefault t f as
585 needsDefault t f as
506 | all boundVar as = return True -- fail $ "Can't resolve " ++ show t
586 | all boundVar as = return True -- fail $ "Can't resolve " ++ show t
507 needsDefault t f a = return False -- trace (show t) $ return ()
587 needsDefault t f a = return False -- trace (show t) $ return ()
@@ -509,7 +589,9 @@ resolveTC depth fn ist
509 boundVar (P Bound _ _) = True
589 boundVar (P Bound _ _) = True
510 boundVar _ = False
590 boundVar _ = False
511
591
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
513 blunderbuss t d (n:ns)
595 blunderbuss t d (n:ns)
514 | n /= fn && tcname n = try' (resolve n d)
596 | n /= fn && tcname n = try' (resolve n d)
515 (blunderbuss t d ns) True
597 (blunderbuss t d ns) True
@@ -526,8 +608,11 @@ resolveTC depth fn ist
526 let imps = case lookupCtxtName Nothing n (idris_implicits ist) of
608 let imps = case lookupCtxtName Nothing n (idris_implicits ist) of
527 [] -> []
609 [] -> []
528 [args] -> map isImp (snd args) -- won't be overloaded!
610 [args] -> map isImp (snd args) -- won't be overloaded!
611+ ps <- get_probs
529 args <- apply (Var n) imps
612 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) $
531 mapM_ (\ (_,n) -> do focus n
616 mapM_ (\ (_,n) -> do focus n
532 t' <- goal
617 t' <- goal
533 let (tc', ttype) = unApply t'
618 let (tc', ttype) = unApply t'
@@ -535,6 +620,7 @@ resolveTC depth fn ist
535 resolveTC depth' fn ist)
620 resolveTC depth' fn ist)
536 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
621 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
537 -- if there's any arguments left, we've failed to resolve
622 -- if there's any arguments left, we've failed to resolve
623+ hs <- get_holes
538 solve
624 solve
539 where isImp (PImp p _ _ _ _) = (True, p)
625 where isImp (PImp p _ _ _ _) = (True, p)
540 isImp arg = (False, priority arg)
626 isImp arg = (False, priority arg)
src/Idris/Error.hs+3−3
@@ -20,7 +20,7 @@ import Data.Typeable
20iucheck :: Idris ()
20iucheck :: Idris ()
21iucheck = do tit <- typeInType
21iucheck = do tit <- typeInType
22 when (not tit) $
22 when (not tit) $
23− do ist <- get
23+ do ist <- getIState
24 idrisCatch (tclift $ ucheck (idris_constraints ist))
24 idrisCatch (tclift $ ucheck (idris_constraints ist))
25 (\e -> do let msg = show e
25 (\e -> do let msg = show e
26 setErrLine (getErrLine msg)
26 setErrLine (getErrLine msg)
@@ -46,13 +46,13 @@ ifail :: String -> Idris ()
46ifail str = throwIO (IErr str)
46ifail str = throwIO (IErr str)
47
47
48ierror :: Err -> Idris ()
48ierror :: Err -> Idris ()
49−ierror err = do i <- get
49+ierror err = do i <- getIState
50 throwIO (IErr $ pshow i err)
50 throwIO (IErr $ pshow i err)
51
51
52tclift :: TC a -> Idris a
52tclift :: TC a -> Idris a
53tclift tc = case tc of
53tclift tc = case tc of
54 OK v -> return v
54 OK v -> return v
55− Error err -> do i <- get
55+ Error err -> do i <- getIState
56 case err of
56 case err of
57 At (FC f l) e -> setErrLine l
57 At (FC f l) e -> setErrLine l
58 _ -> return ()
58 _ -> return ()
src/Idris/IBC.hs+6−4
@@ -21,7 +21,7 @@ import System.Directory
21import Paths_idris
21import Paths_idris
22
22
23ibcVersion :: Word8
23ibcVersion :: Word8
24−ibcVersion = 24
24+ibcVersion = 25
25
25
26data IBCFile = IBCFile { ver :: Word8,
26data IBCFile = IBCFile { ver :: Word8,
27 sourcefile :: FilePath,
27 sourcefile :: FilePath,
@@ -1535,11 +1535,13 @@ instance Binary OptInfo where
1535 return (Optimise x1 x2 x3)
1535 return (Optimise x1 x2 x3)
1536
1536
1537instance Binary TypeInfo where
1537instance Binary TypeInfo where
1538− put (TI x1 x2) = do put x1
1538+ put (TI x1 x2 x3) = do put x1
1539− put x2
1539+ put x2
1540+ put x3
1540 get = do x1 <- get
1541 get = do x1 <- get
1541 x2 <- get
1542 x2 <- get
1542− return (TI x1 x2)
1543+ x3 <- get
1544+ return (TI x1 x2 x3)
1543
1545
1544instance Binary SynContext where
1546instance Binary SynContext where
1545 put x
1547 put x
src/Idris/Parser.hs+12−11
@@ -63,12 +63,13 @@ fixErrorMsg msg fixes = msg ++ ", possible fixes:\n" ++ (concat $ intersperse "\
63loadModule :: FilePath -> Idris String
63loadModule :: FilePath -> Idris String
64loadModule f
64loadModule f
65 = idrisCatch (do i <- getIState
65 = idrisCatch (do i <- getIState
66+ let file = takeWhile (/= ' ') f
66 ibcsd <- valIBCSubDir i
67 ibcsd <- valIBCSubDir i
67 ids <- allImportDirs i
68 ids <- allImportDirs i
68− fp <- liftIO $ findImport ids ibcsd f
69+ fp <- liftIO $ findImport ids ibcsd file
69− if f `elem` imported i
70+ if file `elem` imported i
70− then iLOG $ "Already read " ++ f
71+ then iLOG $ "Already read " ++ file
71− else do putIState (i { imported = f : imported i })
72+ else do putIState (i { imported = file : imported i })
72 case fp of
73 case fp of
73 IDR fn -> loadSource False fn
74 IDR fn -> loadSource False fn
74 LIDR fn -> loadSource True fn
75 LIDR fn -> loadSource True fn
@@ -78,7 +79,7 @@ loadModule f
78 case src of
79 case src of
79 IDR sfn -> loadSource False sfn
80 IDR sfn -> loadSource False sfn
80 LIDR sfn -> loadSource True sfn)
81 LIDR sfn -> loadSource True sfn)
81− let (dir, fh) = splitFileName f
82+ let (dir, fh) = splitFileName file
82 return (dropExtension fh))
83 return (dropExtension fh))
83 (\e -> do let msg = show e
84 (\e -> do let msg = show e
84 setErrLine (getErrLine msg)
85 setErrLine (getErrLine msg)
@@ -110,7 +111,7 @@ loadSource lidr f
110 v <- verbose
111 v <- verbose
111 when v $ iputStrLn $ "Type checking " ++ f
112 when v $ iputStrLn $ "Type checking " ++ f
112 elabDecls toplevel ds
113 elabDecls toplevel ds
113− i <- get
114+ i <- getIState
114 -- simplify every definition do give the totality checker
115 -- simplify every definition do give the totality checker
115 -- a better chance
116 -- a better chance
116 mapM_ (\n -> do logLvl 5 $ "Simplifying " ++ show n
117 mapM_ (\n -> do logLvl 5 $ "Simplifying " ++ show n
@@ -118,7 +119,7 @@ loadSource lidr f
118 (map snd (idris_totcheck i))
119 (map snd (idris_totcheck i))
119 -- build size change graph from simplified definitions
120 -- build size change graph from simplified definitions
120 iLOG "Totality checking"
121 iLOG "Totality checking"
121− i <- get
122+ i <- getIState
122 mapM_ buildSCG (idris_totcheck i)
123 mapM_ buildSCG (idris_totcheck i)
123 mapM_ checkDeclTotality (idris_totcheck i)
124 mapM_ checkDeclTotality (idris_totcheck i)
124 iLOG ("Finished " ++ f)
125 iLOG ("Finished " ++ f)
@@ -162,7 +163,7 @@ parseTac i = runParser (do t <- pTactic defaultSyntax
162
163
163parseImports :: FilePath -> String -> Idris ([String], [String], String, SourcePos)
164parseImports :: FilePath -> String -> Idris ([String], [String], String, SourcePos)
164parseImports fname input
165parseImports fname input
165− = do i <- get
166+ = do i <- getIState
166 case runParser (do whiteSpace
167 case runParser (do whiteSpace
167 mname <- pHeader
168 mname <- pHeader
168 ps <- many pImport
169 ps <- many pImport
@@ -170,7 +171,7 @@ parseImports fname input
170 pos <- getPosition
171 pos <- getPosition
171 return ((mname, ps, rest, pos), i)) i fname input of
172 return ((mname, ps, rest, pos), i)) i fname input of
172 Left err -> fail (show err)
173 Left err -> fail (show err)
173− Right (x, i) -> do put i
174+ Right (x, i) -> do putIState i
174 return x
175 return x
175
176
176pHeader :: IParser [String]
177pHeader :: IParser [String]
@@ -275,7 +276,7 @@ pImport = do reserved "import"; f <- identifier; option ';' (lchar ';')
275parseProg :: SyntaxInfo -> FilePath -> String -> SourcePos ->
276parseProg :: SyntaxInfo -> FilePath -> String -> SourcePos ->
276 Idris [PDecl]
277 Idris [PDecl]
277parseProg syn fname input pos
278parseProg syn fname input pos
278− = do i <- get
279+ = do i <- getIState
279 case runParser (do setPosition pos
280 case runParser (do setPosition pos
280 whiteSpace
281 whiteSpace
281 ps <- many (pDecl syn)
282 ps <- many (pDecl syn)
@@ -284,7 +285,7 @@ parseProg syn fname input pos
284 return (concat ps, i')) i fname input of
285 return (concat ps, i')) i fname input of
285 Left err -> do iputStrLn (show err)
286 Left err -> do iputStrLn (show err)
286 return []
287 return []
287− Right (x, i) -> do put i
288+ Right (x, i) -> do putIState i
288 return (collect x)
289 return (collect x)
289
290
290-- Collect PClauses with the same function name
291-- Collect PClauses with the same function name
src/Idris/Prover.hs+30−13
@@ -13,8 +13,10 @@ import Idris.ElabTerm
13import Idris.Parser
13import Idris.Parser
14import Idris.Error
14import Idris.Error
15import Idris.DataOpts
15import Idris.DataOpts
16+import Idris.Completion
16
17
17import System.Console.Haskeline
18import System.Console.Haskeline
19+import System.Console.Haskeline.History
18import Control.Monad.State
20import Control.Monad.State
19
21
20import Util.Pretty
22import Util.Pretty
@@ -22,7 +24,7 @@ import Util.Pretty
22prover :: Bool -> Name -> Idris ()
24prover :: Bool -> Name -> Idris ()
23prover lit x =
25prover lit x =
24 do ctxt <- getContext
26 do ctxt <- getContext
25− i <- get
27+ i <- getIState
26 case lookupTy Nothing x ctxt of
28 case lookupTy Nothing x ctxt of
27 [t] -> if elem x (idris_metavars i)
29 [t] -> if elem x (idris_metavars i)
28 then prove ctxt lit x t
30 then prove ctxt lit x t
@@ -37,15 +39,23 @@ showProof lit n ps
37 where bird = if lit then "> " else ""
39 where bird = if lit then "> " else ""
38 break = "\n" ++ bird
40 break = "\n" ++ bird
39
41
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+
40prove :: Context -> Bool -> Name -> Type -> Idris ()
50prove :: Context -> Bool -> Name -> Type -> Idris ()
41prove ctxt lit n ty
51prove ctxt lit n ty
42− = do let ps = initElaborator n ctxt ty
52+ = do let ps = initElaborator n ctxt ty
43− (tm, prf) <- ploop True ("-" ++ show n) [] (ES (ps, []) "" Nothing)
53+ (tm, prf) <- ploop True ("-" ++ show n) [] (ES (ps, []) "" Nothing) Nothing
44 iLOG $ "Adding " ++ show tm
54 iLOG $ "Adding " ++ show tm
45 iputStrLn $ showProof lit n prf
55 iputStrLn $ showProof lit n prf
46− i <- get
56+ i <- getIState
47 let proofs = proof_list i
57 let proofs = proof_list i
48− put (i { proof_list = (n, prf) : proofs })
58+ putIState (i { proof_list = (n, prf) : proofs })
49 let tree = simpleCase False True CompileTime (FC "proof" 0) [([], P Ref n ty, tm)]
59 let tree = simpleCase False True CompileTime (FC "proof" 0) [([], P Ref n ty, tm)]
50 logLvl 3 (show tree)
60 logLvl 3 (show tree)
51 (ptm, pty) <- recheckC (FC "proof" 0) [] tm
61 (ptm, pty) <- recheckC (FC "proof" 0) [] tm
@@ -58,7 +68,7 @@ prove ctxt lit n ty
58elabStep :: ElabState [PDecl] -> ElabD a -> Idris (a, ElabState [PDecl])
68elabStep :: ElabState [PDecl] -> ElabD a -> Idris (a, ElabState [PDecl])
59elabStep st e = do case runStateT e st of
69elabStep st e = do case runStateT e st of
60 OK (a, st') -> return (a, st')
70 OK (a, st') -> return (a, st')
61− Error a -> do i <- get
71+ Error a -> do i <- getIState
62 fail (pshow i a)
72 fail (pshow i a)
63
73
64dumpState :: IState -> ProofState -> IO ()
74dumpState :: IState -> ProofState -> IO ()
@@ -108,18 +118,25 @@ lifte :: ElabState [PDecl] -> ElabD a -> Idris a
108lifte st e = do (v, _) <- elabStep st e
118lifte st e = do (v, _) <- elabStep st e
109 return v
119 return v
110
120
111−ploop :: Bool -> String -> [String] -> ElabState [PDecl] -> Idris (Term, [String])
121+ploop :: Bool -> String -> [String] -> ElabState [PDecl] -> Maybe History -> Idris (Term, [String])
112−ploop d prompt prf e
122+ploop d prompt prf e h
113− = do i <- get
123+ = do i <- getIState
114 when d $ liftIO $ dumpState i (proof e)
124 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')
116 (cmd, step) <- case x of
133 (cmd, step) <- case x of
117 Nothing -> fail "Abandoned"
134 Nothing -> fail "Abandoned"
118 Just input -> do return (parseTac i input, input)
135 Just input -> do return (parseTac i input, input)
119 case cmd of
136 case cmd of
120 Right Abandon -> fail "Abandoned"
137 Right Abandon -> fail "Abandoned"
121 _ -> return ()
138 _ -> return ()
122− (d, st, done, prf') <- idrisCatch
139+ (d, st, done, prf') <- idrisCatch
123 (case cmd of
140 (case cmd of
124 Left err -> do iputStrLn (show err)
141 Left err -> do iputStrLn (show err)
125 return (False, e, False, prf)
142 return (False, e, False, prf)
@@ -140,7 +157,7 @@ ploop d prompt prf e
140 return (True, st, False, prf ++ [step]))
157 return (True, st, False, prf ++ [step]))
141 (\err -> do iputStrLn (show err)
158 (\err -> do iputStrLn (show err)
142 return (False, e, False, prf))
159 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
144 return (tm, prf')
161 return (tm, prf')
145− else ploop d prompt prf' st
162+ else ploop d prompt prf' st h'
146
163
src/Idris/REPL.hs+53−46
@@ -16,6 +16,7 @@ import Idris.Primitives
16import Idris.Coverage
16import Idris.Coverage
17import Idris.UnusedArgs
17import Idris.UnusedArgs
18import Idris.Docs
18import Idris.Docs
19+import Idris.Completion
19
20
20import Paths_idris
21import Paths_idris
21import Util.System
22import Util.System
@@ -49,23 +50,23 @@ import Data.List
49import Data.Char
50import Data.Char
50import Data.Version
51import Data.Version
51
52
52−repl :: IState -> [FilePath] -> Idris ()
53+repl :: IState -> [FilePath] -> InputT Idris ()
53repl orig mods
54repl orig mods
54 = H.catch
55 = H.catch
55 (do let prompt = mkPrompt mods
56 (do let prompt = mkPrompt mods
56− x <- lift $ getInputLine (prompt ++ "> ")
57+ x <- getInputLine (prompt ++ "> ")
57 case x of
58 case x of
58− Nothing -> do iputStrLn "Bye bye"
59+ Nothing -> do lift $ iputStrLn "Bye bye"
59 return ()
60 return ()
60 Just input -> H.catch
61 Just input -> H.catch
61− (do ms <- processInput input orig mods
62+ (do ms <- lift $ processInput input orig mods
62 case ms of
63 case ms of
63 Just mods -> repl orig mods
64 Just mods -> repl orig mods
64 Nothing -> return ())
65 Nothing -> return ())
65 ctrlC)
66 ctrlC)
66 ctrlC
67 ctrlC
67− where ctrlC :: SomeException -> Idris ()
68+ where ctrlC :: SomeException -> InputT Idris ()
68− ctrlC e = do iputStrLn (show e)
69+ ctrlC e = do lift $ iputStrLn (show e)
69 repl orig mods
70 repl orig mods
70
71
71mkPrompt [] = "Idris"
72mkPrompt [] = "Idris"
@@ -78,7 +79,7 @@ lit f = case splitExtension f of
78
79
79processInput :: String -> IState -> [FilePath] -> Idris (Maybe [FilePath])
80processInput :: String -> IState -> [FilePath] -> Idris (Maybe [FilePath])
80processInput cmd orig inputs
81processInput cmd orig inputs
81− = do i <- get
82+ = do i <- getIState
82 let fn = case inputs of
83 let fn = case inputs of
83 (f:_) -> f
84 (f:_) -> f
84 _ -> ""
85 _ -> ""
@@ -86,12 +87,12 @@ processInput cmd orig inputs
86 Left err -> do liftIO $ print err
87 Left err -> do liftIO $ print err
87 return (Just inputs)
88 return (Just inputs)
88 Right Reload ->
89 Right Reload ->
89− do put (orig { idris_options = idris_options i })
90+ do putIState (orig { idris_options = idris_options i })
90 clearErr
91 clearErr
91 mods <- mapM loadModule inputs
92 mods <- mapM loadModule inputs
92 return (Just inputs)
93 return (Just inputs)
93 Right (Load f) ->
94 Right (Load f) ->
94− do put (orig { idris_options = idris_options i })
95+ do putIState (orig { idris_options = idris_options i })
95 clearErr
96 clearErr
96 mod <- loadModule f
97 mod <- loadModule f
97 return (Just [f])
98 return (Just [f])
@@ -111,7 +112,7 @@ processInput cmd orig inputs
111
112
112resolveProof :: Name -> Idris Name
113resolveProof :: Name -> Idris Name
113resolveProof n'
114resolveProof n'
114− = do i <- get
115+ = do i <- getIState
115 ctxt <- getContext
116 ctxt <- getContext
116 n <- case lookupNames Nothing n' ctxt of
117 n <- case lookupNames Nothing n' ctxt of
117 [x] -> return x
118 [x] -> return x
@@ -121,15 +122,15 @@ resolveProof n'
121
122
122removeProof :: Name -> Idris ()
123removeProof :: Name -> Idris ()
123removeProof n =
124removeProof n =
124− do i <- get
125+ do i <- getIState
125 let proofs = proof_list i
126 let proofs = proof_list i
126 let ps = filter ((/= n) . fst) proofs
127 let ps = filter ((/= n) . fst) proofs
127− put $ i { proof_list = ps }
128+ putIState $ i { proof_list = ps }
128
129
129edit :: FilePath -> IState -> Idris ()
130edit :: FilePath -> IState -> Idris ()
130edit "" orig = iputStrLn "Nothing to edit"
131edit "" orig = iputStrLn "Nothing to edit"
131edit f orig
132edit f orig
132− = do i <- get
133+ = do i <- getIState
133 env <- liftIO $ getEnvironment
134 env <- liftIO $ getEnvironment
134 let editor = getEditor env
135 let editor = getEditor env
135 let line = case errLine i of
136 let line = case errLine i of
@@ -138,7 +139,7 @@ edit f orig
138 let cmd = editor ++ line ++ f
139 let cmd = editor ++ line ++ f
139 liftIO $ system cmd
140 liftIO $ system cmd
140 clearErr
141 clearErr
141− put (orig { idris_options = idris_options i })
142+ putIState (orig { idris_options = idris_options i })
142 loadModule f
143 loadModule f
143 iucheck
144 iucheck
144 return ()
145 return ()
@@ -149,7 +150,7 @@ edit f orig
149
150
150proofs :: IState -> Idris ()
151proofs :: IState -> Idris ()
151proofs orig
152proofs orig
152− = do i <- get
153+ = do i <- getIState
153 let ps = proof_list i
154 let ps = proof_list i
154 case ps of
155 case ps of
155 [] -> iputStrLn "No proofs available"
156 [] -> iputStrLn "No proofs available"
@@ -166,7 +167,7 @@ process fn Help = iputStrLn displayHelp
166process fn (Eval t)
167process fn (Eval t)
167 = do (tm, ty) <- elabVal toplevel False t
168 = do (tm, ty) <- elabVal toplevel False t
168 ctxt <- getContext
169 ctxt <- getContext
169− ist <- get
170+ ist <- getIState
170 let tm' = normaliseAll ctxt [] tm
171 let tm' = normaliseAll ctxt [] tm
171 let ty' = normaliseAll ctxt [] ty
172 let ty' = normaliseAll ctxt [] ty
172 logLvl 3 $ "Raw: " ++ show (tm', ty')
173 logLvl 3 $ "Raw: " ++ show (tm', ty')
@@ -186,7 +187,7 @@ process fn (ExecVal t)
186 where fc = FC "(input)" 0
187 where fc = FC "(input)" 0
187process fn (Check (PRef _ n))
188process fn (Check (PRef _ n))
188 = do ctxt <- getContext
189 = do ctxt <- getContext
189− ist <- get
190+ ist <- getIState
190 imp <- impShow
191 imp <- impShow
191 case lookupTy Nothing n ctxt of
192 case lookupTy Nothing n ctxt of
192 ts@(_:_) -> mapM_ (\t -> iputStrLn $ show n ++ " : " ++
193 ts@(_:_) -> mapM_ (\t -> iputStrLn $ show n ++ " : " ++
@@ -194,20 +195,20 @@ process fn (Check (PRef _ n))
194 [] -> iputStrLn $ "No such variable " ++ show n
195 [] -> iputStrLn $ "No such variable " ++ show n
195process fn (Check t) = do (tm, ty) <- elabVal toplevel False t
196process fn (Check t) = do (tm, ty) <- elabVal toplevel False t
196 ctxt <- getContext
197 ctxt <- getContext
197− ist <- get
198+ ist <- getIState
198 imp <- impShow
199 imp <- impShow
199 let ty' = normaliseC ctxt [] ty
200 let ty' = normaliseC ctxt [] ty
200 iputStrLn (showImp imp (delab ist tm) ++ " : " ++
201 iputStrLn (showImp imp (delab ist tm) ++ " : " ++
201 showImp imp (delab ist ty))
202 showImp imp (delab ist ty))
202
203
203−process fn (DocStr n) = do i <- get
204+process fn (DocStr n) = do i <- getIState
204 case lookupCtxtName Nothing n (idris_docstrings i) of
205 case lookupCtxtName Nothing n (idris_docstrings i) of
205 [] -> iputStrLn $ "No documentation for " ++ show n
206 [] -> iputStrLn $ "No documentation for " ++ show n
206 ns -> mapM_ showDoc ns
207 ns -> mapM_ showDoc ns
207 where showDoc (n, d)
208 where showDoc (n, d)
208 = do doc <- getDocs n
209 = do doc <- getDocs n
209 iputStrLn $ show doc
210 iputStrLn $ show doc
210−process fn Universes = do i <- get
211+process fn Universes = do i <- getIState
211 let cs = idris_constraints i
212 let cs = idris_constraints i
212-- iputStrLn $ showSep "\n" (map show cs)
213-- iputStrLn $ showSep "\n" (map show cs)
213 liftIO $ print (map fst cs)
214 liftIO $ print (map fst cs)
@@ -216,7 +217,7 @@ process fn Universes = do i <- get
216 case ucheck cs of
217 case ucheck cs of
217 Error e -> iputStrLn $ pshow i e
218 Error e -> iputStrLn $ pshow i e
218 OK _ -> iputStrLn "Universes OK"
219 OK _ -> iputStrLn "Universes OK"
219−process fn (Defn n) = do i <- get
220+process fn (Defn n) = do i <- getIState
220 iputStrLn "Compiled patterns:\n"
221 iputStrLn "Compiled patterns:\n"
221 liftIO $ print (lookupDef Nothing n (tt_ctxt i))
222 liftIO $ print (lookupDef Nothing n (tt_ctxt i))
222 case lookupCtxt Nothing n (idris_patdefs i) of
223 case lookupCtxt Nothing n (idris_patdefs i) of
@@ -230,40 +231,42 @@ process fn (Defn n) = do i <- get
230 = do liftIO $ putStr $ showImp True (delab i lhs)
231 = do liftIO $ putStr $ showImp True (delab i lhs)
231 liftIO $ putStr " = "
232 liftIO $ putStr " = "
232 liftIO $ putStrLn $ showImp True (delab i rhs)
233 liftIO $ putStrLn $ showImp True (delab i rhs)
233−process fn (TotCheck n) = do i <- get
234+process fn (TotCheck n) = do i <- getIState
234 case lookupTotal n (tt_ctxt i) of
235 case lookupTotal n (tt_ctxt i) of
235 [t] -> iputStrLn (showTotal t i)
236 [t] -> iputStrLn (showTotal t i)
236 _ -> return ()
237 _ -> return ()
237process fn (DebugInfo n)
238process fn (DebugInfo n)
238− = do i <- get
239+ = do i <- getIState
239 let oi = lookupCtxtName Nothing n (idris_optimisation i)
240 let oi = lookupCtxtName Nothing n (idris_optimisation i)
240 when (not (null oi)) $ iputStrLn (show oi)
241 when (not (null oi)) $ iputStrLn (show oi)
241 let si = lookupCtxt Nothing n (idris_statics i)
242 let si = lookupCtxt Nothing n (idris_statics i)
242 when (not (null si)) $ iputStrLn (show si)
243 when (not (null si)) $ iputStrLn (show si)
244+ let di = lookupCtxt Nothing n (idris_datatypes i)
245+ when (not (null di)) $ iputStrLn (show di)
243 let d = lookupDef Nothing n (tt_ctxt i)
246 let d = lookupDef Nothing n (tt_ctxt i)
244 when (not (null d)) $ liftIO $
247 when (not (null d)) $ liftIO $
245 do print (head d)
248 do print (head d)
246 let cg = lookupCtxtName Nothing n (idris_callgraph i)
249 let cg = lookupCtxtName Nothing n (idris_callgraph i)
247 findUnusedArgs (map fst cg)
250 findUnusedArgs (map fst cg)
248− i <- get
251+ i <- getIState
249 let cg' = lookupCtxtName Nothing n (idris_callgraph i)
252 let cg' = lookupCtxtName Nothing n (idris_callgraph i)
250 sc <- checkSizeChange n
253 sc <- checkSizeChange n
251 iputStrLn $ "Size change: " ++ show sc
254 iputStrLn $ "Size change: " ++ show sc
252 when (not (null cg')) $ do iputStrLn "Call graph:\n"
255 when (not (null cg')) $ do iputStrLn "Call graph:\n"
253 iputStrLn (show cg')
256 iputStrLn (show cg')
254−process fn (Info n) = do i <- get
257+process fn (Info n) = do i <- getIState
255 case lookupCtxt Nothing n (idris_classes i) of
258 case lookupCtxt Nothing n (idris_classes i) of
256 [c] -> classInfo c
259 [c] -> classInfo c
257 _ -> iputStrLn "Not a class"
260 _ -> iputStrLn "Not a class"
258process fn (Search t) = iputStrLn "Not implemented"
261process fn (Search t) = iputStrLn "Not implemented"
259process fn (Spec t) = do (tm, ty) <- elabVal toplevel False t
262process fn (Spec t) = do (tm, ty) <- elabVal toplevel False t
260 ctxt <- getContext
263 ctxt <- getContext
261− ist <- get
264+ ist <- getIState
262 let tm' = simplify ctxt True [] {- (idris_statics ist) -} tm
265 let tm' = simplify ctxt True [] {- (idris_statics ist) -} tm
263 iputStrLn (show (delab ist tm'))
266 iputStrLn (show (delab ist tm'))
264
267
265process fn (RmProof n')
268process fn (RmProof n')
266− = do i <- get
269+ = do i <- getIState
267 n <- resolveProof n'
270 n <- resolveProof n'
268 let proofs = proof_list i
271 let proofs = proof_list i
269 case lookup n proofs of
272 case lookup n proofs of
@@ -274,15 +277,15 @@ process fn (RmProof n')
274 where
277 where
275 insertMetavar :: Name -> Idris ()
278 insertMetavar :: Name -> Idris ()
276 insertMetavar n =
279 insertMetavar n =
277− do i <- get
280+ do i <- getIState
278 let ms = idris_metavars i
281 let ms = idris_metavars i
279− put $ i { idris_metavars = n : ms }
282+ putIState $ i { idris_metavars = n : ms }
280
283
281process fn (AddProof prf)
284process fn (AddProof prf)
282 = do let fb = fn ++ "~"
285 = do let fb = fn ++ "~"
283 liftIO $ copyFile fn fb -- make a backup in case something goes wrong!
286 liftIO $ copyFile fn fb -- make a backup in case something goes wrong!
284 prog <- liftIO $ readFile fb
287 prog <- liftIO $ readFile fb
285− i <- get
288+ i <- getIState
286 let proofs = proof_list i
289 let proofs = proof_list i
287 n' <- case prf of
290 n' <- case prf of
288 Nothing -> case proofs of
291 Nothing -> case proofs of
@@ -299,7 +302,7 @@ process fn (AddProof prf)
299 where ls = (lines prog)
302 where ls = (lines prog)
300
303
301process fn (ShowProof n')
304process fn (ShowProof n')
302− = do i <- get
305+ = do i <- getIState
303 n <- resolveProof n'
306 n <- resolveProof n'
304 let proofs = proof_list i
307 let proofs = proof_list i
305 case lookup n proofs of
308 case lookup n proofs of
@@ -308,26 +311,26 @@ process fn (ShowProof n')
308
311
309process fn (Prove n')
312process fn (Prove n')
310 = do ctxt <- getContext
313 = do ctxt <- getContext
311− ist <- get
314+ ist <- getIState
312 n <- case lookupNames Nothing n' ctxt of
315 n <- case lookupNames Nothing n' ctxt of
313 [x] -> return x
316 [x] -> return x
314 [] -> return n'
317 [] -> return n'
315 ns -> fail $ pshow ist (CantResolveAlts (map show ns))
318 ns -> fail $ pshow ist (CantResolveAlts (map show ns))
316 prover (lit fn) n
319 prover (lit fn) n
317 -- recheck totality
320 -- recheck totality
318− i <- get
321+ i <- getIState
319 totcheck (FC "(input)" 0, n)
322 totcheck (FC "(input)" 0, n)
320 mapM_ (\ (f,n) -> setTotality n Unchecked) (idris_totcheck i)
323 mapM_ (\ (f,n) -> setTotality n Unchecked) (idris_totcheck i)
321 mapM_ checkDeclTotality (idris_totcheck i)
324 mapM_ checkDeclTotality (idris_totcheck i)
322
325
323process fn (HNF t) = do (tm, ty) <- elabVal toplevel False t
326process fn (HNF t) = do (tm, ty) <- elabVal toplevel False t
324 ctxt <- getContext
327 ctxt <- getContext
325− ist <- get
328+ ist <- getIState
326 let tm' = hnf ctxt [] tm
329 let tm' = hnf ctxt [] tm
327 iputStrLn (show (delab ist tm'))
330 iputStrLn (show (delab ist tm'))
328−process fn TTShell = do ist <- get
331+process fn TTShell = do ist <- getIState
329 let shst = initState (tt_ctxt ist)
332 let shst = initState (tt_ctxt ist)
330− shst' <- lift $ runShell shst
333+ runShell shst
331 return ()
334 return ()
332process fn Execute = do (m, _) <- elabVal toplevel False
335process fn Execute = do (m, _) <- elabVal toplevel False
333 (PApp fc
336 (PApp fc
@@ -359,7 +362,7 @@ process fn (Pattelab t)
359 = do (tm, ty) <- elabVal toplevel True t
362 = do (tm, ty) <- elabVal toplevel True t
360 iputStrLn $ show tm ++ "\n\n : " ++ show ty
363 iputStrLn $ show tm ++ "\n\n : " ++ show ty
361
364
362−process fn (Missing n) = do i <- get
365+process fn (Missing n) = do i <- getIState
363 case lookupDef Nothing n (tt_ctxt i) of
366 case lookupDef Nothing n (tt_ctxt i) of
364 [CaseOp _ _ _ _ _ args t _ _]
367 [CaseOp _ _ _ _ _ args t _ _]
365 -> do tms <- genMissing n args t
368 -> do tms <- genMissing n args t
@@ -367,7 +370,7 @@ process fn (Missing n) = do i <- get
367 [] -> iputStrLn $ show n ++ " undefined"
370 [] -> iputStrLn $ show n ++ " undefined"
368 _ -> iputStrLn $ "Ambiguous name"
371 _ -> iputStrLn $ "Ambiguous name"
369process fn Metavars
372process fn Metavars
370− = do ist <- get
373+ = do ist <- getIState
371 let mvs = idris_metavars ist \\ primDefs
374 let mvs = idris_metavars ist \\ primDefs
372 case mvs of
375 case mvs of
373 [] -> iputStrLn "No global metavariables to solve"
376 [] -> iputStrLn "No global metavariables to solve"
@@ -394,7 +397,7 @@ dumpMethod :: (Name, (FnOpts, PTerm)) -> Idris ()
394dumpMethod (n, (_, t)) = iputStrLn $ show n ++ " : " ++ show t
397dumpMethod (n, (_, t)) = iputStrLn $ show n ++ " : " ++ show t
395
398
396dumpInstance :: Name -> Idris ()
399dumpInstance :: Name -> Idris ()
397−dumpInstance n = do i <- get
400+dumpInstance n = do i <- getIState
398 ctxt <- getContext
401 ctxt <- getContext
399 imp <- impShow
402 imp <- impShow
400 case lookupTy Nothing n ctxt of
403 case lookupTy Nothing n ctxt of
@@ -487,12 +490,16 @@ help =
487 ([":q",":quit"], "", "Exit the Idris system")
490 ([":q",":quit"], "", "Exit the Idris system")
488 ]
491 ]
489
492
493+
494+replSettings :: Settings Idris
495+replSettings = setComplete replCompletion defaultSettings
496+
490-- invoke as if from command line
497-- invoke as if from command line
491idris :: [Opt] -> IO IState
498idris :: [Opt] -> IO IState
492−idris opts = runInputT defaultSettings $ execStateT (idrisMain opts) idrisInit
499+idris opts = execStateT (idrisMain opts) idrisInit
493
500
494idrisMain :: [Opt] -> Idris ()
501idrisMain :: [Opt] -> Idris ()
495−idrisMain opts =
502+idrisMain opts =
496 do let inputs = opt getFile opts
503 do let inputs = opt getFile opts
497 let runrepl = not (NoREPL `elem` opts)
504 let runrepl = not (NoREPL `elem` opts)
498 let output = opt getOutput opts
505 let output = opt getOutput opts
@@ -508,8 +515,8 @@ idrisMain opts =
508 let tgt = case opt getTarget opts of
515 let tgt = case opt getTarget opts of
509 [] -> ViaC
516 [] -> ViaC
510 xs -> last xs
517 xs -> last xs
511− when (DefaultTotal `elem` opts) $ do i <- get
518+ when (DefaultTotal `elem` opts) $ do i <- getIState
512− put (i { default_total = True })
519+ putIState (i { default_total = True })
513 setREPL runrepl
520 setREPL runrepl
514 setVerbose runrepl
521 setVerbose runrepl
515 setCmdLine opts
522 setCmdLine opts
@@ -534,8 +541,8 @@ idrisMain opts =
534 elabPrims
541 elabPrims
535 when (not (NoPrelude `elem` opts)) $ do x <- loadModule "Prelude"
542 when (not (NoPrelude `elem` opts)) $ do x <- loadModule "Prelude"
536 return ()
543 return ()
537− when runrepl $ iputStrLn banner
544+ when runrepl $ iputStrLn banner
538− ist <- get
545+ ist <- getIState
539 mods <- mapM loadModule inputs
546 mods <- mapM loadModule inputs
540 ok <- noErrors
547 ok <- noErrors
541 when ok $ case output of
548 when ok $ case output of
@@ -544,7 +551,7 @@ idrisMain opts =
544 when ok $ case newoutput of
551 when ok $ case newoutput of
545 [] -> return ()
552 [] -> return ()
546 (o:_) -> process "" (NewCompile o)
553 (o:_) -> process "" (NewCompile o)
547− when runrepl $ repl ist inputs
554+ when runrepl $ runInputT replSettings $ repl ist inputs
548 ok <- noErrors
555 ok <- noErrors
549 when (not ok) $ liftIO (exitWith (ExitFailure 1))
556 when (not ok) $ liftIO (exitWith (ExitFailure 1))
550 where
557 where
src/Idris/UnusedArgs.hs+2−2
@@ -14,7 +14,7 @@ findUnusedArgs ns = mapM_ traceUnused ns
14
14
15traceUnused :: Name -> Idris ()
15traceUnused :: Name -> Idris ()
16traceUnused n
16traceUnused n
17− = do i <- get
17+ = do i <- getIState
18 case lookupCtxt Nothing n (idris_callgraph i) of
18 case lookupCtxt Nothing n (idris_callgraph i) of
19 [CGInfo args calls scg usedns _] ->
19 [CGInfo args calls scg usedns _] ->
20 do let argpos = zip args [0..]
20 do let argpos = zip args [0..]
@@ -38,7 +38,7 @@ used path g j
38 | (g, j) `elem` path = return False -- cycle, never used on the way
38 | (g, j) `elem` path = return False -- cycle, never used on the way
39 | otherwise
39 | otherwise
40 = do logLvl 5 $ (show ((g, j) : path))
40 = do logLvl 5 $ (show ((g, j) : path))
41− i <- get
41+ i <- getIState
42 case lookupCtxt Nothing g (idris_callgraph i) of
42 case lookupCtxt Nothing g (idris_callgraph i) of
43 [CGInfo args calls scg usedns unused] ->
43 [CGInfo args calls scg usedns unused] ->
44 if (j >= length args)
44 if (j >= length args)
src/Main.hs+1−1
@@ -39,7 +39,7 @@ import Paths_idris
39
39
40main = do xs <- getArgs
40main = do xs <- getArgs
41 let opts = parseArgs xs
41 let opts = parseArgs xs
42− runInputT defaultSettings $ execStateT (runIdris opts) idrisInit
42+ execStateT (runIdris opts) idrisInit
43
43
44runIdris :: [Opt] -> Idris ()
44runIdris :: [Opt] -> Idris ()
45runIdris opts = do
45runIdris opts = do
test/reg002/reg002.idr+2−2
@@ -13,10 +13,10 @@ S Infinity = Infinity
13Sn_notzero : Main.S n = Co 0 -> _|_
13Sn_notzero : Main.S n = Co 0 -> _|_
14Sn_notzero = believe_me
14Sn_notzero = believe_me
15
15
16−S_Co_not_Inf : S (Co n) = Infinity -> _|_
16+S_Co_not_Inf : Main.S (Co n) = Infinity -> _|_
17S_Co_not_Inf = believe_me
17S_Co_not_Inf = believe_me
18
18
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
20S_inj (Co n) (Co _) refl = refl
20S_inj (Co n) (Co _) refl = refl
21S_inj (Co n) Infinity p = FalseElim (S_Co_not_Inf p)
21S_inj (Co n) Infinity p = FalseElim (S_Co_not_Inf p)
22S_inj Infinity (Co m) p = FalseElim (S_Co_not_Inf (sym p))
22S_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
18rle : (xs : Vect Char n) -> RLE xs
18rle : (xs : Vect Char n) -> RLE xs
19rle [] = REnd
19rle [] = REnd
20rle (x :: xs) with (rle xs)
20rle (x :: xs) with (rle xs)
21− rle (x :: []) | REnd = RChar O x REnd
21+ rle (x :: Vect.Nil) | REnd = RChar O x REnd
22 rle (x :: rep (S n) yvar ++ ys) | RChar n yvar rs with (eq x yvar)
22 rle (x :: rep (S n) yvar ++ ys) | RChar n yvar rs with (eq x yvar)
23 rle (x :: rep (S n) x ++ ys) | RChar n x rs | Just p
23 rle (x :: rep (S n) x ++ ys) | RChar n x rs | Just p
24 = RChar (S n) x rs
24 = RChar (S n) x rs
test/reg008/reg008.idr+1−1
@@ -8,7 +8,7 @@ data Cmp : Nat -> Nat -> Type where
8total cmp : (x, y : Nat) -> Cmp x y
8total cmp : (x, y : Nat) -> Cmp x y
9cmp O O = cmpEQ
9cmp O O = cmpEQ
10cmp O (S k) = cmpLT _
10cmp O (S k) = cmpLT _
11−cmp (S k) O = cmpGT _
11+cmp (S k) O = cmpGT _
12cmp (S x) (S y) with (cmp x y)
12cmp (S x) (S y) with (cmp x y)
13 cmp (S x) (S (x + (S k))) | cmpLT k = cmpLT k
13 cmp (S x) (S (x + (S k))) | cmpLT k = cmpLT k
14 cmp (S x) (S x) | cmpEQ = cmpEQ
14 cmp (S x) (S x) | cmpEQ = cmpEQ
test/reg009/reg009.lidr+1−1
@@ -7,7 +7,7 @@
7> (as : Vect alpha n) ->
7> (as : Vect alpha n) ->
8> so (isAnyBy p (n ** as)) ->
8> so (isAnyBy p (n ** as)) ->
9> (m : Nat ** (Vect (a : alpha ** so (p a)) m, so (m > O)))
9> (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)
11> | True = (_
11> | True = (_
12> **
12> **
13> ((a ** believe_me oh)
13> ((a ** believe_me oh)
test/test005/test005.idr+6−7
@@ -7,10 +7,9 @@ tlist : List Int
7tlist = [1, 2, 3, 4, 5]
7tlist = [1, 2, 3, 4, 5]
8
8
9main : IO ()
9main : IO ()
10−main = do { print (abs (-8))
10+main = do print (abs (-8))
11− print (abs (S O))
11+ print (abs (S O))
12− print (span isAlpha tstr)
12+ print (span isAlpha tstr)
13− print (break isDigit tstr)
13+ print (break isDigit tstr)
14− print (span (\x => x < 3) tlist)
14+ print (span (\x => x < 3) tlist)
15− print (break (\x => x > 2) tlist)
15+ print (break (\x => x > 2) tlist)
16− }
test/test006/test006.idr+4−4
@@ -8,14 +8,14 @@ parity : (n:Nat) -> Parity n
8parity O = even {n=O}
8parity O = even {n=O}
9parity (S O) = odd {n=O}
9parity (S O) = odd {n=O}
10parity (S (S k)) with (parity k)
10parity (S (S k)) with (parity k)
11− parity (S (S (j + j))) | even ?= even {n=S j}
11+ parity (S (S (j + j))) | (even {n = j}) ?= even {n=S j}
12− parity (S (S (S (j + j)))) | odd ?= odd {n=S j}
12+ parity (S (S (S (j + j)))) | (odd {n = j}) ?= odd {n=S j}
13
13
14natToBin : Nat -> List Bool
14natToBin : Nat -> List Bool
15natToBin O = Nil
15natToBin O = Nil
16natToBin k with (parity k)
16natToBin k with (parity k)
17− natToBin (j + j) | even = False :: natToBin j
17+ natToBin (j + j) | even {n = j} = False :: natToBin j
18− natToBin (S (j + j)) | odd = True :: natToBin j
18+ natToBin (S (j + j)) | odd {n = j} = True :: natToBin j
19
19
20main : IO ()
20main : IO ()
21main = do print (natToBin 42)
21main = do print (natToBin 42)
test/test007/test007.idr+1−2
@@ -35,8 +35,7 @@ runEval env e with (eval e) {
35}
35}
36
36
37main : IO ()
37main : IO ()
38−main = do print [| (*2) (Just 4) |]
38+main = do print [| (\x => x *2) (Just 4) |]
39 print [| plus (Just 4) (Just 5) |]
39 print [| plus (Just 4) (Just 5) |]
40 print (runEval [("x",21), ("y", 20)] (Add (Val 1) (Add (Var "x") (Var "y"))))
40 print (runEval [("x",21), ("y", 20)] (Add (Val 1) (Add (Var "x") (Var "y"))))
41 print (runEval [("x",21)] (Add (Val 1) (Add (Var "x") (Var "y"))))
41 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)
109 (>>=) : Res gam gam' (R a) -> (a -> Res gam' gam'' (R t)) ->
109 (>>=) : Res gam gam' (R a) -> (a -> Res gam' gam'' (R t)) ->
110 Res gam gam'' (R t)
110 Res gam gam'' (R t)
111
111
112+ ioret : a -> IO a
113+ ioret = return
112
114
113 interp : Env gam -> {static} Res gam gam' t ->
115 interp : Env gam -> {static} Res gam gam' t ->
114 (Env gam' -> interpTy t -> IO u) -> IO u
116 (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
20 (#) : Binary w v -> Bit bit -> Binary (S w) (bit + 2 * v)
20 (#) : Binary w v -> Bit bit -> Binary (S w) (bit + 2 * v)
21
21
22instance Show (Binary w k) where
22instance Show (Binary w k) where
23− show = show' where
23+ show zero = ""
24− show' : Binary w' k' -> String
24+ show (bin # bit) = show bin ++ show bit
25− show' zero = ""
26− show' (bin # bit) = show bin ++ show bit
27
25
28pad : Binary w n -> Binary (S w) n
26pad : Binary w n -> Binary (S w) n
29pad zero = zero # b0
27pad zero = zero # b0
test/test018/test018a.idr+2−2
@@ -13,8 +13,8 @@ ping main proc
13
13
14pong : Process String ()
14pong : Process String ()
15pong = do -- lift (putStrLn "Waiting for message")
15pong = do -- lift (putStrLn "Waiting for message")
16− (sender, msg) <- recvWithSender
16+ (sender, m) <- recvWithSender
17− lift $ putStrLn ("Received " ++ msg)
17+ lift $ putStrLn ("Received " ++ m)
18 send sender ("Hello back!")
18 send sender ("Hello back!")
19
19
20mainProc : Process String ()
20mainProc : Process String ()
tutorial/classes.tex+25−18
@@ -63,7 +63,7 @@ to a \texttt{String}:
63
63
64instance Show a => Show (Vect a n) where
64instance Show a => Show (Vect a n) where
65 show xs = "[" ++ show' xs ++ "]" where
65 show xs = "[" ++ show' xs ++ "]" where
66− show' : Vect a n' -> String
66+ show' : Vect a n -> String
67 show' Nil = ""
67 show' Nil = ""
68 show' (x :: Nil) = show x
68 show' (x :: Nil) = show x
69 show' (x :: xs) = show x ++ ", " ++ show' xs
69 show' (x :: xs) = show x ++ ", " ++ show' xs
@@ -71,14 +71,14 @@ instance Show a => Show (Vect a n) where
71\end{SaveVerbatim}
71\end{SaveVerbatim}
72\useverb{showvec}
72\useverb{showvec}
73
73
74−\noindent
74+%\noindent
75−\textbf{Remark: } The type of the auxiliary function \texttt{show'} is
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
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
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}
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
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,
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'}.
81+%we use a different name for the length \texttt{n'} in \texttt{show'}.
82
82
83\subsection{Default Definitions}
83\subsection{Default Definitions}
84
84
@@ -355,9 +355,10 @@ m_add' x y = m_app (m_app (Just (+)) x) y
355\useverb{maddb}
355\useverb{maddb}
356
356
357\noindent
357\noindent
358−Rather than having to insert \texttt{m\_app} everywhere there is an application, we can
358+Rather than having to insert \texttt{m\_app} everywhere there is an
359−use \remph{idiom brackets} to do the job for us. To do this, we use the \texttt{Applicative}
359+application, we can use \remph{idiom brackets} to do the job for us. To do
360−class, which captures the notion of application for a data type:
360+this, we use the \texttt{Applicative} class, which captures the notion of
361+application for a data type:
361
362
362\begin{SaveVerbatim}{applicative}
363\begin{SaveVerbatim}{applicative}
363
364
@@ -371,8 +372,8 @@ class Applicative (f : Type -> Type) where
371\useverb{applicative}
372\useverb{applicative}
372
373
373\noindent
374\noindent
374−\texttt{Maybe} is made an instance of \texttt{Applicative} as follows, where \texttt{<\$>}
375+\texttt{Maybe} is made an instance of \texttt{Applicative} as follows, where
375−is defined in the same way as \texttt{m\_app} above:
376+\texttt{<\$>} is defined in the same way as \texttt{m\_app} above:
376
377
377\begin{SaveVerbatim}{maybeapp}
378\begin{SaveVerbatim}{maybeapp}
378
379
@@ -443,15 +444,21 @@ fetch x = MkEval (\e => fetchVal e) where
443\useverb{fetch}
444\useverb{fetch}
444
445
445\noindent
446\noindent
446−When defining an evaluator for the language, we will be applying functions in the
447+When defining an evaluator for the language, we will be applying functions in
447−context of an \texttt{Eval}, so it is natural to make \texttt{Eval} an instance
448+the context of an \texttt{Eval}, so it is natural to make \texttt{Eval} an
448−of \texttt{Applicative}:
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}:
449
453
450\begin{SaveVerbatim}{}
454\begin{SaveVerbatim}{}
451
455
456+instance Functor Eval where
457+ fmap f (MkEval g) = MkEval (\e => fmap f (g e))
458+
452instance Applicative Eval where
459instance Applicative Eval where
453 pure x = MkEval (\e => Just x)
460 pure x = MkEval (\e => Just x)
454−
461+
455 (<$>) (MkEval f) (MkEval g) = MkEval (\x => app (f x) (g x)) where
462 (<$>) (MkEval f) (MkEval g) = MkEval (\x => app (f x) (g x)) where
456 app : Maybe (a -> b) -> Maybe a -> Maybe b
463 app : Maybe (a -> b) -> Maybe a -> Maybe b
457 app (Just fx) (Just gx) = Just (fx gx)
464 app (Just fx) (Just gx) = Just (fx gx)
tutorial/examples/binary.idr+3−5
@@ -6,11 +6,9 @@ data Binary : Nat -> Type where
6 bI : Binary n -> Binary (S (n + n))
6 bI : Binary n -> Binary (S (n + n))
7
7
8instance Show (Binary n) where
8instance Show (Binary n) where
9− show = show' where
9+ show (bO x) = show x ++ "0"
10− show' : Binary n' -> String
10+ show (bI x) = show x ++ "1"
11− show' (bO x) = show x ++ "0"
11+ show bEnd = ""
12− show' (bI x) = show x ++ "1"
13− show' bEnd = ""
14
12
15data Parity : Nat -> Type where
13data Parity : Nat -> Type where
16 even : Parity (n + n)
14 even : Parity (n + n)
tutorial/examples/interp.idr+3
@@ -44,6 +44,9 @@ using (G : Vect Ty n)
44
44
45 eAdd : Expr G (TyFun TyInt (TyFun TyInt TyInt))
45 eAdd : Expr G (TyFun TyInt (TyFun TyInt TyInt))
46 eAdd = Lam (Lam (Op (+) (Var stop) (Var (pop stop))))
46 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))))
47
50
48 eDouble : Expr G (TyFun TyInt TyInt)
51 eDouble : Expr G (TyFun TyInt TyInt)
49 eDouble = Lam (App (App eAdd (Var stop)) (Var stop))
52 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}.
344$ idris interp.idr
344$ idris interp.idr
345 ____ __ _
345 ____ __ _
346 / _/___/ /____(_)____
346 / _/___/ /____(_)____
347− / // __ / ___/ / ___/ Version 0.9.5
347+ / // __ / ___/ / ___/ Version 0.9.6
348 _/ // /_/ / / / (__ ) http://www.idris-lang.org/
348 _/ // /_/ / / / (__ ) http://www.idris-lang.org/
349 /___/\__,_/_/ /_/____/ Type :? for help
349 /___/\__,_/_/ /_/____/ Type :? for help
350
350
tutorial/intro.tex+1−1
@@ -62,7 +62,7 @@ verifying systems software.
62\subsection{Example Code}
62\subsection{Example Code}
63
63
64This tutorial includes some example code, which has been tested with \Idris{} version
64This 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,
66so that you can try them out easily,
66so that you can try them out easily,
67under \texttt{tutorial/examples}. However, it is strongly recommended that you
67under \texttt{tutorial/examples}. However, it is strongly recommended that you
68type them in yourself, rather than simply loading and reading them.
68type 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:
79$ idris
79$ idris
80 ____ __ _
80 ____ __ _
81 / _/___/ /____(_)____
81 / _/___/ /____(_)____
82− / // __ / ___/ / ___/ Version 0.9.5
82+ / // __ / ___/ / ___/ Version 0.9.6
83 _/ // /_/ / / / (__ ) http://www.idris-lang.org/
83 _/ // /_/ / / / (__ ) http://www.idris-lang.org/
84 /___/\__,_/_/ /_/____/ Type :? for help
84 /___/\__,_/_/ /_/____/ Type :? for help
85
85
@@ -99,7 +99,7 @@ as shown in Figure \ref{cmds}. Figure \ref{run1} shows an example run in which
99the program is compiled to the executable \texttt{hello}.
99the program is compiled to the executable \texttt{hello}.
100
100
101\begin{SaveVerbatim}{cmds}
101\begin{SaveVerbatim}{cmds}
102−Idris version 0.9.5
102+Idris version 0.9.6
103-------------------
103-------------------
104
104
105 Command Arguments Purpose
105 Command Arguments Purpose
@@ -134,7 +134,7 @@ Idris version 0.9.5
134$ idris hello.idr
134$ idris hello.idr
135 ____ __ _
135 ____ __ _
136 / _/___/ /____(_)____
136 / _/___/ /____(_)____
137− / // __ / ___/ / ___/ Version 0.9.5
137+ / // __ / ___/ / ___/ Version 0.9.6
138 _/ // /_/ / / / (__ ) http://www.idris-lang.org/
138 _/ // /_/ / / / (__ ) http://www.idris-lang.org/
139 /___/\__,_/_/ /_/____/ Type :? for help
139 /___/\__,_/_/ /_/____/ Type :? for help
140
140
tutorial/typesfuns.tex+6−18
@@ -210,24 +210,12 @@ Indentation is significant --- functions in the \texttt{where} block must be ind
210further than the outer function.
210further than the outer function.
211
211
212\textbf{Scope:}
212\textbf{Scope:}
213−Any names which are visible in the outer scope are also visible in the \texttt{where}
213+Any names which are visible in the outer scope are also visible in the
214−clause (unless they have been redefined, such as \texttt{xs} here).
214+\texttt{where} clause (unless they have been redefined, such as \texttt{xs}
215−\emph{However}, names which appear in the type are \emph{not} in scope. In particular,
215+here). A name which appears only in the type will be in scope in the
216−in the above example, the \texttt{a} in the top level type and the \texttt{a} in the
216+\texttt{where} clause if it is a \remph{parameter} to one of the types,
217−auxiliary definifion \texttt{revAcc} are \emph{not} the same. If this is the required
217+i.e. it is fixed across the entire structure.
218−behaviour, the \texttt{a} can be brought into scope as follows:
219
218
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
231As well as functions, \texttt{where} blocks can include local data
219As well as functions, \texttt{where} blocks can include local data
232declarations, such as the following where \texttt{MyLT} is not accessible outside
220declarations, such as the following where \texttt{MyLT} is not accessible outside
233the definition of \texttt{foo}:
221the definition of \texttt{foo}:
@@ -922,7 +910,7 @@ If the \texttt{Vect} is empty, the result is easy:
922
910
923\begin{SaveVerbatim}{vfilternil}
911\begin{SaveVerbatim}{vfilternil}
924
912
925−filter p Nil = (_ , [])
913+filter p Nil = (_ ** [])
926
914
927\end{SaveVerbatim}
915\end{SaveVerbatim}
928\useverb{vfilternil}
916\useverb{vfilternil}