How to Keep Your Neighbours in Order

被引:0
作者
McBride, Conor [1 ]
机构
[1] Univ Strathclyde, Glasgow G1 1XQ, Lanark, Scotland
基金
英国工程与自然科学研究理事会;
关键词
dependent types; Agda; ordering; balancing; sorting;
D O I
10.1145/2692915.2628163
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
I present a datatype-generic treatment of recursive container types whose elements are guaranteed to be stored in increasing order, with the ordering invariant rolled out systematically. Intervals, lists and binary search trees are instances of the generic treatment. On the journey to this treatment, I report a variety of failed experiments and the transferable learning experiences they triggered. I demonstrate that a total element ordering is enough to deliver insertion and flattening algorithms, and show that (with care about the formulation of the types) the implementations remain as usual. Agda's instance arguments and pattern synonyms maximize the proof search done by the typechecker and minimize the appearance of proofs in program text, often eradicating them entirely. Generalizing to indexed recursive container types, invariants such as size and balance can be expressed in addition to ordering. By way of example, I implement insertion and deletion for 2-3 trees, ensuring both order and balance by the discipline of type checking.
引用
收藏
页码:297 / 309
页数:13
相关论文
共 17 条
[1]  
Aitken William, 1992, 921290 TR CORN U
[2]  
[Anonymous], P WORKSH ALG ASP ADV
[3]  
Atkey R, 2012, LOG METH COMPUT SCI, V8, DOI [10.2168/LMCS-8(2:09)2012, 10.2168/LMCS-8 (2:09)2012]
[4]  
BERNARDY JP, 2013, ICFP, V48, P61
[5]   PROVING PROPERTIES OF PROGRAMS BY STRUCTURAL INDUCTION [J].
BURSTALL, RM .
COMPUTER JOURNAL, 1969, 12 (01) :41-&
[6]   Transporting Functions across Ornaments [J].
Dagand, Pierre-Evariste ;
McBride, Conor .
ACM SIGPLAN NOTICES, 2012, 47 (09) :103-114
[7]  
DEVRIESE D, 2011, ICFP, V46, P143
[8]  
Kahrs S, 2001, J FUNCT PROGRAM, V11, P425
[9]  
Lindblad F., 2004, Types for Proofs and Programs. International Workshop, TYPES 2004. Revised Selected Papers (Lecture Notes in Computer Science Vol. 3839), P154
[10]  
LINDLEY S, 2013, HASKELL, V48, P81